1
# Copyright (C) 2006, 2007 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
"""Branch implementation tests for bzr.
22
These test the conformance of all the branch variations to the expected API.
23
Specific tests for individual formats are in the tests/test_branch file
24
rather than in tests/per_branch/*.py.
31
from bzrlib.branch import (BranchFormat,
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.per_bzrdir.test_bzrdir import TestCaseWithBzrDir
42
from bzrlib.transport.memory import MemoryServer
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.
49
:param formats: A list of (branch_format, bzrdir_format).
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)
68
class TestCaseWithBranch(TestCaseWithBzrDir):
69
"""This helper will be parameterised in each branch_implementation test."""
72
super(TestCaseWithBranch, self).setUp()
76
if self.branch is None:
77
self.branch = self.make_branch('')
80
def make_branch(self, relpath, format=None):
81
if format is not None:
82
return TestCaseWithBzrDir.make_branch(self, relpath, format)
83
repo = self.make_repository(relpath)
84
# fixme RBC 20060210 this isnt necessarily a fixable thing,
85
# Skipped is the wrong exception to raise.
87
return self.branch_format.initialize(repo.bzrdir)
88
except errors.UninitializableFormat:
89
raise tests.TestSkipped('Uninitializable branch format')
91
def make_branch_builder(self, relpath, format=None):
93
format = self.branch_format._matchingbzrdir
94
return super(TestCaseWithBranch, self).make_branch_builder(
95
relpath, format=format)
97
def make_repository(self, relpath, shared=False, format=None):
98
made_control = self.make_bzrdir(relpath, format=format)
99
return made_control.create_repository(shared=shared)
101
def create_tree_with_merge(self):
102
"""Create a branch with a simple ancestry.
104
The graph should look like:
106
"rev-1" -> "rev-2" -> "rev-3";
107
"rev-1" -> "rev-1.1.1" -> "rev-3";
117
tree = self.make_branch_and_memory_tree('tree')
121
tree.commit('first', rev_id='rev-1')
122
tree.commit('second', rev_id='rev-1.1.1')
123
# Uncommit that last commit and switch to the other line
124
tree.branch.set_last_revision_info(1, 'rev-1')
125
tree.set_parent_ids(['rev-1'])
126
tree.commit('alt-second', rev_id='rev-2')
127
tree.set_parent_ids(['rev-2', 'rev-1.1.1'])
128
tree.commit('third', rev_id='rev-3')
135
def branch_scenarios():
137
# Generate a list of branch formats and their associated bzrdir formats to
139
combinations = [(format, format._matchingbzrdir) for format in
140
BranchFormat._formats.values() + _legacy_formats]
141
scenarios = make_scenarios(
142
# None here will cause the default vfs transport server to be used.
144
# None here will cause a readonly decorator to be created
145
# by the TestCaseWithTransport.get_readonly_transport method.
148
# Add RemoteBranch tests, which need a special server.
149
remote_branch_format = RemoteBranchFormat()
150
scenarios.extend(make_scenarios(
151
SmartTCPServer_for_testing,
152
ReadonlySmartTCPServer_for_testing,
153
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
155
name_suffix='-default'))
156
# Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
158
scenarios.extend(make_scenarios(
159
SmartTCPServer_for_testing_v2_only,
160
ReadonlySmartTCPServer_for_testing_v2_only,
161
[(remote_branch_format, remote_branch_format._matchingbzrdir)],
167
def load_tests(standard_tests, module, loader):
168
per_branch_mod_names = [
176
'dotted_revno_to_revision_id',
177
'get_revision_id_to_revno_map',
180
'iter_merge_sorted_revisions',
181
'last_revision_info',
189
'revision_id_to_dotted_revno',
190
'revision_id_to_revno',
197
sub_tests = loader.loadTestsFromModuleNames(
198
['bzrlib.tests.per_branch.test_' + name
199
for name in per_branch_mod_names])
200
return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)