Rev 4934: Implement a permute_for_extension helper. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-permute-for-extension

John Arbash Meinel john at arbash-meinel.com
Tue Dec 22 16:29:01 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-permute-for-extension

------------------------------------------------------------
revno: 4934
revision-id: john at arbash-meinel.com-20091222162847-tvnsc69to4l4uf5r
parent: john at arbash-meinel.com-20091222155040-g78hejkqvzplsoo1
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-permute-for-extension
timestamp: Tue 2009-12-22 10:28:47 -0600
message:
  Implement a permute_for_extension helper.
  
  Use it for all of the 'simple' extension permutations.
  It basically permutes all tests in the current module, by setting TestCase.module.
  Which works well for most of our extension tests. Some had more advanced
  handling of permutations (extra permutations, custom vars, etc.)
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2009-12-18 09:05:13 +0000
+++ b/NEWS	2009-12-22 16:28:47 +0000
@@ -23,6 +23,12 @@
   ``locations.conf`` or ``branch.conf``.
   (Ted Gould, Matthew Fuller, Vincent Ladeuil)
 
+* ``bzrlib.tests.permute_for_extension`` is a helper that simplifies
+  running all tests in the current module, once against a pure python
+  implementation, and once against an extension (pyrex/C) implementation.
+  It can be used to dramatically simplify the implementation of
+  ``load_tests``.  (John Arbash Meinel)
+
 Bug Fixes
 *********
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-12-22 15:37:23 +0000
+++ b/bzrlib/tests/__init__.py	2009-12-22 16:28:47 +0000
@@ -4139,6 +4139,26 @@
     return new_test
 
 
+def permute_tests_for_extension(standard_tests, loader, py_module_name,
+                                ext_module_name):
+    py_module = __import__(py_module_name, {}, {}, ['NO_SUCH_ATTRIB'])
+    scenarios = [
+        ('python', {'module': py_module}),
+    ]
+    suite = loader.suiteClass()
+    feature = ModuleAvailableFeature(ext_module_name)
+    if feature.available():
+        scenarios.append(('C', {'module': feature.module}))
+    else:
+        # the compiled module isn't available, so we add a failing test
+        class FailWithoutFeature(TestCase):
+            def test_fail(self):
+                self.requireFeature(feature)
+        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
+    result = multiply_tests(standard_tests, scenarios, suite)
+    return result, feature
+
+
 def _rmtree_temp_dir(dirname, test_id=None):
     # If LANG=C we probably have created some bogus paths
     # which rmtree(unicode) will fail to delete

=== modified file 'bzrlib/tests/test__annotator.py'
--- a/bzrlib/tests/test__annotator.py	2009-12-22 15:50:40 +0000
+++ b/bzrlib/tests/test__annotator.py	2009-12-22 16:28:47 +0000
@@ -28,26 +28,11 @@
 
 def load_tests(standard_tests, module, loader):
     """Parameterize tests for all versions of groupcompress."""
-    scenarios = [
-        ('python', {'module': _annotator_py}),
-    ]
-    suite = loader.suiteClass()
-    if compiled_annotator_feature.available():
-        scenarios.append(('C', {'module': compiled_annotator_feature.module}))
-    else:
-        # the compiled module isn't available, so we add a failing test
-        class FailWithoutFeature(tests.TestCase):
-            def test_fail(self):
-                self.requireFeature(compiled_annotator_feature)
-        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
-    result = tests.multiply_tests(standard_tests, scenarios, suite)
+    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
+        'bzrlib._annotator_py', 'bzrlib._annotator_pyx')
     return result
 
 
-compiled_annotator_feature = tests.ModuleAvailableFeature(
-                                'bzrlib._annotator_pyx')
-
-
 class TestAnnotator(tests.TestCaseWithMemoryTransport):
 
     module = None # Set by load_tests

=== modified file 'bzrlib/tests/test__chk_map.py'
--- a/bzrlib/tests/test__chk_map.py	2009-12-22 15:50:40 +0000
+++ b/bzrlib/tests/test__chk_map.py	2009-12-22 16:28:47 +0000
@@ -25,25 +25,11 @@
 
 
 def load_tests(standard_tests, module, loader):
-    # parameterize all tests in this module
-    suite = loader.suiteClass()
-    import bzrlib._chk_map_py as py_module
-    scenarios = [('python', {'module': py_module})]
-    if compiled_chkmap_feature.available():
-        scenarios.append(('C', {'module': compiled_chkmap_feature.module}))
-    else:
-        # the compiled module isn't available, so we add a failing test
-        class FailWithoutFeature(tests.TestCase):
-            def test_fail(self):
-                self.requireFeature(compiled_chkmap_feature)
-        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
-    tests.multiply_tests(standard_tests, scenarios, suite)
+    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
+        'bzrlib._chk_map_py', 'bzrlib._chk_map_pyx')
     return suite
 
 
-compiled_chkmap_feature = tests.ModuleAvailableFeature('bzrlib._chk_map_pyx')
-
-
 class TestSearchKeys(tests.TestCase):
 
     module = None # Filled in by test parameterization

