def testGetOverridden(self): parent = chain_dict.ChainDict(None) d = chain_dict.ChainDict(parent) parent['KEY'] = 'VALUE' d['KEY'] = 'OTHER_VALUE' self.assertEqual('VALUE', parent['KEY']) self.assertEqual('OTHER_VALUE', d['KEY'])
def testGetNotInParent(self): parent = chain_dict.ChainDict(None) d = chain_dict.ChainDict(parent) with self.assertRaises(KeyError): # pylint: disable=pointless-statement parent['KEY'] with self.assertRaises(KeyError): # pylint: disable=pointless-statement d['KEY']
def testIteration(self): parent = chain_dict.ChainDict(None) d = chain_dict.ChainDict(parent) parent['KEY'] = 'VALUE' d['KEY'] = 'OTHER_VALUE' d['OTHER_KEY'] = 'YAV' self.assertEqual([('KEY', 'OTHER_VALUE'), ('OTHER_KEY', 'YAV')], sorted(d.items())) self.assertEqual([('KEY', 'VALUE')], sorted(parent.items()))
def testLen(self): parent = chain_dict.ChainDict(None) d = chain_dict.ChainDict(parent) self.assertEqual(0, len(d)) self.assertEqual(0, len(parent)) parent['KEY'] = 'VALUE' self.assertEqual(1, len(d)) self.assertEqual(1, len(parent)) d['KEY'] = 'OTHER_VALUE' self.assertEqual(1, len(d)) self.assertEqual(1, len(parent)) d['OTHER_KEY'] = 'YAV' self.assertEqual(2, len(d)) self.assertEqual(1, len(parent))
def testPlainDictParent(self): d = chain_dict.ChainDict({'KEY': 'VALUE'}) self.assertEqual('VALUE', d['KEY']) self.assertEqual(len(d), 1) # In Python 3, items produces an iterator. self.assertEqual(list(d.items()), [('KEY', 'VALUE')])
def testGetInParent(self): parent = chain_dict.ChainDict(None) d = chain_dict.ChainDict(parent) parent['KEY'] = 'VALUE' self.assertEqual('VALUE', parent['KEY']) self.assertEqual('VALUE', d['KEY'])
def testGetAbsentNoParent(self): d = chain_dict.ChainDict(None) with self.assertRaises(KeyError): # pylint: disable=pointless-statement d['KEY']
def testGetNoParent(self): d = chain_dict.ChainDict(None) d['KEY'] = 'VALUE' self.assertEqual('VALUE', d['KEY'])
def testSet(self): d = chain_dict.ChainDict(None) d['KEY'] = 'VALUE' self.assertEqual({'KEY': 'VALUE'}, d._map)