def test_keyword_arguments_equality_and_get_method(self): d = FancyDict(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 = FancyDict({'a': 2, 'b': 3}) y = FancyDict({'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_attribute(self): d = FancyDict({'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 = FancyDict({'greeting 1': 'hi'}) self.assertEqual(d['greeting 1'], 'hi') with self.assertRaises(AttributeError): d.greeting_1