=== modified file 'bzrlib/tests/test__chunks_to_lines.py'
--- a/bzrlib/tests/test__chunks_to_lines.py	2009-12-22 15:50:40 +0000
+++ b/bzrlib/tests/test__chunks_to_lines.py	2009-12-22 16:28:47 +0000
@@ -21,23 +21,9 @@
 
 
 def load_tests(standard_tests, module, loader):
-    # parameterize all tests in this module
-    import bzrlib._chunks_to_lines_py as py_module
-    scenarios = [('python', {'module': py_module})]
-    if compiled_chunkstolines_feature.available():
-        scenarios.append(('C', {'module':
-                                compiled_chunkstolines_feature.module}))
-    else:
-        # the compiled module isn't available, so we add a failing test
-        class FailWithoutFeature(tests.TestCase):
-            def test_fail(self):
-                self.requireFeature(compiled_chunkstolines_feature)
-        standard_tests.addTest(FailWithoutFeature("test_fail"))
-    return tests.multiply_tests(standard_tests, scenarios, loader.suiteClass())
-
-
-compiled_chunkstolines_feature = tests.ModuleAvailableFeature(
-                                    'bzrlib._chunks_to_lines_pyx')
+    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
+        'bzrlib._chunks_to_lines_py', 'bzrlib._chunks_to_lines_pyx')
+    return suite
 
 
 class TestChunksToLines(tests.TestCase):

=== modified file 'bzrlib/tests/test__rio.py'
--- a/bzrlib/tests/test__rio.py	2009-12-22 15:50:40 +0000
+++ b/bzrlib/tests/test__rio.py	2009-12-22 16:28:47 +0000
@@ -23,25 +23,11 @@
 
 
 def load_tests(standard_tests, module, loader):
-    # parameterize all tests in this module
-    suite = loader.suiteClass()
-    import bzrlib._rio_py as py_module
-    scenarios = [('python', {'module': py_module})]
-    if compiled_rio_feature.available():
-        scenarios.append(('C', {'module': compiled_rio_feature.module}))
-    else:
-        # the compiled module isn't available, so we add a failing test
-        class FailWithoutFeature(tests.TestCase):
-            def test_fail(self):
-                self.requireFeature(compiled_rio_feature)
-        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
-    tests.multiply_tests(standard_tests, scenarios, suite)
+    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
+        'bzrlib._rio_py', 'bzrlib._rio_pyx')
     return suite
 
 
-compiled_rio_feature = tests.ModuleAvailableFeature('bzrlib._rio_pyx')
-
-
 class TestValidTag(tests.TestCase):
 
     module = None # Filled in by test parameterization

=== modified file 'bzrlib/tests/test__static_tuple.py'
--- a/bzrlib/tests/test__static_tuple.py	2009-12-22 15:50:40 +0000
+++ b/bzrlib/tests/test__static_tuple.py	2009-12-22 16:28:47 +0000
@@ -32,25 +32,11 @@
 
 def load_tests(standard_tests, module, loader):
     """Parameterize tests for all versions of groupcompress."""
-    scenarios = [
-        ('python', {'module': _static_tuple_py}),
-    ]
-    suite = loader.suiteClass()
-    if compiled_static_tuple_feature.available():
-        scenarios.append(('C', {'module':
-                                compiled_static_tuple_feature.module}))
-    else:
-        # the compiled module isn't available, so we add a failing test
-        class FailWithoutFeature(tests.TestCase):
-            def test_fail(self):
-                self.requireFeature(compiled_static_tuple_feature)
-        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
-    result = tests.multiply_tests(standard_tests, scenarios, suite)
-    return result
-
-
-compiled_static_tuple_feature = tests.ModuleAvailableFeature(
-                                    'bzrlib._static_tuple_c')
+    global compiled_static_tuple_feature
+    suite, compiled_static_tuple_feature = tests.permute_tests_for_extension(
+        standard_tests, loader, 'bzrlib._static_tuple_py',
+        'bzrlib._static_tuple_c')
+    return suite
 
 
 class _Meliae(tests.Feature):

=== modified file 'bzrlib/tests/test_bencode.py'
--- a/bzrlib/tests/test_bencode.py	2009-12-22 15:50:40 +0000
+++ b/bzrlib/tests/test_bencode.py	2009-12-22 16:28:47 +0000
@@ -19,25 +19,11 @@
 from bzrlib import tests
 
 def load_tests(standard_tests, module, loader):
-    # parameterize all tests in this module
-    suite = loader.suiteClass()
-    import bzrlib.util._bencode_py as py_module
-    scenarios = [('python', {'bencode': py_module})]
-    if compiled_bencode_feature.available():
-        scenarios.append(('C', {'bencode': compiled_bencode_feature.module}))
-    else:
-        # the compiled module isn't available, so we add a failing test
-        class FailWithoutFeature(tests.TestCase):
-            def test_fail(self):
-                self.requireFeature(compiled_bencode_feature)
-        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
-    tests.multiply_tests(standard_tests, scenarios, suite)
+    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
+        'bzrlib.util._bencode_py', 'bzrlib._bencode_pyx')
     return suite
 
 
-compiled_bencode_feature = tests.ModuleAvailableFeature('bzrlib._bencode_pyx')
-
-
 class TestBencodeDecode(tests.TestCase):
 
     bencode = None



More information about the bazaar-commits mailing list