Rev 2556: Split out the common test scenario support from the repository implementation specific code. in sftp://rookery/~/public_html/baz2.0/adapter-cleanup
Robert Collins
robertc at robertcollins.net
Thu Jun 28 02:16:47 BST 2007
At sftp://rookery/~/public_html/baz2.0/adapter-cleanup
------------------------------------------------------------
revno: 2556
revision-id: robertc at robertcollins.net-20070628011643-ns42kcef2ymfxu28
parent: robertc at robertcollins.net-20070627222709-tqtod0gjk3xj5p6w
committer: Robert Collins <robertc at robertcollins.net>
branch nick: adapter-cleanup
timestamp: Thu 2007-06-28 11:16:43 +1000
message:
Split out the common test scenario support from the repository implementation specific code.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS 2007-06-27 07:41:38 +0000
+++ b/NEWS 2007-06-28 01:16:43 +0000
@@ -46,6 +46,12 @@
* The lsprof filename note is emitted via trace.note(), not standard
output. (Aaron Bentley)
+ LIBRARY API BREAKS:
+
+ * ``bzrlib.repository.RepositoryTestProviderAdapter`` has been moved
+ to ``bzrlib.tests.repository_implementations``. This is an API break
+ in the testing infrastructure only.
+
INTERNALS:
* New SMTPConnection class to unify email handling. (Adeodato Simó)
@@ -61,6 +67,9 @@
modification of the generated scenarios before adaption and easier
testing. (Robert Collins)
+ * New testing support class ``TestScenarioApplier`` which multiplies
+ out a single teste by a list of supplied scenarios. (RobertCollins)
+
BUGFIXES:
* Work around python-2.4.1 inhability to correctly parse the
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-06-19 16:11:26 +0000
+++ b/bzrlib/tests/__init__.py 2007-06-28 01:16:43 +0000
@@ -2445,3 +2445,34 @@
if getattr(self, 'feature_name', None):
return self.feature_name()
return self.__class__.__name__
+
+
+class TestScenarioApplier(object):
+ """A tool to apply scenarios to tests."""
+
+ def adapt(self, test):
+ """Return a TestSuite containing a copy of test for each scenario."""
+ result = unittest.TestSuite()
+ for scenario in self.scenarios:
+ result.addTest(self.adapt_test_to_scenario(test, scenario))
+ return result
+
+ def adapt_test_to_scenario(self, test, scenario):
+ """Copy test and apply scenario to it.
+
+ :param test: A test to adapt.
+ :param scenario: A tuple describing the scenarion.
+ The first element of the tuple is the new test id.
+ The second element is a dict containing attributes to set on the
+ test.
+ :return: The adapted test.
+ """
+ from copy import deepcopy
+ new_test = deepcopy(test)
+ for name, value in scenario[1].items():
+ setattr(new_test, name, value)
+ def make_new_test_id():
+ new_id = "%s(%s)" % (new_test.id(), scenario[0])
+ return lambda: new_id
+ new_test.id = make_new_test_id()
+ return new_test
=== modified file 'bzrlib/tests/repository_implementations/__init__.py'
--- a/bzrlib/tests/repository_implementations/__init__.py 2007-06-27 22:27:09 +0000
+++ b/bzrlib/tests/repository_implementations/__init__.py 2007-06-28 01:16:43 +0000
@@ -24,8 +24,6 @@
rather than in tests/branch_implementations/*.py.
"""
-import unittest
-
from bzrlib import (
repository,
)
@@ -35,6 +33,7 @@
from bzrlib.tests import (
adapt_modules,
default_transport,
+ TestScenarioApplier,
TestLoader,
TestSuite,
)
@@ -42,7 +41,7 @@
from bzrlib.transport.memory import MemoryServer
-class RepositoryTestProviderAdapter(object):
+class RepositoryTestProviderAdapter(TestScenarioApplier):
"""A tool to generate a suite testing multiple repository formats at once.
This is done by copying the test once for each transport and injecting
@@ -53,39 +52,13 @@
def __init__(self, transport_server, transport_readonly_server, formats,
vfs_transport_factory=None):
+ TestScenarioApplier.__init__(self)
self._transport_server = transport_server
self._transport_readonly_server = transport_readonly_server
self._vfs_transport_factory = vfs_transport_factory
self._formats = formats
self.scenarios = self.formats_to_scenarios(formats)
- def adapt(self, test):
- """Return a TestSuite containing a copy of test for each scenario."""
- result = unittest.TestSuite()
- for scenario in self.scenarios:
- result.addTest(self.adapt_test_to_scenario(test, scenario))
- return result
-
- def adapt_test_to_scenario(self, test, scenario):
- """Copy test and apply scenario to it.
-
- :param test: A test to adapt.
- :param scenario: A tuple describing the scenarion.
- The first element of the tuple is the new test id.
- The second element is a dict containing attributes to set on the
- test.
- :return: The adapted test.
- """
- from copy import deepcopy
- new_test = deepcopy(test)
- for name, value in scenario[1].items():
- setattr(new_test, name, value)
- def make_new_test_id():
- new_id = "%s(%s)" % (new_test.id(), scenario[0])
- return lambda: new_id
- new_test.id = make_new_test_id()
- return new_test
-
def formats_to_scenarios(self, formats):
"""Transform the input formats to a list of scenarios.
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2007-06-27 22:27:09 +0000
+++ b/bzrlib/tests/test_selftest.py 2007-06-28 01:16:43 +0000
@@ -263,21 +263,6 @@
'vfs_transport_factory': 'vfs'})],
adapter.scenarios)
- def test_adapt_applies_scenarios(self):
- from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
- input_test = TestRepositoryProviderAdapter(
- "test_adapt_test_to_scenario")
- adapter = RepositoryTestProviderAdapter(None, None, [])
- adapter.scenarios = [("1", "dict"), ("2", "settings")]
- calls = []
- def capture_call(test, scenario):
- calls.append((test, scenario))
- return test
- adapter.adapt_test_to_scenario = capture_call
- adapter.adapt(input_test)
- self.assertEqual([(input_test, ("1", "dict")),
- (input_test, ("2", "settings"))], calls)
-
def test_formats_to_scenarios(self):
"""The adapter can generate all the scenarios needed."""
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
@@ -314,12 +299,28 @@
'vfs_transport_factory': 'vfs'})],
vfs_adapter.formats_to_scenarios(formats))
+
+class TestTestScenarioApplier(TestCase):
+ """Tests for the test adaption facilities."""
+
+ def test_adapt_applies_scenarios(self):
+ from bzrlib.tests.repository_implementations import TestScenarioApplier
+ input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
+ adapter = TestScenarioApplier()
+ adapter.scenarios = [("1", "dict"), ("2", "settings")]
+ calls = []
+ def capture_call(test, scenario):
+ calls.append((test, scenario))
+ return test
+ adapter.adapt_test_to_scenario = capture_call
+ adapter.adapt(input_test)
+ self.assertEqual([(input_test, ("1", "dict")),
+ (input_test, ("2", "settings"))], calls)
+
def test_adapt_test_to_scenario(self):
- from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
- input_test = TestRepositoryProviderAdapter(
- "test_adapt_test_to_scenario")
- adapter = RepositoryTestProviderAdapter(None, None, [],
- vfs_transport_factory="vfs")
+ from bzrlib.tests.repository_implementations import TestScenarioApplier
+ input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
+ adapter = TestScenarioApplier()
# setup two adapted tests
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
("new id",
@@ -340,12 +341,12 @@
self.assertEqual("readonly-server",
adapted_test1.transport_readonly_server)
self.assertEqual(
- "bzrlib.tests.test_selftest.TestRepositoryProviderAdapter."
+ "bzrlib.tests.test_selftest.TestTestScenarioApplier."
"test_adapt_test_to_scenario(new id)",
adapted_test1.id())
self.assertEqual(None, adapted_test2.bzrdir_format)
self.assertEqual(
- "bzrlib.tests.test_selftest.TestRepositoryProviderAdapter."
+ "bzrlib.tests.test_selftest.TestTestScenarioApplier."
"test_adapt_test_to_scenario(new id 2)",
adapted_test2.id())
More information about the bazaar-commits
mailing list