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)
def test_normalize_arg(self): d = EasyDict({"greeting 1": "hi"}, normalize=True) self.assertEqual(d["greeting 1"], "hi") self.assertEqual(d.greeting_1, "hi") d.greeting_2 = "hello" self.assertEqual(d["greeting 2"], "hello") self.assertEqual(d.greeting_2, "hello") d["greeting 2"] = "hey" self.assertEqual(d["greeting 2"], "hey") self.assertEqual(d.get("greeting 2"), "hey") self.assertEqual(d.greeting_2, "hey") with self.assertRaises(AttributeError): d.greeting2 d = EasyDict({"greeting 1": "hi"}) self.assertEqual(d["greeting 1"], "hi") with self.assertRaises(AttributeError): d.greeting_1