Rev 2495: Cleanup the multiple testing. in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex

John Arbash Meinel john at arbash-meinel.com
Fri May 4 19:06:10 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex

------------------------------------------------------------
revno: 2495
revision-id: john at arbash-meinel.com-20070504180557-iaitatth56jygggl
parent: john at arbash-meinel.com-20070504174616-4kdi7zi32h7ev4f9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate_pyrex
timestamp: Fri 2007-05-04 13:05:57 -0500
message:
  Cleanup the multiple testing.
  Change the function names from both being 'bisect_dirblocks' to being
  py_bisect_dirblocks and c_bisect_dirblocks.
  And enable using the compiled form when it is available.
modified:
  bzrlib/benchmarks/bench_dirstate.py bench_dirstate.py-20070503203500-gs0pz6zkvjpq9l2x-1
  bzrlib/compiled/dirstate_helpers.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/compiled/test_dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
  bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
-------------- next part --------------
=== modified file 'bzrlib/benchmarks/bench_dirstate.py'
--- a/bzrlib/benchmarks/bench_dirstate.py	2007-05-04 16:03:30 +0000
+++ b/bzrlib/benchmarks/bench_dirstate.py	2007-05-04 18:05:57 +0000
@@ -150,35 +150,35 @@
         offset_str = '\n'.join(str(x) for x in offsets)
         self.assertEqualDiff(expected_str, offset_str)
 
-    def test_bisect_dirblock(self):
+    def test_py_bisect_dirblock(self):
         state = self.build_10k_dirstate_dirs()
         state.lock_read()
         try:
             self.setup_paths_and_offsets(state)
-            offsets = self.time(self.do_bisect_list, dirstate.bisect_dirblock)
+            offsets = self.time(self.do_bisect_list, dirstate.py_bisect_dirblock)
             self.checkOffsets(offsets)
         finally:
             state.unlock()
 
-    def test_bisect_dirblock_cached(self):
+    def test_py_bisect_dirblock_cached(self):
         state = self.build_10k_dirstate_dirs()
         state.lock_read()
         try:
             self.setup_paths_and_offsets(state)
             offsets = self.time(self.do_bisect_list_cached,
-                                dirstate.bisect_dirblock)
+                                dirstate.py_bisect_dirblock)
             self.checkOffsets(offsets)
         finally:
             state.unlock()
 
-    def test_bisect_dirblock_compiled(self):
+    def test_c_bisect_dirblock(self):
         self.requireFeature(CompiledDirstateHelpersFeature)
-        from bzrlib.compiled.dirstate_helpers import bisect_dirblock
+        from bzrlib.compiled.dirstate_helpers import c_bisect_dirblock
         state = self.build_10k_dirstate_dirs()
         state.lock_read()
         try:
             self.setup_paths_and_offsets(state)
-            offsets = self.time(self.do_bisect_list, bisect_dirblock)
+            offsets = self.time(self.do_bisect_list, c_bisect_dirblock)
             self.checkOffsets(offsets)
         finally:
             state.unlock()

=== modified file 'bzrlib/compiled/dirstate_helpers.pyx'
--- a/bzrlib/compiled/dirstate_helpers.pyx	2007-05-04 17:36:00 +0000
+++ b/bzrlib/compiled/dirstate_helpers.pyx	2007-05-04 18:05:57 +0000
@@ -134,7 +134,7 @@
                                  PyString_Size(path2))
 
 
-def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache=None):
+def c_bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache=None):
     """Return the index where to insert dirname into the dirblocks.
 
     The return value idx is such that all directories blocks in dirblock[:idx]

=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-05-03 20:11:37 +0000
+++ b/bzrlib/dirstate.py	2007-05-04 18:05:57 +0000
@@ -2254,7 +2254,7 @@
             raise errors.ObjectNotLocked(self)
 
 
-def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
+def py_bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
     """Return the index where to insert dirname into the dirblocks.
 
     The return value idx is such that all directories blocks in dirblock[:idx]
@@ -2284,6 +2284,10 @@
         else: hi = mid
     return lo
 
+# This is the function that will be used
+# But it may be overridden by the compiled version
+bisect_dirblock = py_bisect_dirblock
+
 
 
 def pack_stat(st, _encode=base64.encodestring, _pack=struct.pack):
@@ -2408,6 +2412,11 @@
 # TODO: jam 20070503 We should have a way to run tests with and without the
 #       compiled extensions.
 try:
-    from bzrlib.compiled.dirstate_helpers import _read_dirblocks
+    from bzrlib.compiled.dirstate_helpers import (
+        _read_dirblocks,
+        c_bisect_dirblock,
+        )
 except ImportError:
     pass
+else:
+    bisect_dirblock = c_bisect_dirblock

=== modified file 'bzrlib/tests/compiled/test_dirstate_helpers.py'
--- a/bzrlib/tests/compiled/test_dirstate_helpers.py	2007-05-04 17:46:16 +0000
+++ b/bzrlib/tests/compiled/test_dirstate_helpers.py	2007-05-04 18:05:57 +0000
@@ -149,8 +149,11 @@
 
     _test_needs_features = [CompiledDirstateHelpersFeature]
 
-    if have_dirstate_helpers:
-        bisect_dirblock_func = dirstate_helpers.bisect_dirblock
-    else:
-        bisect_dirblock_func = None
-
+    def setUp(self):
+        super(TestCompiledBisectDirblock, self).setUp()
+        if have_dirstate_helpers:
+            self.bisect_dirblock_func = dirstate_helpers.c_bisect_dirblock
+        else:
+            # We shouldn't be running these tests because of the
+            # _test_needs_features, so make sure they would fail otherwise
+            self.bisect_dirblock_func = None

=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py	2007-05-04 17:46:16 +0000
+++ b/bzrlib/tests/test_dirstate.py	2007-05-04 18:05:57 +0000
@@ -1977,7 +1977,12 @@
     'to', 'foo') chunks rather than by raw 'path/to/foo'.
     """
 
-    bisect_dirblock_func = dirstate.bisect_dirblock
+    def setUp(self):
+        super(TestBisectDirblock, self).setUp()
+        # We have to set this here, because if we set it at the class variable
+        # level, Python interprets it as a member function, and passes 'self'
+        # as the first argument.
+        self.bisect_dirblock_func = dirstate.py_bisect_dirblock
 
     def assertBisect(self, dirblocks, split_dirblocks, path, *args, **kwargs):
         """Assert that bisect_split works like bisect_left on the split paths.
@@ -1988,6 +1993,7 @@
 
         All other arguments will be passed along.
         """
+        self.assertIsInstance(dirblocks, list)
         bisect_split_idx = self.bisect_dirblock_func(dirblocks, path,
                                                      *args, **kwargs)
         split_dirblock = (path.split('/'), [])



More information about the bazaar-commits mailing list