Exemplo n.º 1
0
 def testGet(self):
     '''Tests simple set/get.'''
     m = Map()
     # What goes in is what comes out.
     m.set('key1', 'value1')
     self.assertEquals(m.get(('key1',)), 'value1')
     # Atoms work as keys.
     self.assertEquals(m.get('key2'), None)
     # Values are write-once
     self.assertRaises(MapError, m.set, 'key1', 'value1b')
Exemplo n.º 2
0
 def testGetPrefix(self):
     '''Tests set/get_prefix.'''
     m = Map()
     # Tuple key
     m.set(('key1a', 'key1b'), 'value1ab')
     self.assertEquals(m.get(('key1a', 'key1b')), 'value1ab')
     # Retrieve by prefix
     self.assertEquals(m.get_prefix('key1a'), {'key1b': 'value1ab'})
     # get_prefix only retrieves at the given level
     m.set(('key1a', 'key1b', 'key1c'), 'value1abc')
     self.assertEquals(m.get_prefix('key1a'), {'key1b': 'value1ab'})
Exemplo n.º 3
0
 def testInheritancePrefix(self):
     '''Tests that inheritance works with prefixes'''
     parent_map = Map()
     parent_map.set(('key1a', 'key1b'), 'value1ab')
     child_map = Map(parent_map)
     self.assertEquals(parent_map.get(('key1a', 'key1b')), 'value1ab')
     self.assertEquals(child_map.get(('key1a', 'key1b')), 'value1ab')
     self.assertEquals(parent_map.get_prefix(('key1a',)), {'key1b': 'value1ab'})
     self.assertEquals(child_map.get_prefix(('key1a',)), {'key1b': 'value1ab'})
     # Override in the child
     child_map.set(('key1a', 'key1b'), 'value1abchild')
     self.assertEquals(parent_map.get(('key1a', 'key1b')), 'value1ab')
     self.assertEquals(child_map.get(('key1a', 'key1b')), 'value1abchild')
     self.assertEquals(parent_map.get_prefix(('key1a',)), {'key1b': 'value1ab'})
     self.assertEquals(child_map.get_prefix(('key1a',)), {'key1b': 'value1abchild'})
Exemplo n.º 4
0
 def testInheritance(self):
     '''Tests that inheritance from a parent map works'''
     parent_map = Map()
     parent_map.set('key1', 'value1')
     self.assertEquals(parent_map.get('key1'), 'value1')
     child_map = Map(parent_map)
     # Check that the child map inherits values from the parent map
     self.assertEquals(child_map.get('key1'), 'value1')
     # Now override the value
     child_map.set('key1', 'value1child')
     self.assertEquals(parent_map.get('key1'), 'value1')
     self.assertEquals(child_map.get('key1'), 'value1child')
     # Likewise with a shared parent
     other_child = Map(parent_map)
     other_child.set('key1', 'value1other')
     self.assertEquals(parent_map.get('key1'), 'value1')
     self.assertEquals(child_map.get('key1'), 'value1child')
     self.assertEquals(other_child.get('key1'), 'value1other')