1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""InterTree implementation tests for bzr.
20
These test the conformance of all the InterTree variations to the expected API.
21
Specific tests for individual variations are in other places such as:
22
- tests/test_workingtree.py
25
import bzrlib.errors as errors
26
from bzrlib.transport import get_transport
27
from bzrlib.tests import (
33
from bzrlib.tests.tree_implementations import (
35
revision_tree_from_workingtree,
38
from bzrlib.tree import InterTree
39
from bzrlib.workingtree import (
41
WorkingTreeTestProviderAdapter,
45
def return_provided_trees(source, target):
46
"""Return the source and target tree unaltered."""
50
class TestCaseWithTwoTrees(TestCaseWithTree):
52
def make_to_branch_and_tree(self, relpath):
53
"""Make a to_workingtree_format branch and tree."""
54
made_control = self.make_bzrdir(relpath,
55
format=self.workingtree_format_to._matchingbzrdir)
56
made_control.create_repository()
57
made_control.create_branch()
58
return self.workingtree_format_to.initialize(made_control)
61
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
62
"""Generate test suites for each InterTree implementation in bzrlib."""
64
def adapt(self, test):
68
workingtree_format_to,
69
mutable_trees_to_test_trees) in self._formats:
70
new_test = self._clone_test(
72
workingtree_format._matchingbzrdir,
74
intertree_class.__name__)
75
new_test.intertree_class = intertree_class
76
new_test.workingtree_format_to = workingtree_format_to
77
# mutable_trees_to_test_trees takes two trees and converts them to
78
# whatever relationship the optimiser under test requires.
79
new_test.mutable_trees_to_test_trees = mutable_trees_to_test_trees
80
# workingtree_to_test_tree is set to disable changing individual
81
# trees: instead the mutable_trees_to_test_trees helper is used.
82
new_test.workingtree_to_test_tree = return_parameter
83
result.addTest(new_test)
90
# load the tests of the infrastructure for these tests
91
result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.intertree_implementations']))
93
default_tree_format = WorkingTreeFormat3()
94
test_intertree_implementations = [
95
'bzrlib.tests.intertree_implementations.test_compare',
97
test_intertree_permutations = [
98
# test InterTree with two default-format working trees.
99
(InterTree, default_tree_format, default_tree_format,
100
return_provided_trees)]
101
for optimiser in InterTree._optimisers:
102
test_intertree_permutations.append(
104
optimiser._matching_from_tree_format,
105
optimiser._matching_to_tree_format,
106
optimiser._test_mutable_trees_to_test_trees))
107
adapter = InterTreeTestProviderAdapter(
109
# None here will cause a readonly decorator to be created
110
# by the TestCaseWithTransport.get_readonly_transport method.
112
test_intertree_permutations)
113
adapt_modules(test_intertree_implementations, adapter, loader, result)