예제 #1
0
 def test_keyword_arguments_equality_and_get_method(self):
     d = EasyDict(a=2, b=3, c=4, d=5)
     self.assertEqual(d.a, 2)
     self.assertEqual(d.b, 3)
     self.assertEqual(d["c"], 4)
     self.assertEqual(d["d"], 5)
     x = EasyDict({"a": 2, "b": 3})
     y = EasyDict({"a": 2, "b": 4})
     self.assertNotEqual(x, y)
     y.b = 3
     self.assertEqual(x, y)
     x.c = 5
     self.assertNotEqual(x, y)
     y.c = 5
     self.assertEqual(x, y)
     self.assertIsNone(y.get("d"))
     self.assertEqual(y.get("c"), 5)
     self.assertEqual(y.get("d", 5), 5)
예제 #2
0
 def test_allow_setting_keys_and_attributes(self):
     d = EasyDict({"a": 2, "b": 3})
     d["a"] = 4
     self.assertEqual(d["a"], 4)
     self.assertEqual(d.a, 4)
     d.c = 9
     self.assertEqual(d["c"], 9)
     self.assertEqual(d.c, 9)
     self.assertEqual(d["b"], 3)
     x = EasyDict()
     y = EasyDict()
     x.a = 4
     y.a = 5
     self.assertEqual(x.a, 4)
예제 #3
0
 def test_original_dictionary_unchanged(self):
     mapping = {"a": 2, "b": 3}
     d = EasyDict(mapping)
     d.c = 4
     self.assertEqual(mapping, {"a": 2, "b": 3})