def test_items(self): obj = Object() obj.attr1 = 1 x = DictAttribute(obj) x["attr2"] = 2 self.assertDictEqual(dict(x.iteritems()), dict(attr1=1, attr2=2)) self.assertDictEqual(dict(x.items()), dict(attr1=1, attr2=2))
def test_get_set_keys_values_items(self): x = DictAttribute(Bunch()) 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", list(x.values()))
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', list(x.values()))