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 (
41
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
42
from bzrlib.transport import get_transport
45
class InterBranchTestProviderAdapter(TestScenarioApplier):
46
"""A tool to generate a suite testing multiple inter branch formats.
48
This is done by copying the test once for each interbranch provider and
49
injecting the transport_server, transport_readonly_server, branch_format and
50
branch_to_format classes into each copy.
51
Each copy is also given a new id() to make it easy to identify.
54
def __init__(self, transport_server, transport_readonly_server, formats):
55
TestScenarioApplier.__init__(self)
56
self._transport_server = transport_server
57
self._transport_readonly_server = transport_readonly_server
58
self.scenarios = self.formats_to_scenarios(formats)
60
def formats_to_scenarios(self, formats):
61
"""Transform the input formats to a list of scenarios.
63
:param formats: A list of tuples:
64
(interbranch_class, branch_format, branch_format_to).
67
for interbranch_class, branch_format, branch_format_to in formats:
68
id = '%s,%s,%s' % (interbranch_class.__name__,
69
branch_format.__class__.__name__,
70
branch_format_to.__class__.__name__)
72
{"transport_server":self._transport_server,
73
"transport_readonly_server":self._transport_readonly_server,
74
"branch_format":branch_format,
75
"interbranch_class":interbranch_class,
76
"branch_format_to":branch_format_to,
78
result.append(scenario)
82
def default_test_list():
83
"""Generate the default list of interbranch permutations to test."""
85
# test the default InterBranch between format 6 and the current
87
for optimiser_class in InterBranch._optimisers:
88
format_to_test = optimiser_class._get_branch_format_to_test()
89
if format_to_test is not None:
90
result.append((optimiser_class,
91
format_to_test, format_to_test))
92
# if there are specific combinations we want to use, we can add them
97
class TestCaseWithInterBranch(TestCaseWithBzrDir):
100
super(TestCaseWithInterBranch, self).setUp()
102
def make_branch(self, relpath, format=None):
103
repo = self.make_repository(relpath, format=format)
104
return repo.bzrdir.create_branch()
106
def make_bzrdir(self, relpath, format=None):
108
url = self.get_url(relpath)
109
segments = url.split('/')
110
if segments and segments[-1] not in ('', '.'):
111
parent = '/'.join(segments[:-1])
112
t = get_transport(parent)
114
t.mkdir(segments[-1])
118
format = self.branch_format._matchingbzrdir
119
return format.initialize(url)
120
except UninitializableFormat:
121
raise TestSkipped("Format %s is not initializable." % format)
123
def make_repository(self, relpath, format=None):
124
made_control = self.make_bzrdir(relpath, format=format)
125
return made_control.create_repository()
127
def make_to_bzrdir(self, relpath):
128
return self.make_bzrdir(relpath,
129
self.branch_format_to._matchingbzrdir)
131
def make_to_branch(self, relpath):
132
made_control = self.make_to_bzrdir(relpath)
133
return self.branch_format_to.initialize(made_control)
136
def load_tests(basic_tests, module, loader):
137
result = loader.suiteClass()
138
# add the tests for this module
139
result.addTests(basic_tests)
141
test_interbranch_implementations = [
142
'bzrlib.tests.per_interbranch.test_update_revisions',
144
adapter = InterBranchTestProviderAdapter(
146
# None here will cause a readonly decorator to be created
147
# by the TestCaseWithTransport.get_readonly_transport method.
149
InterBranchTestProviderAdapter.default_test_list()
151
# add the tests for the sub modules
152
adapt_modules(test_interbranch_implementations, adapter, loader, result)