450
446
self.assertEqual((set(['e']), set(['f', 'g'])),
451
447
graph.find_difference('e', 'f'))
453
def test_stacked_parents_provider_get_parents(self):
454
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
455
parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
456
stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
457
self.assertEqual([['rev4',], ['rev3']],
458
self.applyDeprecated(symbol_versioning.one_one,
459
stacked.get_parents, ['rev1', 'rev2']))
460
self.assertEqual([['rev3',], ['rev4']],
461
self.applyDeprecated(symbol_versioning.one_one,
462
stacked.get_parents, ['rev2', 'rev1']))
463
self.assertEqual([['rev3',], ['rev3']],
464
self.applyDeprecated(symbol_versioning.one_one,
465
stacked.get_parents, ['rev2', 'rev2']))
466
self.assertEqual([['rev4',], ['rev4']],
467
self.applyDeprecated(symbol_versioning.one_one,
468
stacked.get_parents, ['rev1', 'rev1']))
470
449
def test_stacked_parents_provider(self):
471
450
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
472
451
parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
681
652
self.assertEqual(set(['h1', 'h2']),
682
653
self._run_heads_break_deeper(graph_dict, ['h1', 'h2']))
655
def test_breadth_first_search_start_ghosts(self):
657
parents_provider = InstrumentedParentsProvider(
658
_mod_graph.DictParentsProvider(parent_graph))
659
graph = _mod_graph.Graph(parents_provider)
660
# with_ghosts reports the ghosts
661
search = graph._make_breadth_first_searcher(['a-ghost'])
662
self.assertEqual((set(), set(['a-ghost'])), search.next_with_ghosts())
663
self.assertRaises(StopIteration, search.next_with_ghosts)
665
search = graph._make_breadth_first_searcher(['a-ghost'])
666
self.assertEqual(set(['a-ghost']), search.next())
667
self.assertRaises(StopIteration, search.next)
669
def test_breadth_first_search_deep_ghosts(self):
672
'present':['child', 'ghost'],
675
parents_provider = InstrumentedParentsProvider(
676
_mod_graph.DictParentsProvider(parent_graph))
677
graph = _mod_graph.Graph(parents_provider)
678
# with_ghosts reports the ghosts
679
search = graph._make_breadth_first_searcher(['head'])
680
self.assertEqual((set(['head']), set()), search.next_with_ghosts())
681
self.assertEqual((set(['present']), set()), search.next_with_ghosts())
682
self.assertEqual((set(['child']), set(['ghost'])),
683
search.next_with_ghosts())
684
self.assertRaises(StopIteration, search.next_with_ghosts)
686
search = graph._make_breadth_first_searcher(['head'])
687
self.assertEqual(set(['head']), search.next())
688
self.assertEqual(set(['present']), search.next())
689
self.assertEqual(set(['child', 'ghost']),
691
self.assertRaises(StopIteration, search.next)
693
def test_breadth_first_search_change_next_to_next_with_ghosts(self):
694
# To make the API robust, we allow changing from next() to
695
# next_with_ghosts() and vice verca.
698
'present':['child', 'ghost'],
701
parents_provider = InstrumentedParentsProvider(
702
_mod_graph.DictParentsProvider(parent_graph))
703
graph = _mod_graph.Graph(parents_provider)
704
# with_ghosts reports the ghosts
705
search = graph._make_breadth_first_searcher(['head'])
706
self.assertEqual((set(['head']), set()), search.next_with_ghosts())
707
self.assertEqual(set(['present']), search.next())
708
self.assertEqual((set(['child']), set(['ghost'])),
709
search.next_with_ghosts())
710
self.assertRaises(StopIteration, search.next)
712
search = graph._make_breadth_first_searcher(['head'])
713
self.assertEqual(set(['head']), search.next())
714
self.assertEqual((set(['present']), set()), search.next_with_ghosts())
715
self.assertEqual(set(['child', 'ghost']),
717
self.assertRaises(StopIteration, search.next_with_ghosts)
685
720
class TestCachingParentsProvider(tests.TestCase):
690
725
self.inst_pp = InstrumentedParentsProvider(dict_pp)
691
726
self.caching_pp = _mod_graph.CachingParentsProvider(self.inst_pp)
693
def test_get_parents(self):
694
"""Requesting the same revision should be returned from cache"""
695
self.assertEqual({}, self.caching_pp._cache)
696
self.assertEqual([('b',)],
697
self.applyDeprecated(symbol_versioning.one_one,
698
self.caching_pp.get_parents, ['a']))
699
self.assertEqual(['a'], self.inst_pp.calls)
700
self.assertEqual([('b',)],
701
self.applyDeprecated(symbol_versioning.one_one,
702
self.caching_pp.get_parents, ['a']))
703
# No new call, as it should have been returned from the cache
704
self.assertEqual(['a'], self.inst_pp.calls)
705
self.assertEqual({'a':('b',)}, self.caching_pp._cache)
707
728
def test_get_parent_map(self):
708
729
"""Requesting the same revision should be returned from cache"""
709
730
self.assertEqual({}, self.caching_pp._cache)