24
24
rather than in tests/branch_implementations/*.py.
27
from bzrlib.bzrdir import BzrDirTestProviderAdapter, BzrDirFormat
27
from bzrlib.bzrdir import BzrDirFormat
28
28
from bzrlib.tests import (
31
TestCaseWithTransport,
36
from bzrlib.transport.memory import MemoryServer
39
class BzrDirTestProviderAdapter(TestScenarioApplier):
40
"""A tool to generate a suite testing multiple bzrdir formats at once.
42
This is done by copying the test once for each transport and injecting
43
the transport_server, transport_readonly_server, and bzrdir_format
44
classes into each copy. Each copy is also given a new id() to make it
48
def __init__(self, vfs_factory, transport_server, transport_readonly_server,
50
"""Create an object to adapt tests.
52
:param vfs_server: A factory to create a Transport Server which has
53
all the VFS methods working, and is writable.
55
self._vfs_factory = vfs_factory
56
self._transport_server = transport_server
57
self._transport_readonly_server = transport_readonly_server
58
self.scenarios = self.formats_to_scenarios(formats)
60
def formats_to_scenarios(self, formats):
61
"""Transform the input formats to a list of scenarios.
63
:param formats: A list of bzrdir_format objects.
66
for format in formats:
67
scenario = (format.__class__.__name__, {
68
"vfs_transport_factory":self._vfs_factory,
69
"transport_server":self._transport_server,
70
"transport_readonly_server":self._transport_readonly_server,
71
"bzrdir_format":format,
73
result.append(scenario)
77
class TestCaseWithBzrDir(TestCaseWithTransport):
80
super(TestCaseWithBzrDir, self).setUp()
84
if self.bzrdir is None:
85
self.bzrdir = self.make_bzrdir(None)
88
def make_bzrdir(self, relpath, format=None):
89
return super(TestCaseWithBzrDir, self).make_bzrdir(
90
relpath, format=self.bzrdir_format)
41
98
formats = BzrDirFormat.known_formats()
42
99
adapter = BzrDirTestProviderAdapter(
43
100
default_transport,
44
102
# None here will cause a readonly decorator to be created
45
103
# by the TestCaseWithTransport.get_readonly_transport method.
48
106
loader = TestLoader()
49
107
adapt_modules(test_bzrdir_implementations, adapter, loader, result)
109
# This will always add the tests for smart server transport, regardless of
110
# the --transport option the user specified to 'bzr selftest'.
111
from bzrlib.smart.server import SmartTCPServer_for_testing, ReadonlySmartTCPServer_for_testing
112
from bzrlib.remote import RemoteBzrDirFormat
114
# test the remote server behaviour using a MemoryTransport
115
smart_server_suite = TestSuite()
116
adapt_to_smart_server = BzrDirTestProviderAdapter(
118
SmartTCPServer_for_testing,
119
ReadonlySmartTCPServer_for_testing,
120
[(RemoteBzrDirFormat())])
121
adapt_modules(test_bzrdir_implementations,
122
adapt_to_smart_server,
125
result.addTests(smart_server_suite)