Rev 416: Add some tests for _iterate_sufficiently. in http://bazaar.launchpad.net/~jameinel/loggerhead/page_loading

John Arbash Meinel john at arbash-meinel.com
Sat Mar 12 15:27:45 UTC 2011


At http://bazaar.launchpad.net/~jameinel/loggerhead/page_loading

------------------------------------------------------------
revno: 416
revision-id: john at arbash-meinel.com-20110312152740-9uq3n0m1zbz194s7
parent: john at arbash-meinel.com-20110312151502-1jf0iefjucvkw3qm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: page_loading
timestamp: Sat 2011-03-12 16:27:40 +0100
message:
  Add some tests for _iterate_sufficiently.
  
  Turn it into a staticmethod, to be easier to test.
  Find out we had the edge counting wrong. Not critical, but might as
  well make it match what we expected.
-------------- next part --------------
=== modified file 'loggerhead/history.py'
--- a/loggerhead/history.py	2011-03-12 15:15:02 +0000
+++ b/loggerhead/history.py	2011-03-12 15:27:40 +0000
@@ -1,5 +1,4 @@
-#
-# Copyright (C) 2008, 2009 Canonical Ltd.
+# Copyright (C) 2006-2011 Canonical Ltd.
 #                     (Authored by Martin Albisetti <argentina at gmail.com>)
 # Copyright (C) 2006  Robey Pointer <robey at lag.net>
 # Copyright (C) 2006  Goffredo Baroncelli <kreijack at inwind.it>
@@ -480,7 +479,8 @@
             revlist = self.get_revids_from(None, revid)
         return revlist
 
-    def _iterate_sufficiently(self, iterable, stop_at, extra_rev_count):
+    @staticmethod
+    def _iterate_sufficiently(iterable, stop_at, extra_rev_count):
         """Return a list of iterable.
 
         If extra_rev_count is None, fully consume iterable.
@@ -500,9 +500,9 @@
                 break
         if found:
             for count, n in enumerate(iterable):
+                if count >= extra_rev_count:
+                    break
                 result.append(n)
-                if count >= extra_rev_count:
-                    break
         return result
 
     def get_view(self, revid, start_revid, file_id, query=None,

=== modified file 'loggerhead/tests/test_history.py'
--- a/loggerhead/tests/test_history.py	2011-03-11 09:50:24 +0000
+++ b/loggerhead/tests/test_history.py	2011-03-12 15:27:40 +0000
@@ -112,3 +112,31 @@
         self.assertRevidsFrom(['F'], his, ['C'], 'F')
         self.assertRevidsFrom(['B'], his, ['B'], 'F')
         self.assertRevidsFrom(['A'], his, ['A'], 'F')
+
+
+
+class TestHistory_IterateSufficiently(tests.TestCase):
+
+    def assertIterate(self, expected, iterable, stop_at, extra_rev_count):
+        self.assertEqual(expected, history.History._iterate_sufficiently(
+            iterable, stop_at, extra_rev_count))
+
+    def test_iter_no_extra(self):
+        lst = list('abcdefghijklmnopqrstuvwxyz')
+        self.assertIterate(['a', 'b', 'c'], iter(lst), 'c', 0)
+        self.assertIterate(['a', 'b', 'c', 'd'], iter(lst), 'd', 0)
+
+    def test_iter_not_found(self):
+        # If the key in question isn't found, we just exhaust the list
+        lst = list('abcdefghijklmnopqrstuvwxyz')
+        self.assertIterate(lst, iter(lst), 'not-there', 0)
+
+    def test_iter_with_extra(self):
+        lst = list('abcdefghijklmnopqrstuvwxyz')
+        self.assertIterate(['a', 'b', 'c'], iter(lst), 'b', 1)
+        self.assertIterate(['a', 'b', 'c', 'd', 'e'], iter(lst), 'c', 2)
+
+    def test_iter_with_too_many_extra(self):
+        lst = list('abcdefghijklmnopqrstuvwxyz')
+        self.assertIterate(lst, iter(lst), 'y', 10)
+        self.assertIterate(lst, iter(lst), 'z', 10)



More information about the bazaar-commits mailing list