34
34
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
35
from bzrlib.smart.server import (
36
ReadonlySmartTCPServer_for_testing,
37
ReadonlySmartTCPServer_for_testing_v2_only,
38
SmartTCPServer_for_testing,
39
SmartTCPServer_for_testing_v2_only,
41
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
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.
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
35
from bzrlib.tests import test_server
36
from bzrlib.tests.per_bzrdir.test_bzrdir import TestCaseWithBzrDir
37
from bzrlib.transport import memory
40
def make_scenarios(transport_server, transport_readonly_server,
41
formats, vfs_transport_factory=None, name_suffix=''):
42
"""Transform the input formats to a list of scenarios.
44
: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)
47
for branch_format, bzrdir_format in formats:
48
# some branches don't have separate format objects.
49
# so we have a conditional here to handle them.
50
scenario_name = getattr(branch_format, '__name__',
51
branch_format.__class__.__name__)
52
scenario_name += name_suffix
53
scenario = (scenario_name, {
54
"transport_server":transport_server,
55
"transport_readonly_server":transport_readonly_server,
56
"bzrdir_format":bzrdir_format,
57
"branch_format":branch_format,
59
result.append(scenario)
83
63
class TestCaseWithBranch(TestCaseWithBzrDir):
84
"""This helper will be adapted for each branch_implementation test."""
64
"""This helper will be parameterised in each per_branch test."""
87
67
super(TestCaseWithBranch, self).setUp()
142
def load_tests(basic_tests, module, loader):
143
result = loader.suiteClass()
144
# add the tests for this module
145
result.addTests(basic_tests)
147
test_branch_implementations = [
148
'bzrlib.tests.branch_implementations.test_bound_sftp',
149
'bzrlib.tests.branch_implementations.test_branch',
150
'bzrlib.tests.branch_implementations.test_break_lock',
151
'bzrlib.tests.branch_implementations.test_check',
152
'bzrlib.tests.branch_implementations.test_create_checkout',
153
'bzrlib.tests.branch_implementations.test_commit',
154
'bzrlib.tests.branch_implementations.test_get_revision_id_to_revno_map',
155
'bzrlib.tests.branch_implementations.test_hooks',
156
'bzrlib.tests.branch_implementations.test_http',
157
'bzrlib.tests.branch_implementations.test_last_revision_info',
158
'bzrlib.tests.branch_implementations.test_locking',
159
'bzrlib.tests.branch_implementations.test_parent',
160
'bzrlib.tests.branch_implementations.test_permissions',
161
'bzrlib.tests.branch_implementations.test_pull',
162
'bzrlib.tests.branch_implementations.test_push',
163
'bzrlib.tests.branch_implementations.test_reconcile',
164
'bzrlib.tests.branch_implementations.test_revision_history',
165
'bzrlib.tests.branch_implementations.test_revision_id_to_revno',
166
'bzrlib.tests.branch_implementations.test_sprout',
167
'bzrlib.tests.branch_implementations.test_stacking',
168
'bzrlib.tests.branch_implementations.test_tags',
169
'bzrlib.tests.branch_implementations.test_uncommit',
170
'bzrlib.tests.branch_implementations.test_update',
130
def branch_scenarios():
172
132
# Generate a list of branch formats and their associated bzrdir formats to
174
combinations = [(format, format._matchingbzrdir) for format in
134
combinations = [(format, format._matchingbzrdir) for format in
175
135
BranchFormat._formats.values() + _legacy_formats]
176
adapter = BranchTestProviderAdapter(
136
scenarios = make_scenarios(
177
137
# None here will cause the default vfs transport server to be used.
179
139
# None here will cause a readonly decorator to be created
180
140
# by the TestCaseWithTransport.get_readonly_transport method.
183
# add the tests for the sub modules
184
tests.adapt_modules(test_branch_implementations, adapter, loader, result)
186
143
# Add RemoteBranch tests, which need a special server.
187
adapt_to_smart_server = BranchTestProviderAdapter(
188
SmartTCPServer_for_testing,
189
ReadonlySmartTCPServer_for_testing,
190
[(RemoteBranchFormat(), RemoteBzrDirFormat())],
192
name_suffix='-default')
193
tests.adapt_modules(test_branch_implementations,
194
adapt_to_smart_server,
144
remote_branch_format = RemoteBranchFormat()
145
scenarios.extend(make_scenarios(
146
test_server.SmartTCPServer_for_testing,
147
test_server.ReadonlySmartTCPServer_for_testing,
148
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
150
name_suffix='-default'))
198
151
# Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
200
adapt_to_smart_server = BranchTestProviderAdapter(
201
SmartTCPServer_for_testing_v2_only,
202
ReadonlySmartTCPServer_for_testing_v2_only,
203
[(RemoteBranchFormat(), RemoteBzrDirFormat())],
206
tests.adapt_modules(test_branch_implementations,
207
adapt_to_smart_server,
153
scenarios.extend(make_scenarios(
154
test_server.SmartTCPServer_for_testing_v2_only,
155
test_server.ReadonlySmartTCPServer_for_testing_v2_only,
156
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
162
def load_tests(standard_tests, module, loader):
163
per_branch_mod_names = [
171
'dotted_revno_to_revision_id',
172
'get_revision_id_to_revno_map',
175
'iter_merge_sorted_revisions',
176
'last_revision_info',
184
'revision_id_to_dotted_revno',
185
'revision_id_to_revno',
192
sub_tests = loader.loadTestsFromModuleNames(
193
['bzrlib.tests.per_branch.test_' + name
194
for name in per_branch_mod_names])
195
return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)