/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
3735.8.1 by Vincent Ladeuil
TestCompare tests passing.
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
3735.8.1 by Vincent Ladeuil
TestCompare tests passing.
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.
3735.8.1 by Vincent Ladeuil
TestCompare tests passing.
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.
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
132
        (InterTree.__name__, InterTree, 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:
3735.29.1 by Vincent Ladeuil
Create an InterCHKRevisionTree optimiser.
135
        if optimiser is revisiontree.InterCHKRevisionTree:
3735.28.6 by Vincent Ladeuil
Update XXX comment.
136
            # XXX: we shouldn't use an Intertree object to detect inventories
137
            # -- vila 20090311
3735.29.1 by Vincent Ladeuil
Create an InterCHKRevisionTree optimiser.
138
            continue
139
        elif optimiser is bzrlib.workingtree_4.InterDirStateTree:
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
140
            # Its a little ugly to be conditional here, but less so than having
141
            # the optimiser listed twice.
142
            # Add once, compiled version
143
            test_intertree_permutations.append(
144
                (optimiser.__name__ + "(C)",
145
                 optimiser,
146
                 optimiser._matching_from_tree_format,
147
                 optimiser._matching_to_tree_format,
148
                 optimiser.make_source_parent_tree_compiled_dirstate))
149
            # python version
150
            test_intertree_permutations.append(
151
                (optimiser.__name__ + "(PY)",
152
                 optimiser,
153
                 optimiser._matching_from_tree_format,
154
                 optimiser._matching_to_tree_format,
155
                 optimiser.make_source_parent_tree_python_dirstate))
156
        else:
157
            test_intertree_permutations.append(
158
                (optimiser.__name__,
159
                 optimiser,
160
                 optimiser._matching_from_tree_format,
161
                 optimiser._matching_to_tree_format,
162
                 optimiser._test_mutable_trees_to_test_trees))
3696.4.15 by Robert Collins
Merge bzr.dev.
163
    # PreviewTree does not have an InterTree optimiser class.
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
164
    test_intertree_permutations.append(
3696.4.15 by Robert Collins
Merge bzr.dev.
165
        (InterTree.__name__ + "(PreviewTree)",
166
         InterTree,
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
167
         default_tree_format,
168
         default_tree_format,
169
         mutable_trees_to_preview_trees))
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
170
    # CHKInventory does not have an InterTree optimiser class (yet).
171
    chk_tree_format = WorkingTreeFormat4()
172
    chk_tree_format._get_matchingbzrdir = \
3735.17.6 by John Arbash Meinel
Continue tracking down all the references to development3/4
173
        lambda:bzrlib.bzrdir.format_registry.make_bzrdir('development5')
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
174
    test_intertree_permutations.append(
175
        (InterTree.__name__ + "(CHKInventory)",
176
         InterTree,
177
         chk_tree_format,
178
         chk_tree_format,
179
         mutable_trees_to_revision_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)