42
42
from bzrlib.transport.memory import MemoryServer
45
class BranchTestProviderAdapter(tests.TestScenarioApplier):
46
"""A tool to generate a suite testing multiple branch formats at once.
45
def make_scenarios(transport_server, transport_readonly_server,
46
formats, vfs_transport_factory=None, name_suffix=''):
47
"""Transform the input formats to a list of scenarios.
48
This is done by copying the test once for each transport and injecting
49
the transport_server, transport_readonly_server, and branch_format
50
classes into each copy. Each copy is also given a new id() to make it
49
:param formats: A list of (branch_format, bzrdir_format).
54
def __init__(self, transport_server, transport_readonly_server, formats,
55
vfs_transport_factory=None, name_suffix=''):
56
self._transport_server = transport_server
57
self._transport_readonly_server = transport_readonly_server
58
self._name_suffix = name_suffix
59
self.scenarios = self.formats_to_scenarios(formats)
61
def formats_to_scenarios(self, formats):
62
"""Transform the input formats to a list of scenarios.
64
:param formats: A list of (branch_format, bzrdir_format).
67
for branch_format, bzrdir_format in formats:
68
# some branches don't have separate format objects.
69
# so we have a conditional here to handle them.
70
scenario_name = getattr(branch_format, '__name__',
71
branch_format.__class__.__name__)
72
scenario_name += self._name_suffix
73
scenario = (scenario_name, {
74
"transport_server":self._transport_server,
75
"transport_readonly_server":self._transport_readonly_server,
76
"bzrdir_format":bzrdir_format,
77
"branch_format":branch_format,
79
result.append(scenario)
52
for branch_format, bzrdir_format in formats:
53
# some branches don't have separate format objects.
54
# so we have a conditional here to handle them.
55
scenario_name = getattr(branch_format, '__name__',
56
branch_format.__class__.__name__)
57
scenario_name += name_suffix
58
scenario = (scenario_name, {
59
"transport_server":transport_server,
60
"transport_readonly_server":transport_readonly_server,
61
"bzrdir_format":bzrdir_format,
62
"branch_format":branch_format,
64
result.append(scenario)
83
68
class TestCaseWithBranch(TestCaseWithBzrDir):
84
"""This helper will be adapted for each branch_implementation test."""
69
"""This helper will be parameterised in each branch_implementation test."""
87
72
super(TestCaseWithBranch, self).setUp()
148
def load_tests(basic_tests, module, loader):
149
result = loader.suiteClass()
150
# add the tests for this module
151
result.addTests(basic_tests)
133
def branch_scenarios():
135
# Generate a list of branch formats and their associated bzrdir formats to
137
combinations = [(format, format._matchingbzrdir) for format in
138
BranchFormat._formats.values() + _legacy_formats]
139
scenarios = make_scenarios(
140
# None here will cause the default vfs transport server to be used.
142
# None here will cause a readonly decorator to be created
143
# by the TestCaseWithTransport.get_readonly_transport method.
146
# Add RemoteBranch tests, which need a special server.
147
remote_branch_format = RemoteBranchFormat()
148
scenarios.extend(make_scenarios(
149
SmartTCPServer_for_testing,
150
ReadonlySmartTCPServer_for_testing,
151
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
153
name_suffix='-default'))
154
# Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
156
scenarios.extend(make_scenarios(
157
SmartTCPServer_for_testing_v2_only,
158
ReadonlySmartTCPServer_for_testing_v2_only,
159
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
165
def load_tests(standard_tests, module, loader):
153
166
test_branch_implementations = [
154
167
'bzrlib.tests.branch_implementations.test_bound_sftp',
155
168
'bzrlib.tests.branch_implementations.test_branch',
179
192
'bzrlib.tests.branch_implementations.test_uncommit',
180
193
'bzrlib.tests.branch_implementations.test_update',
182
# Generate a list of branch formats and their associated bzrdir formats to
184
combinations = [(format, format._matchingbzrdir) for format in
185
BranchFormat._formats.values() + _legacy_formats]
186
adapter = BranchTestProviderAdapter(
187
# None here will cause the default vfs transport server to be used.
189
# None here will cause a readonly decorator to be created
190
# by the TestCaseWithTransport.get_readonly_transport method.
193
# add the tests for the sub modules
194
tests.adapt_modules(test_branch_implementations, adapter, loader, result)
196
# Add RemoteBranch tests, which need a special server.
197
remote_branch_format = RemoteBranchFormat()
198
adapt_to_smart_server = BranchTestProviderAdapter(
199
SmartTCPServer_for_testing,
200
ReadonlySmartTCPServer_for_testing,
201
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
203
name_suffix='-default')
204
tests.adapt_modules(test_branch_implementations,
205
adapt_to_smart_server,
209
# Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
211
adapt_to_smart_server = BranchTestProviderAdapter(
212
SmartTCPServer_for_testing_v2_only,
213
ReadonlySmartTCPServer_for_testing_v2_only,
214
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
217
tests.adapt_modules(test_branch_implementations,
218
adapt_to_smart_server,
195
sub_tests = loader.loadTestsFromModuleNames(test_branch_implementations)
196
return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)