728
728
self.assertEqual(set(['other_2']), search.next())
729
729
self.assertRaises(StopIteration, search.next)
731
def assertSeenAndRecipes(self, results, search, next):
731
def assertSeenAndRecipes(self, instructions, search, next):
732
732
"""Check the results of .seen and get_recipe() for a seach.
734
:param results: A list of tuples (seen, get_recipe_result).
734
:param instructions: A list of tuples (seen, get_recipe_result, starts,
735
stops). seen and get_recipe_result are results to check. starts and
736
stops are parameters to pass to start_searching and
737
stop_searching_any during each iteration, if they are not None.
735
738
:param search: The search to use.
736
739
:param next: A callable to advance the search.
738
for seen, recipe in results:
741
for seen, recipe, starts, stops in instructions:
743
if starts is not None:
744
search.start_searching(starts)
745
if stops is not None:
746
search.stop_searching_any(stops)
740
747
self.assertEqual(recipe, search.get_recipe())
741
748
self.assertEqual(seen, search.seen)
751
758
self.assertEqual(set(), search.seen)
754
(set(['head']), (set(['head']), set(['child']))),
755
(set(['head', 'child']), (set(['head']), set([NULL_REVISION]))),
756
(set(['head', 'child', NULL_REVISION]), (set(['head']), set())),
761
(set(['head']), (set(['head']), set(['child'])), None, None),
762
(set(['head', 'child']), (set(['head']), set([NULL_REVISION])),
764
(set(['head', 'child', NULL_REVISION]), (set(['head']), set()),
758
767
self.assertSeenAndRecipes(expected, search, search.next)
759
768
# using next_with_ghosts:
760
769
search = graph._make_breadth_first_searcher(['head'])
761
770
self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
772
def test_breadth_first_get_recipe_starts_stops(self):
773
graph = self.make_graph({
775
'child':[NULL_REVISION],
776
'otherhead':['otherchild'],
777
'otherchild':['excluded'],
778
'excluded':[NULL_REVISION],
780
search = graph._make_breadth_first_searcher([])
781
# Starting with nothing and adding a search works:
782
search.start_searching(['head'])
783
# At the start, nothing has been seen, to its all excluded:
784
self.assertEqual((set(['head']), set(['child'])), search.get_recipe())
785
self.assertEqual(set(['head']), search.seen)
788
# stop at child, and start a new search at otherhead:
789
# - otherhead counts as seen immediately when start_searching is
791
(set(['head', 'child', 'otherhead']),
792
(set(['head', 'otherhead']), set(['child', 'otherchild'])),
793
['otherhead'], ['child']),
794
(set(['head', 'child', 'otherhead', 'otherchild']),
795
(set(['head', 'otherhead']), set(['child', 'excluded'])),
797
# stop searchind otherexcluded now
798
(set(['head', 'child', 'otherhead', 'otherchild', 'excluded']),
799
(set(['head', 'otherhead']), set(['child', 'excluded'])),
802
self.assertSeenAndRecipes(expected, search, search.next)
803
# using next_with_ghosts:
804
search = graph._make_breadth_first_searcher([])
805
search.start_searching(['head'])
806
self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
764
809
class TestCachingParentsProvider(tests.TestCase):