/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 (
34
                          adapt_modules,
35
                          default_transport,
36
                          )
37
from bzrlib.tests.tree_implementations import (
38
    return_parameter,
39
    revision_tree_from_workingtree,
40
    TestCaseWithTree,
41
    )
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
42
from bzrlib.tests.workingtree_implementations import (
43
    WorkingTreeTestProviderAdapter,
44
    )
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
45
from bzrlib.tree import InterTree
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
46
from bzrlib.workingtree import (
47
    WorkingTreeFormat3,
48
    )
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
49
from bzrlib.workingtree_4 import WorkingTreeFormat4
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
50
51
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
52
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.
53
    """Return the source and target tree unaltered."""
54
    return source, target
55
56
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
57
class TestCaseWithTwoTrees(TestCaseWithTree):
58
3735.8.1 by Vincent Ladeuil
TestCompare tests passing.
59
    def not_applicable_if_cannot_represent_unversioned(self, tree):
60
        if isinstance(tree, revisiontree.RevisionTree):
61
            # The locked test trees conversion could not preserve the
62
            # unversioned file status. This is normal (e.g. InterDirstateTree
63
            # falls back to InterTree if the basis is not a
64
            # DirstateRevisionTree, and revision trees cannot have unversioned
65
            # files.
66
            raise tests.TestNotApplicable('cannot represent unversioned files')
67
68
    def not_applicable_if_missing_in(self, relpath, tree):
69
        if not tree.path2id(relpath):
70
            # The locked test trees conversion could not preserve the missing
71
            # file status. This is normal (e.g. InterDirstateTree falls back
72
            # to InterTree if the basis is not a DirstateRevisionTree, and
3735.2.99 by John Arbash Meinel
Merge bzr.dev 4034. Whitespace cleanup
73
            # revision trees cannot have missing files.
3735.8.1 by Vincent Ladeuil
TestCompare tests passing.
74
            raise tests.TestNotApplicable('cannot represent missing files')
75
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
76
    def make_to_branch_and_tree(self, relpath):
77
        """Make a to_workingtree_format branch and tree."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
78
        made_control = self.make_bzrdir(relpath,
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
79
            format=self.workingtree_format_to._matchingbzrdir)
80
        made_control.create_repository()
81
        made_control.create_branch()
82
        return self.workingtree_format_to.initialize(made_control)
83
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
84
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
85
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
86
    """Generate test suites for each InterTree implementation in bzrlib."""
87
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
88
    def formats_to_scenarios(self, formats):
89
        """Transform the input formats to a list of scenarios.
90
91
        :param formats: A list of tuples:.
92
            (intertree_class,
93
             workingtree_format,
94
             workingtree_format_to,
95
             mutable_trees_to_test_trees)
96
        """
97
        result = []
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
98
        for (label, intertree_class,
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
99
            workingtree_format,
100
            workingtree_format_to,
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
101
            mutable_trees_to_test_trees) in formats:
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
102
            scenario = (label, {
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
103
                "transport_server":self._transport_server,
104
                "transport_readonly_server":self._transport_readonly_server,
105
                "bzrdir_format":workingtree_format._matchingbzrdir,
106
                "workingtree_format":workingtree_format,
107
                "intertree_class":intertree_class,
108
                "workingtree_format_to":workingtree_format_to,
109
                # mutable_trees_to_test_trees takes two trees and converts them to,
110
                # whatever relationship the optimiser under test requires.,
111
                "mutable_trees_to_test_trees":mutable_trees_to_test_trees,
112
                # workingtree_to_test_tree is set to disable changing individual,
113
                # trees: instead the mutable_trees_to_test_trees helper is used.,
3363.1.6 by Aaron Bentley
Add docs
114
                "_workingtree_to_test_tree": return_parameter,
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
115
                })
116
            result.append(scenario)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
117
        return result
118
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
119
def mutable_trees_to_preview_trees(test_case, source, target):
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
120
    preview = TransformPreview(target)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
121
    test_case.addCleanup(preview.finalize)
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
122
    return source, preview.get_preview_tree()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
123
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
124
125
def mutable_trees_to_revision_trees(test_case, source, target):
126
    """Convert both trees to repository based revision trees."""
127
    return (revision_tree_from_workingtree(test_case, source),
128
        revision_tree_from_workingtree(test_case, target))
129
130
3302.9.12 by Vincent Ladeuil
bzrlib.tests.intertree_implementations switched from test_suite()
131
def load_tests(basic_tests, module, loader):
132
    result = loader.suiteClass()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
133
    # load the tests of the infrastructure for these tests
3302.9.12 by Vincent Ladeuil
bzrlib.tests.intertree_implementations switched from test_suite()
134
    result.addTests(basic_tests)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
135
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
136
    default_tree_format = WorkingTreeFormat3()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
137
    test_intertree_implementations = [
138
        'bzrlib.tests.intertree_implementations.test_compare',
139
        ]
140
    test_intertree_permutations = [
141
        # test InterTree with two default-format working trees.
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
142
        (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.
143
         return_provided_trees)]
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
144
    for optimiser in InterTree._optimisers:
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
145
        if optimiser is bzrlib.workingtree_4.InterDirStateTree:
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))
162
        else:
163
            test_intertree_permutations.append(
164
                (optimiser.__name__,
165
                 optimiser,
166
                 optimiser._matching_from_tree_format,
167
                 optimiser._matching_to_tree_format,
168
                 optimiser._test_mutable_trees_to_test_trees))
3696.4.15 by Robert Collins
Merge bzr.dev.
169
    # PreviewTree does not have an InterTree optimiser class.
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
170
    test_intertree_permutations.append(
3696.4.15 by Robert Collins
Merge bzr.dev.
171
        (InterTree.__name__ + "(PreviewTree)",
172
         InterTree,
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
173
         default_tree_format,
174
         default_tree_format,
175
         mutable_trees_to_preview_trees))
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
176
    # CHKInventory does not have an InterTree optimiser class (yet).
177
    chk_tree_format = WorkingTreeFormat4()
178
    chk_tree_format._get_matchingbzrdir = \
3735.17.6 by John Arbash Meinel
Continue tracking down all the references to development3/4
179
        lambda:bzrlib.bzrdir.format_registry.make_bzrdir('development5')
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
180
    test_intertree_permutations.append(
181
        (InterTree.__name__ + "(CHKInventory)",
182
         InterTree,
183
         chk_tree_format,
184
         chk_tree_format,
185
         mutable_trees_to_revision_trees))
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
186
    adapter = InterTreeTestProviderAdapter(
187
        default_transport,
188
        # None here will cause a readonly decorator to be created
189
        # by the TestCaseWithTransport.get_readonly_transport method.
190
        None,
191
        test_intertree_permutations)
3302.9.27 by Vincent Ladeuil
Fixed as per Ian's review.
192
    # add the tests for the sub modules
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
193
    adapt_modules(test_intertree_implementations, adapter, loader, result)
194
    return result