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., 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.
32
from bzrlib.branch import (
36
from bzrlib.bzrdir import (
40
from bzrlib.errors import (
43
UninitializableFormat,
45
from bzrlib.tests import (
46
TestCaseWithTransport,
49
from bzrlib.transport import get_transport
52
def make_scenarios(test_list):
53
"""Transform the input test list to a list of scenarios.
55
:param formats: A list of tuples:
56
(interbranch_class, branch_format_from, branch_format_to).
59
for interbranch_class, branch_format_from, branch_format_to in test_list:
60
id = '%s,%s,%s' % (interbranch_class.__name__,
61
branch_format_from.__class__.__name__,
62
branch_format_to.__class__.__name__)
65
"branch_format_from": branch_format_from,
66
"interbranch_class": interbranch_class,
67
"branch_format_to": branch_format_to,
69
result.append(scenario)
73
def default_test_list():
74
"""Generate the default list of interbranch permutations to test."""
76
# test the default InterBranch between format 6 and the current
78
for optimiser_class in InterBranch._optimisers:
79
format_from_test, format_to_test = \
80
optimiser_class._get_branch_formats_to_test()
81
if format_to_test is not None:
82
result.append((optimiser_class,
83
format_from_test, format_to_test))
84
# if there are specific combinations we want to use, we can add them
89
class TestCaseWithInterBranch(TestCaseWithTransport):
91
def make_from_branch(self, relpath):
92
repo = self.make_repository(relpath)
93
return self.branch_format_from.initialize(repo.bzrdir)
95
def make_from_branch_and_memory_tree(self, relpath):
96
"""Create a branch on the default transport and a MemoryTree for it."""
97
b = self.make_from_branch(relpath)
98
return memorytree.MemoryTree.create_on_branch(b)
100
def make_from_branch_and_tree(self, relpath):
101
"""Create a branch on the default transport and a working tree for it."""
102
b = self.make_from_branch(relpath)
103
return b.bzrdir.create_workingtree()
105
def make_from_branch_builder(self, relpath):
106
default_format = BzrDirFormat.get_default_format()
107
format = BzrDirMetaFormat1()
108
format.set_branch_format(self.branch_format_from)
109
format.repository_format = default_format.repository_format
110
format.workingtree_format = default_format.workingtree_format
111
return branchbuilder.BranchBuilder(self.get_transport(relpath),
114
def make_to_branch(self, relpath):
115
repo = self.make_repository(relpath)
116
return self.branch_format_to.initialize(repo.bzrdir)
118
def make_to_branch_and_memory_tree(self, relpath):
119
"""Create a branch on the default transport and a MemoryTree for it."""
120
b = self.make_to_branch(relpath)
121
return memorytree.MemoryTree.create_on_branch(b)
123
def make_to_branch_and_tree(self, relpath):
124
"""Create a branch on the default transport and a working tree for it."""
125
b = self.make_to_branch(relpath)
126
return b.bzrdir.create_workingtree()
128
def sprout_to(self, origdir, to_url):
129
"""Sprout a bzrdir, using to_format for the new branch."""
130
newbranch = self.make_to_branch(to_url)
131
origbranch = origdir.open_branch()
132
newbranch.repository.fetch(origbranch.repository)
133
origbranch.copy_content_into(newbranch)
134
newbranch.bzrdir.create_workingtree()
135
return newbranch.bzrdir
137
def sprout_from(self, origdir, to_url):
138
"""Sprout a bzrdir, using from_format for the new bzrdir."""
139
newbranch = self.make_from_branch(to_url)
140
origbranch = origdir.open_branch()
141
newbranch.repository.fetch(origbranch.repository)
142
origbranch.copy_content_into(newbranch)
143
newbranch.bzrdir.create_workingtree()
144
return newbranch.bzrdir
147
def load_tests(standard_tests, module, loader):
148
submod_tests = loader.loadTestsFromModuleNames([
149
'bzrlib.tests.per_interbranch.test_pull',
150
'bzrlib.tests.per_interbranch.test_push',
151
'bzrlib.tests.per_interbranch.test_update_revisions',
153
scenarios = make_scenarios(default_test_list())
154
return multiply_tests(submod_tests, scenarios, standard_tests)