2220.2.17
by Martin Pool
merge up from bzr.dev to get metadir changes |
1 |
# Copyright (C) 2006, 2007 Canonical Ltd
|
1534.4.24
by Robert Collins
update (C) on branch_implementations/__init__.py |
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
2220.2.17
by Martin Pool
merge up from bzr.dev to get metadir changes |
3 |
# and others
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
4 |
#
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
9 |
#
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
14 |
#
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
18 |
|
19 |
||
20 |
"""Branch implementation tests for bzr.
|
|
21 |
||
22 |
These test the conformance of all the branch variations to the expected API.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
23 |
Specific tests for individual formats are in the tests/test_branch file
|
4523.1.1
by Martin Pool
Rename tests.branch_implementations to per_branch |
24 |
rather than in tests/per_branch/*.py.
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
25 |
"""
|
26 |
||
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
27 |
from bzrlib import ( |
28 |
errors, |
|
29 |
tests, |
|
30 |
)
|
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
31 |
from bzrlib.branch import (BranchFormat, |
32 |
_legacy_formats, |
|
33 |
)
|
|
2418.5.11
by John Arbash Meinel
[merge] bzr.dev 2447 |
34 |
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat |
2018.5.167
by Andrew Bennetts
Various changes in response to John's review. |
35 |
from bzrlib.smart.server import ( |
3453.5.1
by Andrew Bennetts
Add {bzrdir,repository,branch}_implementations tests for Remote objects using protocol v2 and pre-1.6 RPCs. |
36 |
ReadonlySmartTCPServer_for_testing, |
37 |
ReadonlySmartTCPServer_for_testing_v2_only, |
|
2018.5.167
by Andrew Bennetts
Various changes in response to John's review. |
38 |
SmartTCPServer_for_testing, |
3453.5.1
by Andrew Bennetts
Add {bzrdir,repository,branch}_implementations tests for Remote objects using protocol v2 and pre-1.6 RPCs. |
39 |
SmartTCPServer_for_testing_v2_only, |
2018.5.167
by Andrew Bennetts
Various changes in response to John's review. |
40 |
)
|
4523.1.2
by Martin Pool
Rename bzrdir_implementations to per_bzrdir |
41 |
from bzrlib.tests.per_bzrdir.test_bzrdir import TestCaseWithBzrDir |
2018.5.167
by Andrew Bennetts
Various changes in response to John's review. |
42 |
from bzrlib.transport.memory import MemoryServer |
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
43 |
|
44 |
||
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
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.
|
|
2553.2.6
by Robert Collins
And overhaul BranchTestProviderAdapter too. |
48 |
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
49 |
:param formats: A list of (branch_format, bzrdir_format).
|
2553.2.6
by Robert Collins
And overhaul BranchTestProviderAdapter too. |
50 |
"""
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
51 |
result = [] |
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, |
|
63 |
})
|
|
64 |
result.append(scenario) |
|
65 |
return result |
|
2553.2.6
by Robert Collins
And overhaul BranchTestProviderAdapter too. |
66 |
|
67 |
||
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
68 |
class TestCaseWithBranch(TestCaseWithBzrDir): |
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
69 |
"""This helper will be parameterised in each branch_implementation test."""
|
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
70 |
|
71 |
def setUp(self): |
|
72 |
super(TestCaseWithBranch, self).setUp() |
|
73 |
self.branch = None |
|
74 |
||
75 |
def get_branch(self): |
|
76 |
if self.branch is None: |
|
77 |
self.branch = self.make_branch('') |
|
78 |
return self.branch |
|
79 |
||
80 |
def make_branch(self, relpath, format=None): |
|
4617.3.1
by Robert Collins
Fix test_stacking tests for 2a as a default format. The change to 2a exposed some actual bugs, both in tests and bzrdir/branch code. |
81 |
if format is not None: |
82 |
return TestCaseWithBzrDir.make_branch(self, relpath, format) |
|
83 |
repo = self.make_repository(relpath) |
|
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
84 |
# fixme RBC 20060210 this isnt necessarily a fixable thing,
|
85 |
# Skipped is the wrong exception to raise.
|
|
86 |
try: |
|
87 |
return self.branch_format.initialize(repo.bzrdir) |
|
88 |
except errors.UninitializableFormat: |
|
89 |
raise tests.TestSkipped('Uninitializable branch format') |
|
90 |
||
3904.3.4
by Andrew Bennetts
First cut of a branch_implementations test. It fails. |
91 |
def make_branch_builder(self, relpath, format=None): |
92 |
if format is None: |
|
93 |
format = self.branch_format._matchingbzrdir |
|
94 |
return super(TestCaseWithBranch, self).make_branch_builder( |
|
95 |
relpath, format=format) |
|
96 |
||
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
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) |
|
100 |
||
101 |
def create_tree_with_merge(self): |
|
102 |
"""Create a branch with a simple ancestry.
|
|
103 |
||
104 |
The graph should look like:
|
|
105 |
digraph H {
|
|
106 |
"rev-1" -> "rev-2" -> "rev-3";
|
|
107 |
"rev-1" -> "rev-1.1.1" -> "rev-3";
|
|
108 |
}
|
|
109 |
||
110 |
Or in ASCII:
|
|
2418.5.14
by John Arbash Meinel
clean up ASCII revision graph art. |
111 |
1
|
112 |
|\
|
|
113 |
2 1.1.1
|
|
114 |
|/
|
|
115 |
3
|
|
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
116 |
"""
|
117 |
tree = self.make_branch_and_memory_tree('tree') |
|
118 |
tree.lock_write() |
|
119 |
try: |
|
120 |
tree.add('') |
|
121 |
tree.commit('first', rev_id='rev-1') |
|
2418.5.3
by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge' |
122 |
tree.commit('second', rev_id='rev-1.1.1') |
2418.5.10
by John Arbash Meinel
fix typo |
123 |
# Uncommit that last commit and switch to the other line
|
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
124 |
tree.branch.set_last_revision_info(1, 'rev-1') |
125 |
tree.set_parent_ids(['rev-1']) |
|
2418.5.3
by John Arbash Meinel
Use a more straightforward implementation of generating 'tree_with_merge' |
126 |
tree.commit('alt-second', rev_id='rev-2') |
2418.5.2
by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py |
127 |
tree.set_parent_ids(['rev-2', 'rev-1.1.1']) |
128 |
tree.commit('third', rev_id='rev-3') |
|
129 |
finally: |
|
130 |
tree.unlock() |
|
131 |
||
132 |
return tree |
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
133 |
|
1534.4.24
by Robert Collins
update (C) on branch_implementations/__init__.py |
134 |
|
4108.2.1
by Michael Hudson
Factor branch scenario generation out of branch test loading. |
135 |
def branch_scenarios(): |
136 |
""" """
|
|
137 |
# Generate a list of branch formats and their associated bzrdir formats to
|
|
138 |
# use.
|
|
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.
|
|
143 |
None, |
|
144 |
# None here will cause a readonly decorator to be created
|
|
145 |
# by the TestCaseWithTransport.get_readonly_transport method.
|
|
146 |
None, |
|
147 |
combinations) |
|
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)], |
|
154 |
MemoryServer, |
|
155 |
name_suffix='-default')) |
|
156 |
# Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
|
|
157 |
# server.
|
|
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)], |
|
162 |
MemoryServer, |
|
163 |
name_suffix='-v2')) |
|
164 |
return scenarios |
|
165 |
||
166 |
||
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
167 |
def load_tests(standard_tests, module, loader): |
4523.1.5
by Vincent Ladeuil
Fixed as asked in review. |
168 |
per_branch_mod_names = [ |
169 |
'bound_sftp', |
|
170 |
'branch', |
|
171 |
'break_lock', |
|
172 |
'check', |
|
173 |
'create_checkout', |
|
174 |
'create_clone', |
|
175 |
'commit', |
|
176 |
'dotted_revno_to_revision_id', |
|
177 |
'get_revision_id_to_revno_map', |
|
178 |
'hooks', |
|
179 |
'http', |
|
180 |
'iter_merge_sorted_revisions', |
|
181 |
'last_revision_info', |
|
182 |
'locking', |
|
183 |
'parent', |
|
184 |
'permissions', |
|
185 |
'pull', |
|
186 |
'push', |
|
187 |
'reconcile', |
|
188 |
'revision_history', |
|
189 |
'revision_id_to_dotted_revno', |
|
190 |
'revision_id_to_revno', |
|
191 |
'sprout', |
|
192 |
'stacking', |
|
193 |
'tags', |
|
194 |
'uncommit', |
|
195 |
'update', |
|
1534.4.23
by Robert Collins
Move branch implementations tests into a package. |
196 |
]
|
4523.1.5
by Vincent Ladeuil
Fixed as asked in review. |
197 |
sub_tests = loader.loadTestsFromModuleNames( |
198 |
['bzrlib.tests.per_branch.test_' + name |
|
199 |
for name in per_branch_mod_names]) |
|
4108.2.1
by Michael Hudson
Factor branch scenario generation out of branch test loading. |
200 |
return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests) |