Rev 2558: And overhaul TransportTestProviderAdapter too. in sftp://rookery/~/public_html/baz2.0/adapter-cleanup

Robert Collins robertc at robertcollins.net
Thu Jun 28 05:57:48 BST 2007


At sftp://rookery/~/public_html/baz2.0/adapter-cleanup

------------------------------------------------------------
revno: 2558
revision-id: robertc at robertcollins.net-20070628045744-v8b44ng9lmh5azyj
parent: robertc at robertcollins.net-20070628042515-7uktaa31hsky2nw8
committer: Robert Collins <robertc at robertcollins.net>
branch nick: adapter-cleanup
timestamp: Thu 2007-06-28 14:57:44 +1000
message:
  And overhaul TransportTestProviderAdapter too.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
=== modified file 'NEWS'
--- a/NEWS	2007-06-28 04:25:15 +0000
+++ b/NEWS	2007-06-28 04:57:44 +0000
@@ -48,11 +48,15 @@
 
   LIBRARY API BREAKS:
 
-    * ``bzrlib.repository.RepositoryTestProviderAdapter`` has been moved
-      to ``bzrlib.tests.repository_implementations``. 
+    * Testing cleanups - 
+     ``bzrlib.repository.RepositoryTestProviderAdapter`` has been moved
+      to ``bzrlib.tests.repository_implementations``;
       ``bzrlib.repository.InterRepositoryTestProviderAdapter`` has been moved
-      to ``bzrlib.tests.interrepository_implementations``.
+      to ``bzrlib.tests.interrepository_implementations``;
+      ``bzrlib.transport.TransportTestProviderAdapter`` has moved to 
+      ``bzrlib.tests.test_transport_implementations``.
       These changes are an API break in the testing infrastructure only.
+      (Robert Collins)
 
   INTERNALS:
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-06-28 01:16:43 +0000
+++ b/bzrlib/tests/__init__.py	2007-06-28 04:57:44 +0000
@@ -2340,7 +2340,7 @@
     suite = TestUtil.TestSuite()
     loader = TestUtil.TestLoader()
     suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
-    from bzrlib.transport import TransportTestProviderAdapter
+    from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
     adapter = TransportTestProviderAdapter()
     adapt_modules(test_transport_implementations, adapter, loader, suite)
     for package in packages_to_test():

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2007-06-28 04:25:15 +0000
+++ b/bzrlib/tests/test_selftest.py	2007-06-28 04:57:44 +0000
@@ -114,7 +114,8 @@
             def get_test_permutations(self):
                 return sample_permutation
         sample_permutation = [(1,2), (3,4)]
-        from bzrlib.transport import TransportTestProviderAdapter
+        from bzrlib.tests.test_transport_implementations \
+            import TransportTestProviderAdapter
         adapter = TransportTestProviderAdapter()
         self.assertEqual(sample_permutation,
                          adapter.get_transport_test_permutations(MockModule()))
@@ -125,9 +126,9 @@
         # - we assume if this matches its probably doing the right thing
         # especially in combination with the tests for setting the right
         # classes below.
-        from bzrlib.transport import (TransportTestProviderAdapter,
-                                      _get_transport_modules
-                                      )
+        from bzrlib.tests.test_transport_implementations \
+            import TransportTestProviderAdapter
+        from bzrlib.transport import _get_transport_modules
         modules = _get_transport_modules()
         permutation_count = 0
         for module in modules:
@@ -150,17 +151,16 @@
         # This test used to know about all the possible transports and the
         # order they were returned but that seems overly brittle (mbp
         # 20060307)
-        input_test = TestTransportProviderAdapter(
-            "test_adapter_sets_transport_class")
-        from bzrlib.transport import TransportTestProviderAdapter
-        suite = TransportTestProviderAdapter().adapt(input_test)
-        tests = list(iter(suite))
-        self.assertTrue(len(tests) > 6)
+        from bzrlib.tests.test_transport_implementations \
+            import TransportTestProviderAdapter
+        scenarios = TransportTestProviderAdapter().scenarios
         # there are at least that many builtin transports
