~bzr-pqm/bzr/bzr.dev

3735.2.137 by Martin Pool
merge trunk
1
# Copyright (C) 2006, 2009 Canonical Ltd
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
2
#
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.
7
#
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.
12
#
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
16
17
18
"""InterTree implementation tests for bzr.
19
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
23
"""
24
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
25
import bzrlib
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
26
from bzrlib import (
27
    errors,
28
    revisiontree,
29
    tests,
30
    )
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
31
from bzrlib.transport import get_transport
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
32
from bzrlib.transform import TransformPreview
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
33
from bzrlib.tests import (
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
34
    default_transport,
35
    multiply_tests,
36
    )
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
37
from bzrlib.tests.tree_implementations import (
38
    return_parameter,
39
    revision_tree_from_workingtree,
40
    TestCaseWithTree,
41
    )
42
from bzrlib.tree import InterTree
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
43
from bzrlib.workingtree import (
44
    WorkingTreeFormat3,
45
    )
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
46
from bzrlib.workingtree_4 import WorkingTreeFormat4
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
47
48
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
49
def return_provided_trees(test_case, source, target):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
50
    """Return the source and target tree unaltered."""
51
    return source, target
52
53
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
54
class TestCaseWithTwoTrees(TestCaseWithTree):
55
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
56
    def not_applicable_if_cannot_represent_unversioned(self, tree):
57
        if isinstance(tree, revisiontree.RevisionTree):
58
            # The locked test trees conversion could not preserve the
59
            # unversioned file status. This is normal (e.g. InterDirstateTree
60
            # falls back to InterTree if the basis is not a
61
            # DirstateRevisionTree, and revision trees cannot have unversioned
62
            # files.
63
            raise tests.TestNotApplicable('cannot represent unversioned files')
64
65
    def not_applicable_if_missing_in(self, relpath, tree):
66
        if not tree.path2id(relpath):
67
            # The locked test trees conversion could not preserve the missing
68
            # file status. This is normal (e.g. InterDirstateTree falls back
69
            # to InterTree if the basis is not a DirstateRevisionTree, and
3735.2.99 by John Arbash Meinel
Merge bzr.dev 4034. Whitespace cleanup
70
            # revision trees cannot have missing files.
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
71
            raise tests.TestNotApplicable('cannot represent missing files')
72
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
73
    def make_to_branch_and_tree(self, relpath):
74
        """Make a to_workingtree_format branch and tree."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
75
        made_control = self.make_bzrdir(relpath,
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
76
            format=self.workingtree_format_to._matchingbzrdir)
77
        made_control.create_repository()
78
        made_control.create_branch()
79
        return self.workingtree_format_to.initialize(made_control)
80
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
81
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
82
def make_scenarios(transport_server, transport_readonly_server, formats):
83
    """Transform the input formats to a list of scenarios.
84
85
    :param formats: A list of tuples:.
86
        (intertree_class,
87
         workingtree_format,
88
         workingtree_format_to,
89
         mutable_trees_to_test_trees)
90
    """
91
    result = []
92
    for (label, intertree_class,
93
        workingtree_format,
94
        workingtree_format_to,
95
        mutable_trees_to_test_trees) in formats:
96
        scenario = (label, {
97
            "transport_server": transport_server,
98
            "transport_readonly_server": transport_readonly_server,
99
            "bzrdir_format":workingtree_format._matchingbzrdir,
100
            "workingtree_format":workingtree_format,
101
            "intertree_class":intertree_class,
102
            "workingtree_format_to":workingtree_format_to,
103
            # mutable_trees_to_test_trees takes two trees and converts them to,
104
            # whatever relationship the optimiser under test requires.,
105
            "mutable_trees_to_test_trees":mutable_trees_to_test_trees,
106
            # workingtree_to_test_tree is set to disable changing individual,
107
            # trees: instead the mutable_trees_to_test_trees helper is used.,
108
            "_workingtree_to_test_tree": return_parameter,
109
            })
110
        result.append(scenario)
111
    return result
112
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
113
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
114
def mutable_trees_to_preview_trees(test_case, source, target):
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
115
    preview = TransformPreview(target)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
116
    test_case.addCleanup(preview.finalize)
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
117
    return source, preview.get_preview_tree()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
118
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
119
def mutable_trees_to_revision_trees(test_case, source, target):
120
    """Convert both trees to repository based revision trees."""
121
    return (revision_tree_from_workingtree(test_case, source),
122
        revision_tree_from_workingtree(test_case, target))
123
124
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
125
def load_tests(standard_tests, module, loader):
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
126
    default_tree_format = WorkingTreeFormat3()
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
127
    submod_tests = loader.loadTestsFromModuleNames([
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
128
        'bzrlib.tests.intertree_implementations.test_compare',
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
129
        ])
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
130
    test_intertree_permutations = [
131
        # test InterTree with two default-format working trees.
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
132
        (InterTree.__name__, InterTree,
133
         default_tree_format, default_tree_format,
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
134
         return_provided_trees)]
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
135
    for optimiser in InterTree._optimisers:
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
136
        if optimiser is revisiontree.InterCHKRevisionTree:
137
            # XXX: we shouldn't use an Intertree object to detect inventories
138
            # -- vila 20090311
139
            chk_tree_format = WorkingTreeFormat4()
140
            chk_tree_format._get_matchingbzrdir = \
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
141
                lambda:bzrlib.bzrdir.format_registry.make_bzrdir(
142
                    'development6-rich-root')
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
143
            test_intertree_permutations.append(
144
                (InterTree.__name__ + "(CHKInventory)",
145
                 InterTree,
146
                 chk_tree_format,
147
                 chk_tree_format,
148
                 mutable_trees_to_revision_trees))
149
        elif optimiser is bzrlib.workingtree_4.InterDirStateTree:
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
150
            # Its a little ugly to be conditional here, but less so than having
151
            # the optimiser listed twice.
152
            # Add once, compiled version
153
            test_intertree_permutations.append(
154
                (optimiser.__name__ + "(C)",
155
                 optimiser,
156
                 optimiser._matching_from_tree_format,
157
                 optimiser._matching_to_tree_format,
158
                 optimiser.make_source_parent_tree_compiled_dirstate))
159
            # python version
160
            test_intertree_permutations.append(
161
                (optimiser.__name__ + "(PY)",
162
                 optimiser,
163
                 optimiser._matching_from_tree_format,
164
                 optimiser._matching_to_tree_format,
165
                 optimiser.make_source_parent_tree_python_dirstate))
166
        else:
167
            test_intertree_permutations.append(
168
                (optimiser.__name__,
169
                 optimiser,
170
                 optimiser._matching_from_tree_format,
171
                 optimiser._matching_to_tree_format,
172
                 optimiser._test_mutable_trees_to_test_trees))
3696.4.15 by Robert Collins
Merge bzr.dev.
173
    # PreviewTree does not have an InterTree optimiser class.
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
174
    test_intertree_permutations.append(
3696.4.15 by Robert Collins
Merge bzr.dev.
175
        (InterTree.__name__ + "(PreviewTree)",
176
         InterTree,
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
177
         default_tree_format,
178
         default_tree_format,
179
         mutable_trees_to_preview_trees))
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
180
    scenarios = make_scenarios(
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
181
        default_transport,
182
        # None here will cause a readonly decorator to be created
183
        # by the TestCaseWithTransport.get_readonly_transport method.
184
        None,
185
        test_intertree_permutations)
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
186
    # add the tests for the sub modules to the standard tests.
187
    return multiply_tests(submod_tests, scenarios, standard_tests)