Example #1
0
 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'])
Example #2
0
 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']
Example #3
0
    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()))
Example #4
0
    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))
Example #5
0
 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')])
Example #6
0
 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'])
Example #7
0
 def testGetAbsentNoParent(self):
     d = chain_dict.ChainDict(None)
     with self.assertRaises(KeyError):
         # pylint: disable=pointless-statement
         d['KEY']
Example #8
0
 def testGetNoParent(self):
     d = chain_dict.ChainDict(None)
     d['KEY'] = 'VALUE'
     self.assertEqual('VALUE', d['KEY'])
Example #9
0
 def testSet(self):
     d = chain_dict.ChainDict(None)
     d['KEY'] = 'VALUE'
     self.assertEqual({'KEY': 'VALUE'}, d._map)