525
526
graph = self.make_graph(history_shortcut)
526
527
self.assertEqual(set(['rev2b']), graph.find_lca('rev3a', 'rev3b'))
529
def test_lefthand_distance_smoke(self):
530
"""A simple does it work test for graph.lefthand_distance(keys)."""
531
graph = self.make_graph(history_shortcut)
532
distance_graph = graph.find_lefthand_distances(['rev3b', 'rev2a'])
533
self.assertEqual({'rev2a': 2, 'rev3b': 3}, distance_graph)
535
def test_lefthand_distance_ghosts(self):
536
"""A simple does it work test for graph.lefthand_distance(keys)."""
537
nodes = {'nonghost':[NULL_REVISION], 'toghost':['ghost']}
538
graph = self.make_graph(nodes)
539
distance_graph = graph.find_lefthand_distances(['nonghost', 'toghost'])
540
self.assertEqual({'nonghost': 1, 'toghost': -1}, distance_graph)
528
542
def test_recursive_unique_lca(self):
529
543
"""Test finding a unique least common ancestor.
661
675
self.assertEqual((set(['e']), set(['f', 'g'])),
662
676
graph.find_difference('e', 'f'))
664
679
def test_stacked_parents_provider(self):
665
680
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
666
681
parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
667
stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
682
stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
683
self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
684
stacked.get_parent_map(['rev1', 'rev2']))
685
self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
686
stacked.get_parent_map(['rev2', 'rev1']))
687
self.assertEqual({'rev2':['rev3']},
688
stacked.get_parent_map(['rev2', 'rev2']))
689
self.assertEqual({'rev1':['rev4']},
690
stacked.get_parent_map(['rev1', 'rev1']))
692
def test_stacked_parents_provider_overlapping(self):
693
# rev2 is availible in both providers.
697
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
698
parents2 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
699
stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
700
self.assertEqual({'rev2': ['rev1']},
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])
668
708
self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
669
709
stacked.get_parent_map(['rev1', 'rev2']))
670
710
self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
1558
1598
result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1559
1599
self.assertEqual(set(['rev-1', 'rev-2']), set(result.get_keys()))
1601
def test_get_keys_excludes_ghosts(self):
1602
builder = self.make_branch_builder('b')
1603
builder.start_series()
1604
builder.build_snapshot('rev-1', None, [
1605
('add', ('', 'root-id', 'directory', ''))])
1606
builder.build_snapshot('rev-2', ['rev-1', 'ghost'], [])
1607
builder.finish_series()
1608
repo = builder.get_branch().repository
1610
self.addCleanup(repo.unlock)
1611
result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1612
self.assertEqual(sorted(['rev-1', 'rev-2']), sorted(result.get_keys()))
1561
1614
def test_get_keys_excludes_null(self):
1562
1615
# Make a 'graph' with an iter_ancestry that returns NULL_REVISION
1563
1616
# somewhere other than the last element, which can happen in real