~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

Add tests for starting and stopping searches in combination with get_recipe.

Show diffs side-by-side

added added

removed removed

Lines of Context:
728
728
        self.assertEqual(set(['other_2']), search.next())
729
729
        self.assertRaises(StopIteration, search.next)
730
730
 
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.
733
733
 
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.
737
740
        """
738
 
        for seen, recipe in results:
 
741
        for seen, recipe, starts, stops in instructions:
739
742
            next()
 
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)
742
749
 
751
758
        self.assertEqual(set(), search.seen)
752
759
        # using next:
753
760
        expected = [
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])),
 
763
             None, None),
 
764
            (set(['head', 'child', NULL_REVISION]), (set(['head']), set()),
 
765
             None, None),
757
766
            ]
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)
762
771
 
 
772
    def test_breadth_first_get_recipe_starts_stops(self):
 
773
        graph = self.make_graph({
 
774
            'head':['child'],
 
775
            'child':[NULL_REVISION],
 
776
            'otherhead':['otherchild'],
 
777
            'otherchild':['excluded'],
 
778
            'excluded':[NULL_REVISION],
 
779
            })
 
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)
 
786
        # using next:
 
787
        expected = [
 
788
            # stop at child, and start a new search at otherhead:
 
789
            # - otherhead counts as seen immediately when start_searching is
 
790
            # called.
 
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'])),
 
796
             None, None),
 
797
            # stop searchind otherexcluded now
 
798
            (set(['head', 'child', 'otherhead', 'otherchild', 'excluded']),
 
799
             (set(['head', 'otherhead']), set(['child', 'excluded'])),
 
800
             None, ['excluded']),
 
801
            ]
 
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)
 
807
 
763
808
 
764
809
class TestCachingParentsProvider(tests.TestCase):
765
810