Rev 2559: And overhaul BranchTestProviderAdapter too. in sftp://rookery/~/public_html/baz2.0/adapter-cleanup
Robert Collins
robertc at robertcollins.net
Thu Jun 28 06:19:08 BST 2007
At sftp://rookery/~/public_html/baz2.0/adapter-cleanup
------------------------------------------------------------
revno: 2559
revision-id: robertc at robertcollins.net-20070628051904-mjbhgq3n8dw3m8jg
parent: robertc at robertcollins.net-20070628045744-v8b44ng9lmh5azyj
committer: Robert Collins <robertc at robertcollins.net>
branch nick: adapter-cleanup
timestamp: Thu 2007-06-28 15:19:04 +1000
message:
And overhaul BranchTestProviderAdapter too.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
=== modified file 'NEWS'
--- a/NEWS 2007-06-28 04:57:44 +0000
+++ b/NEWS 2007-06-28 05:19:04 +0000
@@ -55,6 +55,8 @@
to ``bzrlib.tests.interrepository_implementations``;
``bzrlib.transport.TransportTestProviderAdapter`` has moved to
``bzrlib.tests.test_transport_implementations``.
+ ``bzrlib.branch.BranchTestProviderAdapter`` has moved to
+ ``bzrlib.tests.branch_implementations``.
These changes are an API break in the testing infrastructure only.
(Robert Collins)
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-06-21 03:29:39 +0000
+++ b/bzrlib/branch.py 2007-06-28 05:19:04 +0000
@@ -19,8 +19,6 @@
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
-from copy import deepcopy
-from unittest import TestSuite
from warnings import warn
import bzrlib
@@ -2099,40 +2097,6 @@
return BasicTags(self)
-class BranchTestProviderAdapter(object):
- """A tool to generate a suite testing multiple branch formats at once.
-
- This is done by copying the test once for each transport and injecting
- the transport_server, transport_readonly_server, and branch_format
- classes into each copy. Each copy is also given a new id() to make it
- easy to identify.
- """
-
- def __init__(self, transport_server, transport_readonly_server, formats,
- vfs_transport_factory=None):
- self._transport_server = transport_server
- self._transport_readonly_server = transport_readonly_server
- self._formats = formats
-
- def adapt(self, test):
- result = TestSuite()
- for branch_format, bzrdir_format in self._formats:
- new_test = deepcopy(test)
- new_test.transport_server = self._transport_server
- new_test.transport_readonly_server = self._transport_readonly_server
- new_test.bzrdir_format = bzrdir_format
- new_test.branch_format = branch_format
- def make_new_test_id():
- # the format can be either a class or an instance
- name = getattr(branch_format, '__name__',
- branch_format.__class__.__name__)
- new_id = "%s(%s)" % (new_test.id(), name)
- return lambda: new_id
- new_test.id = make_new_test_id()
- result.addTest(new_test)
- return result
-
-
######################################################################
# results of operations
=== modified file 'bzrlib/tests/branch_implementations/__init__.py'
--- a/bzrlib/tests/branch_implementations/__init__.py 2007-06-12 16:21:40 +0000
+++ b/bzrlib/tests/branch_implementations/__init__.py 2007-06-28 05:19:04 +0000
@@ -29,7 +29,6 @@
tests,
)
from bzrlib.branch import (BranchFormat,
- BranchTestProviderAdapter,
_legacy_formats,
)
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
@@ -41,6 +40,42 @@
from bzrlib.transport.memory import MemoryServer
+class BranchTestProviderAdapter(tests.TestScenarioApplier):
+ """A tool to generate a suite testing multiple branch formats at once.
+
+ This is done by copying the test once for each transport and injecting
+ the transport_server, transport_readonly_server, and branch_format
+ classes into each copy. Each copy is also given a new id() to make it
+ easy to identify.
+ """
+
+ def __init__(self, transport_server, transport_readonly_server, formats,
+ vfs_transport_factory=None):
+ 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 (branch_format, bzrdir_format).
+ """
+ result = []
+ for branch_format, bzrdir_format in formats:
+ # some branches don't have separate format objects.
+ # so we have a conditional here to handle them.
+ scenario_name = getattr(branch_format, '__name__',
+ branch_format.__class__.__name__)
+ scenario = (scenario_name, {
+ "transport_server":self._transport_server,
+ "transport_readonly_server":self._transport_readonly_server,
+ "bzrdir_format":bzrdir_format,
+ "branch_format":branch_format,
+ })
+ result.append(scenario)
+ return result
+
+
class TestCaseWithBranch(TestCaseWithBzrDir):
"""This helper will be adapted for each branch_implementation test."""
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2007-06-28 04:57:44 +0000
+++ b/bzrlib/tests/test_selftest.py 2007-06-28 05:19:04 +0000
@@ -167,27 +167,27 @@
class TestBranchProviderAdapter(TestCase):
"""A group of tests that test the branch implementation test adapter."""
- def test_adapted_tests(self):
+ def test_constructor(self):
# check that constructor parameters are passed through to the adapted
# test.
- from bzrlib.branch import BranchTestProviderAdapter
- input_test = TestBranchProviderAdapter(
- "test_adapted_tests")
+ from bzrlib.tests.branch_implementations import BranchTestProviderAdapter
server1 = "a"
server2 = "b"
formats = [("c", "C"), ("d", "D")]
adapter = BranchTestProviderAdapter(server1, server2, formats)
- suite = adapter.adapt(input_test)
- tests = list(iter(suite))
- self.assertEqual(2, len(tests))
- self.assertEqual(tests[0].branch_format, formats[0][0])
- self.assertEqual(tests[0].bzrdir_format, formats[0][1])
- self.assertEqual(tests[0].transport_server, server1)
- self.assertEqual(tests[0].transport_readonly_server, server2)
- self.assertEqual(tests[1].branch_format, formats[1][0])
- self.assertEqual(tests[1].bzrdir_format, formats[1][1])
- self.assertEqual(tests[1].transport_server, server1)
- self.assertEqual(tests[1].transport_readonly_server, server2)
+ self.assertEqual(2, len(adapter.scenarios))
+ self.assertEqual([
+ ('str',
+ {'branch_format': 'c',
+ 'bzrdir_format': 'C',
+ 'transport_readonly_server': 'b',
+ 'transport_server': 'a'}),
+ ('str',
+ {'branch_format': 'd',
+ 'bzrdir_format': 'D',
+ 'transport_readonly_server': 'b',
+ 'transport_server': 'a'})],
+ adapter.scenarios)
class TestBzrDirProviderAdapter(TestCase):
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-06-28 04:57:44 +0000
+++ b/bzrlib/transport/__init__.py 2007-06-28 05:19:04 +0000
@@ -34,7 +34,6 @@
lazy_import(globals(), """
import errno
from collections import deque
-from copy import deepcopy
from stat import S_ISDIR
import unittest
import urllib
More information about the bazaar-commits
mailing list