1
# Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
28
from bzrlib.branch import (
32
from bzrlib.errors import (
34
UninitializableFormat,
36
from bzrlib.tests import multiply_tests
37
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
38
from bzrlib.transport import get_transport
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
format_from_test, format_to_test = \
69
optimiser_class._get_branch_formats_to_test()
70
if format_to_test is not None:
71
result.append((optimiser_class,
72
format_from_test, format_to_test))
73
# if there are specific combinations we want to use, we can add them
78
class TestCaseWithInterBranch(TestCaseWithBzrDir):
81
super(TestCaseWithInterBranch, self).setUp()
83
def make_branch(self, relpath, format=None):
84
repo = self.make_repository(relpath, format=format)
85
return repo.bzrdir.create_branch()
87
def make_bzrdir(self, relpath, format=None):
89
url = self.get_url(relpath)
90
segments = url.split('/')
91
if segments and segments[-1] not in ('', '.'):
92
parent = '/'.join(segments[:-1])
93
t = get_transport(parent)
99
format = self.branch_format_from._matchingbzrdir
100
return format.initialize(url)
101
except UninitializableFormat:
102
raise TestSkipped("Format %s is not initializable." % format)
104
def make_repository(self, relpath, format=None):
105
made_control = self.make_bzrdir(relpath, format=format)
106
return made_control.create_repository()
108
def make_to_bzrdir(self, relpath):
109
return self.make_bzrdir(relpath,
110
self.branch_format_to._matchingbzrdir)
112
def make_to_branch(self, relpath):
113
made_control = self.make_to_bzrdir(relpath)
114
return self.branch_format_to.initialize(made_control)
117
def load_tests(standard_tests, module, loader):
118
submod_tests = loader.loadTestsFromModuleNames([
119
'bzrlib.tests.per_interbranch.test_update_revisions',
121
scenarios = make_scenarios(default_test_list())
122
return multiply_tests(submod_tests, scenarios, standard_tests)