def test_basic(self): p = idict() self.assertEqual(p.local, {}) self.assertEqual(p.inherited, {}) # update the (local) values p.update(x=1, y=2, z=3) self.assertEqual(p, p.local) self.assertNotEqual(p, p.inherited) self.assertEqual(len(p), 3) self.assertEqual(len(p.local), 3) self.assertEqual(len(p.inherited), 0) # update inherited values p.inherited.update(a=1, b=2, c=3) self.assertNotEqual(p, p.local) self.assertNotEqual(p, p.inherited) self.assertEqual(len(p), 6) self.assertEqual(len(p.local), 3) self.assertEqual(len(p.inherited), 3) # perform some updates in place p["a"] = 100 self.assertEqual(p.get("a"), 100) self.assertEqual(p.local.get("a"), 100) # local now has an override self.assertEqual(len(p), 6) self.assertEqual(len(p.local), 4) self.assertEqual(len(p.inherited), 3)
def test_init_kwargs(self): p = idict(a=1, b=2, c=3) self.assertEqual(len(p), 3) self.assertEqual(len(p.local), 3) self.assertEqual(len(p.inherited), 0) self.assertEqual(p.get("a"), 1) self.assertEqual(p.get("b"), 2) self.assertEqual(p.get("c"), 3)
def test_init_args(self): p = idict({"a": 1, "b": 2}) self.assertEqual(len(p), 2) self.assertEqual(len(p.local), 2) self.assertEqual(len(p.inherited), 0) p.inherited.update(a=2, b=3, c=4) self.assertEqual(len(p), 3) self.assertEqual(len(p.local), 2) self.assertEqual(len(p.inherited), 3) self.assertEqual(p.get("a"), 1) self.assertEqual(p.get("b"), 2) self.assertEqual(p.get("c"), 4)
def test_init_args(self): p = idict({"a": 1, "b":2}) self.assertEqual(len(p), 2) self.assertEqual(len(p.local), 2) self.assertEqual(len(p.inherited), 0) p.inherited.update(a=2, b=3, c=4) self.assertEqual(len(p), 3) self.assertEqual(len(p.local), 2) self.assertEqual(len(p.inherited), 3) self.assertEqual(p.get("a"), 1) self.assertEqual(p.get("b"), 2) self.assertEqual(p.get("c"), 4)