~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

Record the number of found revisions for cross checking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
755
755
            })
756
756
        search = graph._make_breadth_first_searcher(['head'])
757
757
        # At the start, nothing has been seen, to its all excluded:
758
 
        self.assertEqual((set(['head']), set(['head'])), search.get_recipe())
 
758
        self.assertEqual((set(['head']), set(['head']), 0),
 
759
            search.get_recipe())
759
760
        self.assertEqual(set(), search.seen)
760
761
        # using next:
761
762
        expected = [
762
 
            (set(['head']), (set(['head']), set(['child'])), None, None),
763
 
            (set(['head', 'child']), (set(['head']), set([NULL_REVISION])),
 
763
            (set(['head']), (set(['head']), set(['child']), 1), None, None),
 
764
            (set(['head', 'child']), (set(['head']), set([NULL_REVISION]), 2),
764
765
             None, None),
765
 
            (set(['head', 'child', NULL_REVISION]), (set(['head']), set()),
 
766
            (set(['head', 'child', NULL_REVISION]), (set(['head']), set(), 3),
766
767
             None, None),
767
768
            ]
768
769
        self.assertSeenAndRecipes(expected, search, search.next)
782
783
        search = graph._make_breadth_first_searcher([])
783
784
        # Starting with nothing and adding a search works:
784
785
        search.start_searching(['head'])
785
 
        # At the start, nothing has been seen, to its all excluded:
786
 
        self.assertEqual((set(['head']), set(['child'])), search.get_recipe())
 
786
        # head has been seen:
 
787
        self.assertEqual((set(['head']), set(['child']), 1),
 
788
            search.get_recipe())
787
789
        self.assertEqual(set(['head']), search.seen)
788
790
        # using next:
789
791
        expected = [
791
793
            # - otherhead counts as seen immediately when start_searching is
792
794
            # called.
793
795
            (set(['head', 'child', 'otherhead']),
794
 
             (set(['head', 'otherhead']), set(['child', 'otherchild'])),
 
796
             (set(['head', 'otherhead']), set(['child', 'otherchild']), 2),
795
797
             ['otherhead'], ['child']),
796
798
            (set(['head', 'child', 'otherhead', 'otherchild']),
797
 
             (set(['head', 'otherhead']), set(['child', 'excluded'])),
 
799
             (set(['head', 'otherhead']), set(['child', 'excluded']), 3),
798
800
             None, None),
799
 
            # stop searchind otherexcluded now
 
801
            # stop searching excluded now
800
802
            (set(['head', 'child', 'otherhead', 'otherchild', 'excluded']),
801
 
             (set(['head', 'otherhead']), set(['child', 'excluded'])),
 
803
             (set(['head', 'otherhead']), set(['child', 'excluded']), 3),
802
804
             None, ['excluded']),
803
805
            ]
804
806
        self.assertSeenAndRecipes(expected, search, search.next)
817
819
        # using next:
818
820
        expected = [
819
821
            (set(['head']),
820
 
             (set(['head']), set(['ghost', 'child'])),
 
822
             (set(['head']), set(['ghost', 'child']), 1),
821
823
             None, None),
822
824
            (set(['head', 'child', 'ghost']),
823
 
             (set(['head']), set([NULL_REVISION, 'ghost'])),
 
825
             (set(['head']), set([NULL_REVISION, 'ghost']), 2),
824
826
             None, None),
825
827
            ]
826
828
        self.assertSeenAndRecipes(expected, search, search.next)
838
840
        # using next:
839
841
        expected = [
840
842
            (set(['head', 'ghost']),
841
 
             (set(['head', 'ghost']), set(['child', 'ghost'])),
 
843
             (set(['head', 'ghost']), set(['child', 'ghost']), 1),
842
844
             ['ghost'], None),
843
845
            (set(['head', 'child', 'ghost']),
844
 
             (set(['head', 'ghost']), set([NULL_REVISION, 'ghost'])),
845
 
             None, None),
846
 
            ]
847
 
        self.assertSeenAndRecipes(expected, search, search.next)
848
 
        # using next_with_ghosts:
849
 
        search = graph._make_breadth_first_searcher(['head'])
850
 
        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
 
846
             (set(['head', 'ghost']), set([NULL_REVISION, 'ghost']), 2),
 
847
             None, None),
 
848
            ]
 
849
        self.assertSeenAndRecipes(expected, search, search.next)
 
850
        # using next_with_ghosts:
 
851
        search = graph._make_breadth_first_searcher(['head'])
 
852
        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
 
853
 
 
854
    def test_breadth_first_revision_count_includes_NULL_REVISION(self):
 
855
        graph = self.make_graph({
 
856
            'head':[NULL_REVISION],
 
857
            NULL_REVISION:[],
 
858
            })
 
859
        search = graph._make_breadth_first_searcher(['head'])
 
860
        # using next:
 
861
        expected = [
 
862
            (set(['head']),
 
863
             (set(['head']), set([NULL_REVISION]), 1),
 
864
             None, None),
 
865
            (set(['head', NULL_REVISION]),
 
866
             (set(['head']), set([]), 2),
 
867
             None, None),
 
868
            ]
 
869
        self.assertSeenAndRecipes(expected, search, search.next)
 
870
        # using next_with_ghosts:
 
871
        search = graph._make_breadth_first_searcher(['head'])
 
872
        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
 
873
 
 
874
    def test_breadth_first_search_get_recipe_after_StopIteration(self):
 
875
        # StopIteration should not invalid anything..
 
876
        graph = self.make_graph({
 
877
            'head':[NULL_REVISION],
 
878
            NULL_REVISION:[],
 
879
            })
 
880
        search = graph._make_breadth_first_searcher(['head'])
 
881
        # using next:
 
882
        expected = [
 
883
            (set(['head']),
 
884
             (set(['head']), set([NULL_REVISION]), 1),
 
885
             None, None),
 
886
            (set(['head', 'ghost', NULL_REVISION]),
 
887
             (set(['head', 'ghost']), set(['ghost']), 2),
 
888
             ['ghost'], None),
 
889
            ]
 
890
        self.assertSeenAndRecipes(expected, search, search.next)
 
891
        self.assertRaises(StopIteration, search.next)
 
892
        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
 
893
        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
 
894
            search.get_recipe())
 
895
        # using next_with_ghosts:
 
896
        search = graph._make_breadth_first_searcher(['head'])
 
897
        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
 
898
        self.assertRaises(StopIteration, search.next)
 
899
        self.assertEqual(set(['head', 'ghost', NULL_REVISION]), search.seen)
 
900
        self.assertEqual((set(['ghost', 'head']), set(['ghost']), 2),
 
901
            search.get_recipe())
 
902
 
851
903
 
852
904
 
853
905
class TestCachingParentsProvider(tests.TestCase):