bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
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.""" |
|
|
6127.1.9
by Jelmer Vernooij
Add lightweight option to _get_checkout_format(). |
94 |
return self.make_branch_and_tree(relpath, |
95 |
format=self.branch_format_from._matchingbzrdir) |
|
|
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 |
return branchbuilder.BranchBuilder(self.get_transport(relpath), |
|
|
6162.3.2
by Jelmer Vernooij
Add WorkingTreeFormat.get_controldir_for_branch(). |
99 |
format=self.branch_format_from._matchingbzrdir) |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
100 |
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
101 |
def make_to_branch(self, relpath): |
|
5705.2.3
by Jelmer Vernooij
Run interbranch tests with correct bzrdir/repository formats. |
102 |
repo = self.make_repository(relpath, format=self.branch_format_to._matchingbzrdir) |
|
4216.7.1
by Jelmer Vernooij
Simplify interbranch test base class. |
103 |
return self.branch_format_to.initialize(repo.bzrdir) |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
104 |
|
105 |
def make_to_branch_and_memory_tree(self, relpath): |
|
106 |
"""Create a branch on the default transport and a MemoryTree for it.""" |
|
107 |
b = self.make_to_branch(relpath) |
|
108 |
return memorytree.MemoryTree.create_on_branch(b) |
|
109 |
||
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
110 |
def make_to_branch_and_tree(self, relpath): |
111 |
"""Create a branch on the default transport and a working tree for it.""" |
|
|
6127.1.9
by Jelmer Vernooij
Add lightweight option to _get_checkout_format(). |
112 |
return self.make_branch_and_tree(relpath, |
113 |
format=self.branch_format_to._matchingbzrdir) |
|
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
114 |
|
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
115 |
def sprout_to(self, origdir, to_url): |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
116 |
"""Sprout a bzrdir, using to_format for the new branch.""" |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
117 |
newbranch = self.make_to_branch(to_url) |
|
4000.5.20
by Jelmer Vernooij
Fix InterBranch.pull tests. |
118 |
origbranch = origdir.open_branch() |
119 |
newbranch.repository.fetch(origbranch.repository) |
|
120 |
origbranch.copy_content_into(newbranch) |
|
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
121 |
newbranch.bzrdir.create_workingtree() |
122 |
return newbranch.bzrdir |
|
|
4000.5.3
by Jelmer Vernooij
Add tests for InterBranch. |
123 |
|
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
124 |
def sprout_from(self, origdir, to_url): |
125 |
"""Sprout a bzrdir, using from_format for the new bzrdir.""" |
|
126 |
newbranch = self.make_from_branch(to_url) |
|
127 |
origbranch = origdir.open_branch() |
|
128 |
newbranch.repository.fetch(origbranch.repository) |
|
129 |
origbranch.copy_content_into(newbranch) |
|
130 |
newbranch.bzrdir.create_workingtree() |
|
131 |
return newbranch.bzrdir |
|
132 |
||
133 |
||
|
5284.4.2
by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to |
134 |
class StubWithFormat(object): |
135 |
"""A stub object used to check that convenience methods call Inter's.""" |
|
136 |
||
137 |
_format = object() |
|
138 |
||
139 |
||
140 |
class StubMatchingInter(object): |
|
141 |
"""An inter for tests. |
|
142 |
||
143 |
This is not a subclass of InterBranch so that missing methods are caught
|
|
144 |
and added rather than actually trying to do something.
|
|
145 |
"""
|
|
146 |
||
147 |
_uses = [] |
|
148 |
||
149 |
def __init__(self, source, target): |
|
150 |
self.source = source |
|
151 |
self.target = target |
|
152 |
||
153 |
@classmethod
|
|
154 |
def is_compatible(klass, source, target): |
|
155 |
return StubWithFormat._format in (source._format, target._format) |
|
156 |
||
157 |
def copy_content_into(self, *args, **kwargs): |
|
158 |
self.__class__._uses.append( |
|
159 |
(self, 'copy_content_into', args, kwargs)) |
|
160 |
||
161 |
||
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
162 |
def load_tests(standard_tests, module, loader): |
163 |
submod_tests = loader.loadTestsFromModuleNames([ |
|
|
5741.1.3
by Jelmer Vernooij
Move fetch tests. |
164 |
'bzrlib.tests.per_interbranch.test_fetch', |
|
5284.4.1
by Robert Collins
* Fetching was slightly confused about the best code to use and was |
165 |
'bzrlib.tests.per_interbranch.test_get', |
|
5284.4.2
by Robert Collins
* ``Branch.copy_content_into`` is now a convenience method dispatching to |
166 |
'bzrlib.tests.per_interbranch.test_copy_content_into', |
|
4000.5.11
by Jelmer Vernooij
Improve tests for InterBranch.pull. |
167 |
'bzrlib.tests.per_interbranch.test_pull', |
|
4211.1.4
by Jelmer Vernooij
add InterBranch.push() tests. |
168 |
'bzrlib.tests.per_interbranch.test_push', |
|
4084.5.1
by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters. |
169 |
])
|
170 |
scenarios = make_scenarios(default_test_list()) |
|
171 |
return multiply_tests(submod_tests, scenarios, standard_tests) |