1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""InterBranch implementation tests for bzr.
21
These test the conformance of all the interbranch variations to the
22
expected API including generally applicable corner cases.
23
Specific tests for individual formats are in the tests for the formats
24
itself rather than in tests/per_interbranch/*.py.
31
from bzrlib.branch import (
35
from bzrlib.tests import (
36
TestCaseWithTransport,
41
def make_scenarios(test_list):
42
"""Transform the input test list to a list of scenarios.
44
:param formats: A list of tuples:
45
(interbranch_class, branch_format_from, branch_format_to).
48
for interbranch_class, branch_format_from, branch_format_to in test_list:
49
id = '%s,%s,%s' % (interbranch_class.__name__,
50
branch_format_from.__class__.__name__,
51
branch_format_to.__class__.__name__)
54
"branch_format_from": branch_format_from,
55
"interbranch_class": interbranch_class,
56
"branch_format_to": branch_format_to,
58
result.append(scenario)
62
def default_test_list():
63
"""Generate the default list of interbranch permutations to test."""
65
# test the default InterBranch between format 6 and the current
67
for optimiser_class in InterBranch._optimisers:
68
for format_from_test, format_to_test in \
69
optimiser_class._get_branch_formats_to_test():
70
result.append((optimiser_class, format_from_test, format_to_test))
71
# if there are specific combinations we want to use, we can add them
76
class TestCaseWithInterBranch(TestCaseWithTransport):
78
def make_from_branch(self, relpath):
79
return self.make_branch(relpath, format=self.branch_format_from._matchingbzrdir)
81
def make_from_branch_and_memory_tree(self, relpath):
82
"""Create a branch on the default transport and a MemoryTree for it."""
84
self.branch_format_from._matchingbzrdir.get_branch_format(),
85
self.branch_format_from)
86
return self.make_branch_and_memory_tree(
87
relpath, format=self.branch_format_from._matchingbzrdir)
89
def make_from_branch_and_tree(self, relpath):
90
"""Create a branch on the default transport and a working tree for it."""
92
self.branch_format_from._matchingbzrdir.get_branch_format(),
93
self.branch_format_from)
94
return self.make_branch_and_tree(relpath,
95
format=self.branch_format_from._matchingbzrdir)
97
def make_from_branch_builder(self, relpath):
99
self.branch_format_from._matchingbzrdir.get_branch_format(),
100
self.branch_format_from)
101
return branchbuilder.BranchBuilder(self.get_transport(relpath),
102
format=self.branch_format_from._matchingbzrdir)
104
def make_to_branch(self, relpath):
106
self.branch_format_to._matchingbzrdir.get_branch_format(),
107
self.branch_format_to)
108
return self.make_branch(relpath, format=self.branch_format_to._matchingbzrdir)
110
def make_to_branch_and_memory_tree(self, relpath):
111
"""Create a branch on the default transport and a MemoryTree for it."""
113
self.branch_format_to._matchingbzrdir.get_branch_format(),
114
self.branch_format_to)
115
return self.make_branch_and_memory_tree(
116
relpath, format=self.branch_format_to._matchingbzrdir)
118
def make_to_branch_and_tree(self, relpath):
119
"""Create a branch on the default transport and a working tree for it."""
121
self.branch_format_to._matchingbzrdir.get_branch_format(),
122
self.branch_format_to)
123
return self.make_branch_and_tree(relpath,
124
format=self.branch_format_to._matchingbzrdir)
126
def _sprout(self, origdir, to_url, format):
127
if format.supports_workingtrees:
128
newbranch = self.make_branch(to_url, format=format)
130
newbranch = self.make_branch(to_url+".branch", format=format)
131
origbranch = origdir.open_branch()
132
newbranch.repository.fetch(origbranch.repository)
133
origbranch.copy_content_into(newbranch)
134
if format.supports_workingtrees:
135
wt = newbranch.bzrdir.create_workingtree()
137
wt = newbranch.create_checkout(to_url, lightweight=True)
140
def sprout_to(self, origdir, to_url):
141
"""Sprout a bzrdir, using to_format for the new branch."""
142
wt = self._sprout(origdir, to_url, self.branch_format_to._matchingbzrdir)
143
self.assertEqual(wt.branch._format, self.branch_format_to)
146
def sprout_from(self, origdir, to_url):
147
"""Sprout a bzrdir, using from_format for the new bzrdir."""
148
wt = self._sprout(origdir, to_url,
149
self.branch_format_from._matchingbzrdir)
150
self.assertEqual(wt.branch._format, self.branch_format_from)
154
class StubWithFormat(object):
155
"""A stub object used to check that convenience methods call Inter's."""
160
class StubMatchingInter(object):
161
"""An inter for tests.
163
This is not a subclass of InterBranch so that missing methods are caught
164
and added rather than actually trying to do something.
169
def __init__(self, source, target):
174
def is_compatible(klass, source, target):
175
return StubWithFormat._format in (source._format, target._format)
177
def copy_content_into(self, *args, **kwargs):
178
self.__class__._uses.append(
179
(self, 'copy_content_into', args, kwargs))
182
def load_tests(standard_tests, module, loader):
183
submod_tests = loader.loadTestsFromModuleNames([
184
'bzrlib.tests.per_interbranch.test_fetch',
185
'bzrlib.tests.per_interbranch.test_get',
186
'bzrlib.tests.per_interbranch.test_copy_content_into',
187
'bzrlib.tests.per_interbranch.test_pull',
188
'bzrlib.tests.per_interbranch.test_push',
190
scenarios = make_scenarios(default_test_list())
191
return multiply_tests(submod_tests, scenarios, standard_tests)