def test_get_set_keys_values_items(self): x = DictAttribute(Object()) x['foo'] = 'The quick brown fox' self.assertEqual(x['foo'], 'The quick brown fox') self.assertEqual(x['foo'], x.obj.foo) self.assertEqual(x.get('foo'), 'The quick brown fox') self.assertIsNone(x.get('bar')) with self.assertRaises(KeyError): x['bar'] x.foo = 'The quick yellow fox' self.assertEqual(x['foo'], 'The quick yellow fox') self.assertIn( ('foo', 'The quick yellow fox'), list(x.items()), ) self.assertIn('foo', list(x.keys())) self.assertIn('The quick yellow fox', x.values())
def test_setdefault(self): x = DictAttribute(Object()) self.assertEqual(x.setdefault('foo', 'NEW'), 'NEW') self.assertEqual(x.setdefault('foo', 'XYZ'), 'NEW')