757
757
class TestGraphIndexPrefixAdapter(TestCaseWithMemoryTransport):
759
def make_index(self, ref_lists=1, key_elements=2, nodes=[]):
759
def make_index(self, ref_lists=1, key_elements=2, nodes=[], add_callback=False):
760
760
result = InMemoryGraphIndex(ref_lists, key_elements=key_elements)
761
761
result.add_nodes(nodes)
762
adapter = GraphIndexPrefixAdapter(result, ('prefix', ), key_elements - 1)
763
add_nodes_callback=result.add_nodes
765
add_nodes_callback=None
766
adapter = GraphIndexPrefixAdapter(result, ('prefix', ), key_elements - 1,
767
add_nodes_callback=add_nodes_callback)
763
768
return result, adapter
770
def test_add_node(self):
771
index, adapter = self.make_index(add_callback=True)
772
adapter.add_node(('key',), 'value', ((('ref',),),))
773
self.assertEqual(set([(('prefix', 'key'), 'value', ((('prefix', 'ref'),),))]),
774
set(index.iter_all_entries()))
776
def test_add_nodes(self):
777
index, adapter = self.make_index(add_callback=True)
779
(('key',), 'value', ((('ref',),),)),
780
(('key2',), 'value2', ((),)),
782
self.assertEqual(set([
783
(('prefix', 'key2'), 'value2', ((),)),
784
(('prefix', 'key'), 'value', ((('prefix', 'ref'),),))
786
set(index.iter_all_entries()))
765
788
def test_construct(self):
766
789
index = InMemoryGraphIndex()
767
790
adapter = GraphIndexPrefixAdapter(index, ('prefix', ), 1)