698
700
self.assertEqual({'rev2': ['rev1']},
699
701
stacked.get_parent_map(['rev2']))
703
def test__stacked_parents_provider_deprecated(self):
704
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
705
parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
706
stacked = self.applyDeprecated(deprecated_in((1, 16, 0)),
707
_mod_graph._StackedParentsProvider, [parents1, parents2])
708
self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
709
stacked.get_parent_map(['rev1', 'rev2']))
710
self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
711
stacked.get_parent_map(['rev2', 'rev1']))
712
self.assertEqual({'rev2':['rev3']},
713
stacked.get_parent_map(['rev2', 'rev2']))
714
self.assertEqual({'rev1':['rev4']},
715
stacked.get_parent_map(['rev1', 'rev1']))
701
717
def test_iter_topo_order(self):
702
718
graph = self.make_graph(ancestry_1)
703
719
args = ['rev2a', 'rev3', 'rev1']
1408
1424
self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3'])
1411
class TestFindDescendants(TestGraphBase):
1413
def test_find_descendants_rev1_rev3(self):
1414
graph = self.make_graph(ancestry_1)
1415
descendants = graph.find_descendants('rev1', 'rev3')
1416
self.assertEqual(set(['rev1', 'rev2a', 'rev3']), descendants)
1418
def test_find_descendants_rev1_rev4(self):
1419
graph = self.make_graph(ancestry_1)
1420
descendants = graph.find_descendants('rev1', 'rev4')
1421
self.assertEqual(set(['rev1', 'rev2a', 'rev2b', 'rev3', 'rev4']),
1424
def test_find_descendants_rev2a_rev4(self):
1425
graph = self.make_graph(ancestry_1)
1426
descendants = graph.find_descendants('rev2a', 'rev4')
1427
self.assertEqual(set(['rev2a', 'rev3', 'rev4']), descendants)
1429
class TestFindLefthandMerger(TestGraphBase):
1431
def check_merger(self, result, ancestry, merged, tip):
1432
graph = self.make_graph(ancestry)
1433
self.assertEqual(result, graph.find_lefthand_merger(merged, tip))
1435
def test_find_lefthand_merger_rev2b(self):
1436
self.check_merger('rev4', ancestry_1, 'rev2b', 'rev4')
1438
def test_find_lefthand_merger_rev2a(self):
1439
self.check_merger('rev2a', ancestry_1, 'rev2a', 'rev4')
1441
def test_find_lefthand_merger_rev4(self):
1442
self.check_merger(None, ancestry_1, 'rev4', 'rev2a')
1444
def test_find_lefthand_merger_f(self):
1445
self.check_merger('i', complex_shortcut, 'f', 'm')
1447
def test_find_lefthand_merger_g(self):
1448
self.check_merger('i', complex_shortcut, 'g', 'm')
1450
def test_find_lefthand_merger_h(self):
1451
self.check_merger('n', complex_shortcut, 'h', 'n')
1454
class TestGetChildMap(TestGraphBase):
1456
def test_get_child_map(self):
1457
graph = self.make_graph(ancestry_1)
1458
child_map = graph.get_child_map(['rev4', 'rev3', 'rev2a', 'rev2b'])
1459
self.assertEqual({'rev1': ['rev2a', 'rev2b'],
1466
1427
class TestCachingParentsProvider(tests.TestCase):
1467
1428
"""These tests run with:
1638
1599
self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'C'])))
1639
1600
self.assertEqual(['B', 'C'], sorted(graph_thunk.heads(['B', 'C'])))
1641
def test_add_node(self):
1642
d = {('C',):[('A',)], ('B',): [('A',)], ('A',): []}
1643
g = _mod_graph.KnownGraph(d)
1644
graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1645
graph_thunk.add_node("D", ["A", "C"])
1646
self.assertEqual(['B', 'D'],
1647
sorted(graph_thunk.heads(['D', 'B', 'A'])))
1649
def test_merge_sort(self):
1650
d = {('C',):[('A',)], ('B',): [('A',)], ('A',): []}
1651
g = _mod_graph.KnownGraph(d)
1652
graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1653
graph_thunk.add_node("D", ["A", "C"])
1654
self.assertEqual([('C', 0, (2,), False), ('A', 0, (1,), True)],
1655
[(n.key, n.merge_depth, n.revno, n.end_of_merge)
1656
for n in graph_thunk.merge_sort('C')])
1659
1603
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
1660
1604
"""Tests for bzrlib.graph.PendingAncestryResult."""