Rev 3186: Add tests for starting and stopping searches in combination with get_recipe. in http://people.ubuntu.com/~robertc/baz2.0/search-results

Robert Collins robertc at robertcollins.net
Tue Jan 15 23:26:25 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/search-results

------------------------------------------------------------
revno: 3186
revision-id:robertc at robertcollins.net-20080115232617-8ybv6rq1yqmesqzd
parent: robertc at robertcollins.net-20080115225449-wvrgig7f9763jtxd
committer: Robert Collins <robertc at robertcollins.net>
branch nick: search-results
timestamp: Wed 2008-01-16 10:26:17 +1100
message:
  Add tests for starting and stopping searches in combination with get_recipe.
modified:
  bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
  bzrlib/tests/test_graph.py     test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py	2008-01-15 22:54:49 +0000
+++ b/bzrlib/graph.py	2008-01-15 23:26:17 +0000
@@ -513,6 +513,9 @@
         self._stopped_keys = set()
         self._parents_provider = parents_provider
         self._returning = 'next_with_ghosts'
+        self._current_present = set()
+        self._current_ghosts = set()
+        self._current_parents = {}
 
     def __repr__(self):
         if self._iterations:
@@ -677,6 +680,7 @@
                 if refs == 0:
                     stop_parents.add(rev_id)
             self._next_query.difference_update(stop_parents)
+        self._stopped_keys.update(stopped)
         return stopped
 
     def start_searching(self, revisions):
@@ -688,6 +692,7 @@
         ghost/not ghost status of revisions. (A tuple (present, ghosted)).
         """
         revisions = frozenset(revisions)
+        self._started_keys.update(revisions)
         if self._returning == 'next':
             self._next_query.update(revisions.difference(self.seen))
             self.seen.update(revisions)

=== modified file 'bzrlib/tests/test_graph.py'
--- a/bzrlib/tests/test_graph.py	2008-01-15 22:54:49 +0000
+++ b/bzrlib/tests/test_graph.py	2008-01-15 23:26:17 +0000
@@ -728,15 +728,22 @@
         self.assertEqual(set(['other_2']), search.next())
         self.assertRaises(StopIteration, search.next)
 
-    def assertSeenAndRecipes(self, results, search, next):
+    def assertSeenAndRecipes(self, instructions, search, next):
         """Check the results of .seen and get_recipe() for a seach.
 
-        :param results: A list of tuples (seen, get_recipe_result).
+        :param instructions: A list of tuples (seen, get_recipe_result, starts,
+            stops). seen and get_recipe_result are results to check. starts and
+            stops are parameters to pass to start_searching and
+            stop_searching_any during each iteration, if they are not None.
         :param search: The search to use.
         :param next: A callable to advance the search.
         """
-        for seen, recipe in results:
+        for seen, recipe, starts, stops in instructions:
             next()
+            if starts is not None:
+                search.start_searching(starts)
+            if stops is not None:
+                search.stop_searching_any(stops)
             self.assertEqual(recipe, search.get_recipe())
             self.assertEqual(seen, search.seen)
 
@@ -751,15 +758,53 @@
         self.assertEqual(set(), search.seen)
         # using next:
         expected = [
-            (set(['head']), (set(['head']), set(['child']))),
-            (set(['head', 'child']), (set(['head']), set([NULL_REVISION]))),
-            (set(['head', 'child', NULL_REVISION]), (set(['head']), set())),
+            (set(['head']), (set(['head']), set(['child'])), None, None),
+            (set(['head', 'child']), (set(['head']), set([NULL_REVISION])),
+             None, None),
+            (set(['head', 'child', NULL_REVISION]), (set(['head']), set()),
+             None, None),
             ]
         self.assertSeenAndRecipes(expected, search, search.next)
         # using next_with_ghosts:
         search = graph._make_breadth_first_searcher(['head'])
         self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
 
+    def test_breadth_first_get_recipe_starts_stops(self):
+        graph = self.make_graph({
+            'head':['child'],
+            'child':[NULL_REVISION],
+            'otherhead':['otherchild'],
+            'otherchild':['excluded'],
+            'excluded':[NULL_REVISION],
+            })
+        search = graph._make_breadth_first_searcher([])
+        # Starting with nothing and adding a search works:
+        search.start_searching(['head'])
+        # At the start, nothing has been seen, to its all excluded:
+        self.assertEqual((set(['head']), set(['child'])), search.get_recipe())
+        self.assertEqual(set(['head']), search.seen)
+        # using next:
+        expected = [
+            # stop at child, and start a new search at otherhead:
+            # - otherhead counts as seen immediately when start_searching is
+            # called.
+            (set(['head', 'child', 'otherhead']),
+             (set(['head', 'otherhead']), set(['child', 'otherchild'])),
+             ['otherhead'], ['child']),
+            (set(['head', 'child', 'otherhead', 'otherchild']),
+             (set(['head', 'otherhead']), set(['child', 'excluded'])),
+             None, None),
+            # stop searchind otherexcluded now
+            (set(['head', 'child', 'otherhead', 'otherchild', 'excluded']),
+             (set(['head', 'otherhead']), set(['child', 'excluded'])),
+             None, ['excluded']),
+            ]
+        self.assertSeenAndRecipes(expected, search, search.next)
+        # using next_with_ghosts:
+        search = graph._make_breadth_first_searcher([])
+        search.start_searching(['head'])
+        self.assertSeenAndRecipes(expected, search, search.next_with_ghosts)
+
 
 class TestCachingParentsProvider(tests.TestCase):
 



More information about the bazaar-commits mailing list