/brz/remove-bazaar

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