-        one_test = tests[0]
-        self.assertTrue(issubclass(one_test.transport_class, 
+        self.assertTrue(len(scenarios) > 6)
+        one_scenario = scenarios[0]
+        self.assertIsInstance(one_scenario[0], str)
+        self.assertTrue(issubclass(one_scenario[1]["transport_class"],
                                    bzrlib.transport.Transport))
-        self.assertTrue(issubclass(one_test.transport_server, 
+        self.assertTrue(issubclass(one_scenario[1]["transport_server"],
                                    bzrlib.transport.Server))
 
 

=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py	2007-05-02 14:36:55 +0000
+++ b/bzrlib/tests/test_transport_implementations.py	2007-06-28 04:57:44 +0000
@@ -25,6 +25,7 @@
 from StringIO import StringIO as pyStringIO
 import stat
 import sys
+import unittest
 
 from bzrlib import (
     errors,
@@ -45,12 +46,53 @@
 from bzrlib.osutils import getcwd
 from bzrlib.smart import medium
 from bzrlib.symbol_versioning import zero_eleven
-from bzrlib.tests import TestCaseInTempDir, TestSkipped
+from bzrlib.tests import TestCaseInTempDir, TestScenarioApplier, TestSkipped
 from bzrlib.tests.test_transport import TestTransportImplementation
-from bzrlib.transport import memory, remote
+from bzrlib.transport import memory, remote, _get_transport_modules
 import bzrlib.transport
 
 
+class TransportTestProviderAdapter(TestScenarioApplier):
+    """A tool to generate a suite testing all transports for a single test.
+
+    This is done by copying the test once for each transport and injecting
+    the transport_class and transport_server classes into each copy. Each copy
+    is also given a new id() to make it easy to identify.
+    """
+
+    def __init__(self):
+        self.scenarios = self._test_permutations()
+
+    def get_transport_test_permutations(self, module):
+        """Get the permutations module wants to have tested."""
+        if getattr(module, 'get_test_permutations', None) is None:
+            raise AssertionError("transport module %s doesn't provide get_test_permutations()"
+                    % module.__name__)
+            ##warning("transport module %s doesn't provide get_test_permutations()"
+            ##       % module.__name__)
+            return []
+        return module.get_test_permutations()
+
+    def _test_permutations(self):
+        """Return a list of the klass, server_factory pairs to test."""
+        result = []
+        for module in _get_transport_modules():
+            try:
+                permutations = self.get_transport_test_permutations(
+                    reduce(getattr, (module).split('.')[1:], __import__(module)))
+                for (klass, server_factory) in permutations:
+                    scenario = (server_factory.__name__,
+                        {"transport_class":klass,
+                         "transport_server":server_factory})
+                    result.append(scenario)
+            except errors.DependencyNotPresent, e:
+                # Continue even if a dependency prevents us 
+                # from running this test
+                pass
+        return result
+
+
+
 class TransportTests(TestTransportImplementation):
 
     def setUp(self):

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2007-05-08 20:00:50 +0000
+++ b/bzrlib/transport/__init__.py	2007-06-28 04:57:44 +0000
@@ -1177,52 +1177,6 @@
         raise NotImplementedError
 
 
-class TransportTestProviderAdapter(object):
-    """A tool to generate a suite testing all transports for a single test.
-
-    This is done by copying the test once for each transport and injecting
-    the transport_class and transport_server classes into each copy. Each copy
-    is also given a new id() to make it easy to identify.
-    """
-
-    def adapt(self, test):
-        result = unittest.TestSuite()
-        for klass, server_factory in self._test_permutations():
-            new_test = deepcopy(test)
-            new_test.transport_class = klass
-            new_test.transport_server = server_factory
-            def make_new_test_id():
-                new_id = "%s(%s)" % (new_test.id(), server_factory.__name__)
-                return lambda: new_id
-            new_test.id = make_new_test_id()
-            result.addTest(new_test)
-        return result
-
-    def get_transport_test_permutations(self, module):
-        """Get the permutations module wants to have tested."""
-        if getattr(module, 'get_test_permutations', None) is None:
-            raise AssertionError("transport module %s doesn't provide get_test_permutations()"
-                    % module.__name__)
-            ##warning("transport module %s doesn't provide get_test_permutations()"
-            ##       % module.__name__)
-            return []
-        return module.get_test_permutations()
-
-    def _test_permutations(self):
-        """Return a list of the klass, server_factory pairs to test."""
-        result = []
-        for module in _get_transport_modules():
-            try:
-                result.extend(self.get_transport_test_permutations(reduce(getattr, 
-                    (module).split('.')[1:],
-                     __import__(module))))
-            except errors.DependencyNotPresent, e:
-                # Continue even if a dependency prevents us 
-                # from running this test
-                pass
-        return result
-
-
 class TransportLogger(object):
     """Adapt a transport to get clear logging data on api calls.
     



More information about the bazaar-commits mailing list