954
954
self.assertEqual(set([]), index.external_references(0))
956
def test_get_ancestry(self):
956
def test__find_ancestors(self):
957
957
key1 = ('key-1',)
958
958
key2 = ('key-2',)
959
959
index = self.make_index(ref_lists=1, key_elements=1, nodes=[
964
964
missing_keys = set()
965
search_keys = index.get_ancestry([key1], 0, parent_map, missing_keys)
965
search_keys = index._find_ancestors([key1], 0, parent_map, missing_keys)
966
966
self.assertEqual({key1: (key2,)}, parent_map)
967
967
self.assertEqual(set(), missing_keys)
968
968
self.assertEqual(set([key2]), search_keys)
969
search_keys = index.get_ancestry(search_keys, 0, parent_map,
969
search_keys = index._find_ancestors(search_keys, 0, parent_map,
971
971
self.assertEqual({key1: (key2,), key2: ()}, parent_map)
972
972
self.assertEqual(set(), missing_keys)
973
973
self.assertEqual(set(), search_keys)
975
def test_get_ancestry_w_missing(self):
975
def test__find_ancestors_w_missing(self):
976
976
key1 = ('key-1',)
977
977
key2 = ('key-2',)
978
978
key3 = ('key-3',)
984
984
missing_keys = set()
985
search_keys = index.get_ancestry([key2, key3], 0, parent_map,
985
search_keys = index._find_ancestors([key2, key3], 0, parent_map,
987
987
self.assertEqual({key2: ()}, parent_map)
988
988
self.assertEqual(set([key3]), missing_keys)
989
989
self.assertEqual(set(), search_keys)
991
def test_get_ancestry_dont_search_known(self):
991
def test__find_ancestors_dont_search_known(self):
992
992
key1 = ('key-1',)
993
993
key2 = ('key-2',)
994
994
key3 = ('key-3',)
1000
1000
# We already know about key2, so we won't try to search for key3
1001
1001
parent_map = {key2: (key3,)}
1002
1002
missing_keys = set()
1003
search_keys = index.get_ancestry([key1], 0, parent_map,
1003
search_keys = index._find_ancestors([key1], 0, parent_map,
1005
1005
self.assertEqual({key1: (key2,), key2: (key3,)}, parent_map)
1006
1006
self.assertEqual(set(), missing_keys)
1007
1007
self.assertEqual(set(), search_keys)
1338
1338
(key4, 'value', ([key3],)),
1340
1340
c_index = CombinedGraphIndex([index1, index2])
1341
parent_map, missing_keys = c_index.get_ancestry([key1])
1341
parent_map, missing_keys = c_index.find_ancestry([key1], 0)
1342
1342
self.assertEqual({key1: ()}, parent_map)
1343
1343
self.assertEqual(set(), missing_keys)
1344
1344
# Now look for a key from index2 which requires us to find the key in
1345
1345
# the second index, and then continue searching for parents in the
1347
parent_map, missing_keys = c_index.get_ancestry([key3])
1347
parent_map, missing_keys = c_index.find_ancestry([key3], 0)
1348
1348
self.assertEqual({key1: (), key2: (key1,), key3: (key2,)}, parent_map)
1349
1349
self.assertEqual(set(), missing_keys)
1351
def test_get_ancestry_missing_keys(self):
1351
def test_find_ancestors_missing_keys(self):
1352
1352
key1 = ('key-1',)
1353
1353
key2 = ('key-2',)
1354
1354
key3 = ('key-3',)
1363
1363
c_index = CombinedGraphIndex([index1, index2])
1364
1364
# Searching for a key which is actually not present at all should
1365
1365
# eventually converge
1366
parent_map, missing_keys = c_index.get_ancestry([key4])
1366
parent_map, missing_keys = c_index.find_ancestry([key4], 0)
1367
1367
self.assertEqual({}, parent_map)
1368
1368
self.assertEqual(set([key4]), missing_keys)
1370
def test_get_ancestry_no_indexes(self):
1370
def test_find_ancestors_no_indexes(self):
1371
1371
c_index = CombinedGraphIndex([])
1372
1372
key1 = ('key-1',)
1373
parent_map, missing_keys = c_index.get_ancestry([key1])
1373
parent_map, missing_keys = c_index.find_ancestry([key1], 0)
1374
1374
self.assertEqual({}, parent_map)
1375
1375
self.assertEqual(set([key1]), missing_keys)
1377
def test_get_ancestry_ghost_parent(self):
1377
def test_find_ancestors_ghost_parent(self):
1378
1378
key1 = ('key-1',)
1379
1379
key2 = ('key-2',)
1380
1380
key3 = ('key-3',)
1389
1389
c_index = CombinedGraphIndex([index1, index2])
1390
1390
# Searching for a key which is actually not present at all should
1391
1391
# eventually converge
1392
parent_map, missing_keys = c_index.get_ancestry([key4])
1392
parent_map, missing_keys = c_index.find_ancestry([key4], 0)
1393
1393
self.assertEqual({key4: (key2, key3), key2: (key1,), key1: ()},
1395
1395
self.assertEqual(set([key3]), missing_keys)
1397
def test_get_ancestry_empty_index(self):
1398
index = self.make_index(ref_lists=1, key_elements=1, nodes=[])
1397
def test__find_ancestors_empty_index(self):
1398
index = self.make_index('test', ref_lists=1, key_elements=1, nodes=[])
1399
1399
parent_map = {}
1400
1400
missing_keys = set()
1401
search_keys = index.get_ancestry([('one',), ('two',)], 0, parent_map,
1401
search_keys = index._find_ancestors([('one',), ('two',)], 0, parent_map,
1403
1403
self.assertEqual(set(), search_keys)
1404
1404
self.assertEqual({}, parent_map)
1405
1405
self.assertEqual(set([('one',), ('two',)]), missing_keys)