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 (
40
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
41
from bzrlib.transport import get_transport
44
class InterBranchTestProviderAdapter(TestScenarioApplier):
45
"""A tool to generate a suite testing multiple inter branch formats.
47
This is done by copying the test once for each interbranch provider and
48
injecting the branch_format_from and branch_to_format classes into each
49
copy. Each copy is also given a new id() to make it easy to identify.
52
def __init__(self, formats):
53
TestScenarioApplier.__init__(self)
54
self.scenarios = self.formats_to_scenarios(formats)
56
def formats_to_scenarios(self, formats):
57
"""Transform the input formats to a list of scenarios.
59
:param formats: A list of tuples:
60
(interbranch_class, branch_format_from, branch_format_to).
63
for interbranch_class, branch_format_from, branch_format_to in formats:
64
id = '%s,%s,%s' % (interbranch_class.__name__,
65
branch_format_from.__class__.__name__,
66
branch_format_to.__class__.__name__)
69
"branch_format_from":branch_format_from,
70
"interbranch_class":interbranch_class,
71
"branch_format_to":branch_format_to,
73
result.append(scenario)
77
def default_test_list():
78
"""Generate the default list of interbranch permutations to test."""
80
# test the default InterBranch between format 6 and the current
82
for optimiser_class in InterBranch._optimisers:
83
format_from_test, format_to_test = \
84
optimiser_class._get_branch_formats_to_test()
85
if format_to_test is not None:
86
result.append((optimiser_class,
87
format_from_test, format_to_test))
88
# if there are specific combinations we want to use, we can add them
93
class TestCaseWithInterBranch(TestCaseWithBzrDir):
96
super(TestCaseWithInterBranch, self).setUp()
98
def make_branch(self, relpath, format=None):
99
repo = self.make_repository(relpath, format=format)
100
return repo.bzrdir.create_branch()
102
def make_bzrdir(self, relpath, format=None):
104
url = self.get_url(relpath)
105
segments = url.split('/')
106
if segments and segments[-1] not in ('', '.'):
107
parent = '/'.join(segments[:-1])
108
t = get_transport(parent)
110
t.mkdir(segments[-1])
114
format = self.branch_format_from._matchingbzrdir
115
return format.initialize(url)
116
except UninitializableFormat:
117
raise TestSkipped("Format %s is not initializable." % format)
119
def make_repository(self, relpath, format=None):
120
made_control = self.make_bzrdir(relpath, format=format)
121
return made_control.create_repository()
123
def make_to_bzrdir(self, relpath):
124
return self.make_bzrdir(relpath,
125
self.branch_format_to._matchingbzrdir)
127
def make_to_branch(self, relpath):
128
made_control = self.make_to_bzrdir(relpath)
129
return self.branch_format_to.initialize(made_control)
132
def load_tests(basic_tests, module, loader):
133
result = loader.suiteClass()
134
# add the tests for this module
135
result.addTests(basic_tests)
137
test_interbranch_implementations = [
138
'bzrlib.tests.per_interbranch.test_update_revisions',
140
adapter = InterBranchTestProviderAdapter(
141
InterBranchTestProviderAdapter.default_test_list()
143
# add the tests for the sub modules
144
adapt_modules(test_interbranch_implementations, adapter, loader, result)