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 |
)
|
|
4211.1.6
by Jelmer Vernooij
Review from Ian. |
40 |
from bzrlib.tests import ( |
41 |
TestCaseWithTransport, |
|
42 |
multiply_tests, |
|
43 |
)
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
44 |
|
45 |
||
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
46 |
def make_scenarios(test_list): |
47 |
"""Transform the input test list to a list of scenarios.
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
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 tuples:
|
50 |
(interbranch_class, branch_format_from, branch_format_to).
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
51 |
"""
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
52 |
result = [] |
53 |
for interbranch_class, branch_format_from, branch_format_to in test_list: |
|
54 |
id = '%s,%s,%s' % (interbranch_class.__name__, |
|
55 |
branch_format_from.__class__.__name__, |
|
56 |
branch_format_to.__class__.__name__) |
|
57 |
scenario = (id, |
|
58 |
{
|
|
59 |
"branch_format_from": branch_format_from, |
|
60 |
"interbranch_class": interbranch_class, |
|
61 |
"branch_format_to": branch_format_to, |
|
62 |
})
|
|
63 |
result.append(scenario) |
|
64 |
return result |
|
65 |
||
66 |
||
67 |
def default_test_list(): |
|
68 |
"""Generate the default list of interbranch permutations to test."""
|
|
69 |
result = [] |
|
70 |
# test the default InterBranch between format 6 and the current
|
|
71 |
# default format.
|
|
72 |
for optimiser_class in InterBranch._optimisers: |
|
5297.2.1
by Robert Collins
``bzrlib.branch.InterBranch._get_branch_formats_to_test`` now returns |
73 |
for format_from_test, format_to_test in \ |
74 |
optimiser_class._get_branch_formats_to_test(): |
|
75 |
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. |
76 |
# if there are specific combinations we want to use, we can add them
|
77 |
# here.
|
|
78 |
return result |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
79 |
|
80 |
||
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
81 |
class TestCaseWithInterBranch(TestCaseWithTransport): |
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
82 |
|
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
83 |
def make_from_branch(self, relpath): |
5705.2.3
by Jelmer Vernooij
Run interbranch tests with correct bzrdir/repository formats. |
84 |
repo = self.make_repository(relpath, format=self.branch_format_from._matchingbzrdir) |
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
85 |
return self.branch_format_from.initialize(repo.bzrdir) |
86 |
||
87 |
def make_from_branch_and_memory_tree(self, relpath): |
|
88 |
"""Create a branch on the default transport and a MemoryTree for it."""
|
|
89 |
b = self.make_from_branch(relpath) |
|
90 |
return memorytree.MemoryTree.create_on_branch(b) |
|
91 |
||
92 |
def make_from_branch_and_tree(self, relpath): |
|
93 |
"""Create a branch on the default transport and a working tree for it."""
|
|
94 |
b = self.make_from_branch(relpath) |
|
95 |
return b.bzrdir.create_workingtree() |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
96 |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
97 |
def make_from_branch_builder(self, relpath): |
98 |
default_format = BzrDirFormat.get_default_format() |
|
99 |
format = BzrDirMetaFormat1() |
|
100 |
format.set_branch_format(self.branch_format_from) |
|
101 |
format.repository_format = default_format.repository_format |
|
102 |
format.workingtree_format = default_format.workingtree_format |
|
103 |
return branchbuilder.BranchBuilder(self.get_transport(relpath), |
|
104 |
format=format) |
|
105 |
||
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
106 |
def make_to_branch(self, relpath): |
5705.2.3
by Jelmer Vernooij
Run interbranch tests with correct bzrdir/repository formats. |
107 |
repo = self.make_repository(relpath, format=self.branch_format_to._matchingbzrdir) |
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
108 |
return self.branch_format_to.initialize(repo.bzrdir) |
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
109 |
|
110 |
def make_to_branch_and_memory_tree(self, relpath): |
|
111 |
"""Create a branch on the default transport and a MemoryTree for it."""
|
|
112 |
b = self.make_to_branch(relpath) |
|
113 |
return memorytree.MemoryTree.create_on_branch(b) |
|
114 |
||
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
115 |
def make_to_branch_and_tree(self, relpath): |
116 |
"""Create a branch on the default transport and a working tree for it."""
|
|
117 |
b = self.make_to_branch(relpath) |
|
118 |
return b.bzrdir.create_workingtree() |
|
119 |
||
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
120 |
def sprout_to(self, origdir, to_url): |
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
121 |
"""Sprout a bzrdir, using to_format for the new branch."""
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
122 |
newbranch = self.make_to_branch(to_url) |
4000.5.20
by Jelmer Vernooij
Fix InterBranch.pull tests. |
123 |
origbranch = origdir.open_branch() |
124 |
newbranch.repository.fetch(origbranch.repository) |
|
125 |
origbranch.copy_content_into(newbranch) |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
126 |
newbranch.bzrdir.create_workingtree() |
127 |
return newbranch.bzrdir |
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
128 |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
129 |
def sprout_from(self, origdir, to_url): |
130 |
"""Sprout a bzrdir, using from_format for the new bzrdir."""
|
|
131 |
newbranch = self.make_from_branch(to_url) |
|
132 |
origbranch = origdir.open_branch() |
|
133 |
newbranch.repository.fetch(origbranch.repository) |
|
134 |
origbranch.copy_content_into(newbranch) |
|
135 |
newbranch.bzrdir.create_workingtree() |
|
136 |
return newbranch.bzrdir |
|
137 |
||
138 |
||
5284.4.2
by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to |
139 |
class StubWithFormat(object): |
140 |
"""A stub object used to check that convenience methods call Inter's."""
|
|
141 |
||
142 |
_format = object() |
|
143 |
||
144 |
||
145 |
class StubMatchingInter(object): |
|
146 |
"""An inter for tests.
|
|
147 |
||
148 |
This is not a subclass of InterBranch so that missing methods are caught
|
|
149 |
and added rather than actually trying to do something.
|
|
150 |
"""
|
|
151 |
||
152 |
_uses = [] |
|
153 |
||
154 |
def __init__(self, source, target): |
|
155 |
self.source = source |
|
156 |
self.target = target |
|
157 |
||
158 |
@classmethod
|
|
159 |
def is_compatible(klass, source, target): |
|
160 |
return StubWithFormat._format in (source._format, target._format) |
|
161 |
||
162 |
def copy_content_into(self, *args, **kwargs): |
|
163 |
self.__class__._uses.append( |
|
164 |
(self, 'copy_content_into', args, kwargs)) |
|
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): |
168 |
submod_tests = loader.loadTestsFromModuleNames([ |
|
5741.1.3
by Jelmer Vernooij
Move fetch tests. |
169 |
'bzrlib.tests.per_interbranch.test_fetch', |
5284.4.1
by Robert Collins
* Fetching was slightly confused about the best code to use and was |
170 |
'bzrlib.tests.per_interbranch.test_get', |
5284.4.2
by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to |
171 |
'bzrlib.tests.per_interbranch.test_copy_content_into', |
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
172 |
'bzrlib.tests.per_interbranch.test_pull', |
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
173 |
'bzrlib.tests.per_interbranch.test_push', |
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
174 |
'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. |
175 |
])
|
176 |
scenarios = make_scenarios(default_test_list()) |
|
177 |
return multiply_tests(submod_tests, scenarios, standard_tests) |