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

Robert Collins robertc at robertcollins.net
Thu Jun 28 07:01:22 BST 2007


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

------------------------------------------------------------
revno: 2560
revision-id: robertc at robertcollins.net-20070628060118-wpuciqx1xrjesces
parent: robertc at robertcollins.net-20070628051904-mjbhgq3n8dw3m8jg
committer: Robert Collins <robertc at robertcollins.net>
branch nick: adapter-cleanup
timestamp: Thu 2007-06-28 16:01:18 +1000
message:
  And overhaul BzrDirTestProviderAdapter too.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/bzrdir_implementations/__init__.py __init__.py-20060131065642-34c39b54f42dd048
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS	2007-06-28 05:19:04 +0000
+++ b/NEWS	2007-06-28 06:01:18 +0000
@@ -57,6 +57,8 @@
       ``bzrlib.tests.test_transport_implementations``.
       ``bzrlib.branch.BranchTestProviderAdapter`` has moved to
       ``bzrlib.tests.branch_implementations``.
+      ``bzrlib.bzrdir.BzrDirTestProviderAdapter`` has moved to 
+      ``bzrlib.tests.bzrdir_implementations``.
       These changes are an API break in the testing infrastructure only.
       (Robert Collins)
 

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-05-02 14:54:20 +0000
+++ b/bzrlib/bzrdir.py	2007-06-28 06:01:18 +0000
@@ -20,8 +20,6 @@
 directories.
 """
 
-# TODO: remove unittest dependency; put that stuff inside the test suite
-
 # TODO: Can we move specific formats into separate modules to make this file
 # smaller?
 
@@ -31,9 +29,7 @@
 
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
-from copy import deepcopy
 from stat import S_ISDIR
-import unittest
 
 import bzrlib
 from bzrlib import (
@@ -1700,43 +1696,6 @@
 BzrDirFormat._default_format = __default_format
 
 
-class BzrDirTestProviderAdapter(object):
-    """A tool to generate a suite testing multiple bzrdir formats at once.
-
-    This is done by copying the test once for each transport and injecting
-    the transport_server, transport_readonly_server, and bzrdir_format
-    classes into each copy. Each copy is also given a new id() to make it
-    easy to identify.
-    """
-
-    def __init__(self, vfs_factory, transport_server, transport_readonly_server,
-        formats):
-        """Create an object to adapt tests.
-
-        :param vfs_server: A factory to create a Transport Server which has
-            all the VFS methods working, and is writable.
-        """
-        self._vfs_factory = vfs_factory
-        self._transport_server = transport_server
-        self._transport_readonly_server = transport_readonly_server
-        self._formats = formats
-    
-    def adapt(self, test):
-        result = unittest.TestSuite()
-        for format in self._formats:
-            new_test = deepcopy(test)
-            new_test.vfs_transport_factory = self._vfs_factory
-            new_test.transport_server = self._transport_server
-            new_test.transport_readonly_server = self._transport_readonly_server
-            new_test.bzrdir_format = format
-            def make_new_test_id():
-                new_id = "%s(%s)" % (new_test.id(), format.__class__.__name__)
-                return lambda: new_id
-            new_test.id = make_new_test_id()
-            result.addTest(new_test)
-        return result
-
-
 class Converter(object):
     """Converts a disk format object from one format to another."""
 

=== modified file 'bzrlib/tests/bzrdir_implementations/__init__.py'
--- a/bzrlib/tests/bzrdir_implementations/__init__.py	2007-05-01 22:41:41 +0000
+++ b/bzrlib/tests/bzrdir_implementations/__init__.py	2007-06-28 06:01:18 +0000
@@ -24,17 +24,56 @@
 rather than in tests/branch_implementations/*.py.
 """
 
-from bzrlib.bzrdir import BzrDirTestProviderAdapter, BzrDirFormat
+from bzrlib.bzrdir import BzrDirFormat
 from bzrlib.tests import (
                           adapt_modules,
                           default_transport,
                           TestCaseWithTransport,
                           TestLoader,
+                          TestScenarioApplier,
                           TestSuite,
                           )
 from bzrlib.transport.memory import MemoryServer
 
 
+class BzrDirTestProviderAdapter(TestScenarioApplier):
+    """A tool to generate a suite testing multiple bzrdir formats at once.
+
+    This is done by copying the test once for each transport and injecting
+    the transport_server, transport_readonly_server, and bzrdir_format
+    classes into each copy. Each copy is also given a new id() to make it
+    easy to identify.
+    """
+
+    def __init__(self, vfs_factory, transport_server, transport_readonly_server,
+        formats):
+        """Create an object to adapt tests.
+
+        :param vfs_server: A factory to create a Transport Server which has
+            all the VFS methods working, and is writable.
+        """
+        self._vfs_factory = vfs_factory
+        self._transport_server = transport_server
+        self._transport_readonly_server = transport_readonly_server
+        self.scenarios = self.formats_to_scenarios(formats)
+    
+    def formats_to_scenarios(self, formats):
+        """Transform the input formats to a list of scenarios.
+
+        :param formats: A list of bzrdir_format objects.
+        """
+        result = []
+        for format in formats:
+            scenario = (format.__class__.__name__, {
+                "vfs_transport_factory":self._vfs_factory,
+                "transport_server":self._transport_server,
+                "transport_readonly_server":self._transport_readonly_server,
+                "bzrdir_format":format,
+                })
+            result.append(scenario)
+        return result
+
+
 class TestCaseWithBzrDir(TestCaseWithTransport):
 
     def setUp(self):

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2007-06-28 05:19:04 +0000
+++ b/bzrlib/tests/test_selftest.py	2007-06-28 06:01:18 +0000
@@ -196,26 +196,25 @@
     def test_adapted_tests(self):
         # check that constructor parameters are passed through to the adapted
         # test.
-        from bzrlib.bzrdir import BzrDirTestProviderAdapter
-        input_test = TestBzrDirProviderAdapter(
-            "test_adapted_tests")
+        from bzrlib.tests.bzrdir_implementations import BzrDirTestProviderAdapter
         vfs_factory = "v"
         server1 = "a"
         server2 = "b"
         formats = ["c", "d"]
         adapter = BzrDirTestProviderAdapter(vfs_factory,
             server1, server2, formats)
-        suite = adapter.adapt(input_test)
-        tests = list(iter(suite))
-        self.assertEqual(2, len(tests))
-        self.assertEqual(tests[0].bzrdir_format, formats[0])
-        self.assertEqual(tests[0].vfs_transport_factory, vfs_factory)
-        self.assertEqual(tests[0].transport_server, server1)
-        self.assertEqual(tests[0].transport_readonly_server, server2)
-        self.assertEqual(tests[1].bzrdir_format, formats[1])
-        self.assertEqual(tests[1].vfs_transport_factory, vfs_factory)
-        self.assertEqual(tests[1].transport_server, server1)
-        self.assertEqual(tests[1].transport_readonly_server, server2)
+        self.assertEqual([
+            ('str',
+             {'bzrdir_format': 'c',
+              'transport_readonly_server': 'b',
+              'transport_server': 'a',
+              'vfs_transport_factory': 'v'}),
+            ('str',
+             {'bzrdir_format': 'd',
+              'transport_readonly_server': 'b',
+              'transport_server': 'a',
+              'vfs_transport_factory': 'v'})],
+            adapter.scenarios)
 
 
 class TestRepositoryProviderAdapter(TestCase):



More information about the bazaar-commits mailing list