~bzr-pqm/bzr/bzr.dev

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