5273.1.5
by Vincent Ladeuil
Merge bzr.dev into cleanup |
1 |
# Copyright (C) 2009, 2010 Canonical Ltd
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
2 |
# -*- coding: utf-8 -*-
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
17 |
|
18 |
||
19 |
"""InterBranch implementation tests for bzr.
|
|
20 |
||
21 |
These test the conformance of all the interbranch variations to the
|
|
22 |
expected API including generally applicable corner cases.
|
|
4000.5.8
by Jelmer Vernooij
Fix whitespace. |
23 |
Specific tests for individual formats are in the tests for the formats
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
24 |
itself rather than in tests/per_interbranch/*.py.
|
25 |
"""
|
|
26 |
||
27 |
||
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
28 |
from bzrlib import ( |
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
29 |
branchbuilder, |
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
30 |
memorytree, |
31 |
)
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
32 |
from bzrlib.branch import ( |
33 |
GenericInterBranch, |
|
34 |
InterBranch, |
|
35 |
)
|
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
36 |
from bzrlib.bzrdir import ( |
37 |
BzrDirFormat, |
|
38 |
BzrDirMetaFormat1, |
|
39 |
)
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
40 |
from bzrlib.errors import ( |
41 |
FileExists, |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
42 |
NotBranchError, |
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
43 |
UninitializableFormat, |
44 |
)
|
|
4211.1.6
by Jelmer Vernooij
Review from Ian. |
45 |
from bzrlib.tests import ( |
46 |
TestCaseWithTransport, |
|
47 |
multiply_tests, |
|
48 |
)
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
49 |
|
50 |
||
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
51 |
def make_scenarios(test_list): |
52 |
"""Transform the input test list to a list of scenarios.
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
53 |
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
54 |
:param formats: A list of tuples:
|
55 |
(interbranch_class, branch_format_from, branch_format_to).
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
56 |
"""
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
57 |
result = [] |
58 |
for interbranch_class, branch_format_from, branch_format_to in test_list: |
|
59 |
id = '%s,%s,%s' % (interbranch_class.__name__, |
|
60 |
branch_format_from.__class__.__name__, |
|
61 |
branch_format_to.__class__.__name__) |
|
62 |
scenario = (id, |
|
63 |
{
|
|
64 |
"branch_format_from": branch_format_from, |
|
65 |
"interbranch_class": interbranch_class, |
|
66 |
"branch_format_to": branch_format_to, |
|
67 |
})
|
|
68 |
result.append(scenario) |
|
69 |
return result |
|
70 |
||
71 |
||
72 |
def default_test_list(): |
|
73 |
"""Generate the default list of interbranch permutations to test."""
|
|
74 |
result = [] |
|
75 |
# test the default InterBranch between format 6 and the current
|
|
76 |
# default format.
|
|
77 |
for optimiser_class in InterBranch._optimisers: |
|
5297.2.1
by Robert Collins
``bzrlib.branch.InterBranch._get_branch_formats_to_test`` now returns |
78 |
for format_from_test, format_to_test in \ |
79 |
optimiser_class._get_branch_formats_to_test(): |
|
80 |
result.append((optimiser_class, format_from_test, format_to_test)) |
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
81 |
# if there are specific combinations we want to use, we can add them
|
82 |
# here.
|
|
83 |
return result |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
84 |
|
85 |
||
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
86 |
class TestCaseWithInterBranch(TestCaseWithTransport): |
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
87 |
|
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
88 |
def make_from_branch(self, relpath): |
89 |
repo = self.make_repository(relpath) |
|
90 |
return self.branch_format_from.initialize(repo.bzrdir) |
|
91 |
||
92 |
def make_from_branch_and_memory_tree(self, relpath): |
|
93 |
"""Create a branch on the default transport and a MemoryTree for it."""
|
|
94 |
b = self.make_from_branch(relpath) |
|
95 |
return memorytree.MemoryTree.create_on_branch(b) |
|
96 |
||
97 |
def make_from_branch_and_tree(self, relpath): |
|
98 |
"""Create a branch on the default transport and a working tree for it."""
|
|
99 |
b = self.make_from_branch(relpath) |
|
100 |
return b.bzrdir.create_workingtree() |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
101 |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
102 |
def make_from_branch_builder(self, relpath): |
103 |
default_format = BzrDirFormat.get_default_format() |
|
104 |
format = BzrDirMetaFormat1() |
|
105 |
format.set_branch_format(self.branch_format_from) |
|
106 |
format.repository_format = default_format.repository_format |
|
107 |
format.workingtree_format = default_format.workingtree_format |
|
108 |
return branchbuilder.BranchBuilder(self.get_transport(relpath), |
|
109 |
format=format) |
|
110 |
||
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
111 |
def make_to_branch(self, relpath): |
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
112 |
repo = self.make_repository(relpath) |
113 |
return self.branch_format_to.initialize(repo.bzrdir) |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
114 |
|
115 |
def make_to_branch_and_memory_tree(self, relpath): |
|
116 |
"""Create a branch on the default transport and a MemoryTree for it."""
|
|
117 |
b = self.make_to_branch(relpath) |
|
118 |
return memorytree.MemoryTree.create_on_branch(b) |
|
119 |
||
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
120 |
def make_to_branch_and_tree(self, relpath): |
121 |
"""Create a branch on the default transport and a working tree for it."""
|
|
122 |
b = self.make_to_branch(relpath) |
|
123 |
return b.bzrdir.create_workingtree() |
|
124 |
||
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
125 |
def sprout_to(self, origdir, to_url): |
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
126 |
"""Sprout a bzrdir, using to_format for the new branch."""
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
127 |
newbranch = self.make_to_branch(to_url) |
4000.5.20
by Jelmer Vernooij
Fix InterBranch.pull tests. |
128 |
origbranch = origdir.open_branch() |
129 |
newbranch.repository.fetch(origbranch.repository) |
|
130 |
origbranch.copy_content_into(newbranch) |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
131 |
newbranch.bzrdir.create_workingtree() |
132 |
return newbranch.bzrdir |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
133 |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
134 |
def sprout_from(self, origdir, to_url): |
135 |
"""Sprout a bzrdir, using from_format for the new bzrdir."""
|
|
136 |
newbranch = self.make_from_branch(to_url) |
|
137 |
origbranch = origdir.open_branch() |
|
138 |
newbranch.repository.fetch(origbranch.repository) |
|
139 |
origbranch.copy_content_into(newbranch) |
|
140 |
newbranch.bzrdir.create_workingtree() |
|
141 |
return newbranch.bzrdir |
|
142 |
||
143 |
||
5284.4.2
by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to |
144 |
class StubWithFormat(object): |
145 |
"""A stub object used to check that convenience methods call Inter's."""
|
|
146 |
||
147 |
_format = object() |
|
148 |
||
149 |
||
150 |
class StubMatchingInter(object): |
|
151 |
"""An inter for tests.
|
|
152 |
||
153 |
This is not a subclass of InterBranch so that missing methods are caught
|
|
154 |
and added rather than actually trying to do something.
|
|
155 |
"""
|
|
156 |
||
157 |
_uses = [] |
|
158 |
||
159 |
def __init__(self, source, target): |
|
160 |
self.source = source |
|
161 |
self.target = target |
|
162 |
||
163 |
@classmethod
|
|
164 |
def is_compatible(klass, source, target): |
|
165 |
return StubWithFormat._format in (source._format, target._format) |
|
166 |
||
167 |
def copy_content_into(self, *args, **kwargs): |
|
168 |
self.__class__._uses.append( |
|
169 |
(self, 'copy_content_into', args, kwargs)) |
|
170 |
||
171 |
||
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
172 |
def load_tests(standard_tests, module, loader): |
173 |
submod_tests = loader.loadTestsFromModuleNames([ |
|
5284.4.1
by Robert Collins
* Fetching was slightly confused about the best code to use and was |
174 |
'bzrlib.tests.per_interbranch.test_get', |
5284.4.2
by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to |
175 |
'bzrlib.tests.per_interbranch.test_copy_content_into', |
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
176 |
'bzrlib.tests.per_interbranch.test_pull', |
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
177 |
'bzrlib.tests.per_interbranch.test_push', |
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
178 |
'bzrlib.tests.per_interbranch.test_update_revisions', |
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
179 |
])
|
180 |
scenarios = make_scenarios(default_test_list()) |
|
181 |
return multiply_tests(submod_tests, scenarios, standard_tests) |