File: test_dotty_basics.py

package info (click to toggle)
dotty-dict 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 352 kB
  • sloc: python: 1,166; makefile: 192; sh: 5
file content (54 lines) | stat: -rw-r--r-- 1,756 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest

from dotty_dict import dotty


class TestDottyBasics(unittest.TestCase):
    def test_create_empty_instance(self):
        dot = dotty()
        self.assertEqual(dot, {})

    def test_create_non_empty_instance(self):
        plain_dict = {'not': 'empty'}

        dot = dotty(plain_dict)
        self.assertEqual(dot, plain_dict)
        self.assertIsNot(dot, plain_dict)

    # noinspection PyTypeChecker
    def test_raise_attr_error_if_input_is_not_dict(self):
        with self.assertRaises(AttributeError):
            dotty(['not', 'valid'])

    def test_two_dotty_with_the_same_input_should_be_equal(self):
        first = dotty({'is': 'valid'})
        second = dotty({'is': 'valid'})

        self.assertEqual(first, second)

    def test_two_dotty_with_different_input_should_not_be_equal(self):
        first = dotty({'counter': 1})
        second = dotty({'counter': 2})

        self.assertNotEqual(first, second)

    def test_plain_dict_and_dotty_wrapper_should_be_equal(self):
        plain = {'a': 1, 'b': 2}
        dot = dotty(plain)
        self.assertEqual(dot, plain)

    def test_dotty_and_not_mapping_instance_should_not_be_equal(self):
        dot = dotty({'a': 1, 'b': 2})
        self.assertNotEqual(dot, [('a', 1), ('b', 2)])
        self.assertNotEqual(dot, ('a', 1))
        self.assertNotEqual(dot, {1, 2, 3})
        self.assertNotEqual(dot, 123)
        self.assertNotEqual(dot, 'a:1, b:2')

    def test_pop_with_default_value(self):
        dot = dotty()
        self.assertEqual(dot.pop('does.not.exist', None), None)
        self.assertEqual(dot.pop('does.not.exist', 55), 55)
        self.assertEqual(dot.pop('does.not.exist', 'my_value'), 'my_value')