Exemplo n.º 1
0
 def test_construction_from_ddict(self):
     d = ddict(ddict({'a': 1, 'b': 2}))
     self.assertEqual(len(d), 2)
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d['a'], 1)
     self.assertEqual(d['b'], 2)
Exemplo n.º 2
0
    def test_iter(self):
        result = {}
        for k, v in ddict(a=1, b=2):
            result[k] = v

        self.assertDictEqual(result, {'a': 1, 'b': 2})

        result = {}
        for k, v in ddict(a=1, b=2).items():
            result[k] = v

        self.assertDictEqual(result, {'a': 1, 'b': 2})
Exemplo n.º 3
0
 def test_del(self):
     d = ddict(a=1, b=2)
     self.assertEqual(len(d), 2)
     del d.a
     self.assertEqual(len(d), 1)
     del d['b']
     self.assertEqual(len(d), 0)
Exemplo n.º 4
0
 def test_construction_from_kwargs(self):
     d = ddict(a=1, b=2)
     self.assertEqual(len(d), 2)
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d['a'], 1)
     self.assertEqual(d['b'], 2)
Exemplo n.º 5
0
 def test_construction_from_iterable(self):
     d = ddict({'a': 1, 'b': 2}.items())
     self.assertEqual(len(d), 2)
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d['a'], 1)
     self.assertEqual(d['b'], 2)
Exemplo n.º 6
0
 def test_construction_from_iterable_and_kwargs(self):
     d = ddict((('c', 3), ), a=1, b=2)
     self.assertEqual(len(d), 3)
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d.c, 3)
     self.assertEqual(d['a'], 1)
     self.assertEqual(d['b'], 2)
     self.assertEqual(d['c'], 3)
Exemplo n.º 7
0
 def test_construction_from_dict_and_kwargs(self):
     d = ddict({'c': 3}, a=1, b=2)
     self.assertEqual(len(d), 3)
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
     self.assertEqual(d.c, 3)
     self.assertEqual(d['a'], 1)
     self.assertEqual(d['b'], 2)
     self.assertEqual(d['c'], 3)
Exemplo n.º 8
0
    def test_equality(self):
        a, b = ddict(a=1, b=2), dict(a=1, b=2)
        self.assertTrue(a == b)
        self.assertEqual(a, b)
        self.assertEqual(a, b)

        a, b = ddict(b=2, a=1), dict(a=1, b=2)
        self.assertTrue(a == b)
        self.assertEqual(a, b)
        self.assertEqual(a, b)

        a, b = ddict(b=2, a=1, c=3), dict(a=1, b=2)
        self.assertTrue(a != b)
        self.assertNotEqual(a, b)
        self.assertNotEqual(a, b)

        a, b = ddict(b=2, a=3), dict(a=1, b=2)
        self.assertTrue(a != b)
        self.assertNotEqual(a, b)
        self.assertNotEqual(a, b)
Exemplo n.º 9
0
    def test_add_operator(self):
        a, b = ddict(b=2, a=1, c=3), dict(a=2, b=3)
        with self.assertRaises(TypeError):
            c = a + 1

        c = a + b
        self.assertDictEqual(c, dict(a=2, b=3, c=3))

        b2 = dict(z=4)
        c = a + b2
        self.assertDictEqual(a, dict(a=1, b=2, c=3))
        self.assertDictEqual(b2, dict(z=4))
        self.assertDictEqual(c, dict(a=1, b=2, c=3, z=4))
Exemplo n.º 10
0
 def test_nonexistent_key(self):
     d = ddict(a=1)
     self.assertTrue(d.b is undefined)