/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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
import breezy
26
from breezy import (
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
27
    revisiontree,
28
    tests,
29
    )
6670.4.12 by Jelmer Vernooij
Move inventorytree to breezy.bzr.
30
from breezy.bzr import (
31
    inventorytree,
32
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
33
from breezy.transform import TransformPreview
34
from breezy.tests import (
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
35
    default_transport,
36
    multiply_tests,
37
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
38
from breezy.tests.per_tree import (
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
39
    return_parameter,
40
    revision_tree_from_workingtree,
41
    TestCaseWithTree,
42
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
43
from breezy.tree import InterTree
6670.4.1 by Jelmer Vernooij
Update imports.
44
from breezy.bzr.workingtree_3 import WorkingTreeFormat3
45
from breezy.bzr.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):
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
65
        if not tree.is_versioned(relpath):
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
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."""
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
74
        made_control = self.make_controldir(relpath,
7143.15.2 by Jelmer Vernooij
Run autopep8.
75
                                            format=self.workingtree_format_to._matchingcontroldir)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
92
         workingtree_format,
93
         workingtree_format_to,
94
         mutable_trees_to_test_trees) in formats:
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
95
        scenario = (label, {
96
            "transport_server": transport_server,
97
            "transport_readonly_server": transport_readonly_server,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
98
            "bzrdir_format": workingtree_format._matchingcontroldir,
99
            "workingtree_format": workingtree_format,
100
            "intertree_class": intertree_class,
101
            "workingtree_format_to": workingtree_format_to,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
102
            # mutable_trees_to_test_trees takes two trees and converts them to,
103
            # whatever relationship the optimiser under test requires.,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
104
            "mutable_trees_to_test_trees": mutable_trees_to_test_trees,
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
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
7143.15.2 by Jelmer Vernooij
Run autopep8.
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),
7143.15.2 by Jelmer Vernooij
Run autopep8.
122
            revision_tree_from_workingtree(test_case, target))
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
123
124
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
125
def load_tests(loader, standard_tests, pattern):
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([
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
128
        'breezy.tests.per_intertree.test_compare',
129
        'breezy.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.
130
        ])
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
131
    test_intertree_permutations = [
132
        # test InterTree with two default-format working trees.
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
133
        (InterTree.__name__, InterTree,
134
         default_tree_format, default_tree_format,
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
135
         return_provided_trees)]
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
136
    for optimiser in InterTree._optimisers:
6672.2.5 by Jelmer Vernooij
Fix remaining inventorytree reference.
137
        if optimiser is inventorytree.InterCHKRevisionTree:
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
138
            # XXX: we shouldn't use an Intertree object to detect inventories
139
            # -- vila 20090311
140
            chk_tree_format = WorkingTreeFormat4()
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
141
            chk_tree_format._get_matchingcontroldir = \
7143.15.2 by Jelmer Vernooij
Run autopep8.
142
                lambda: breezy.controldir.format_registry.make_controldir('2a')
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))
6670.4.1 by Jelmer Vernooij
Update imports.
149
        elif optimiser is breezy.bzr.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))
7143.15.2 by Jelmer Vernooij
Run autopep8.
166
        elif (optimiser._matching_from_tree_format is not None and
4585.1.17 by Jelmer Vernooij
Skip InterTree tests if from/to test tree formats are set to None (required for bzr-git).
167
              optimiser._matching_to_tree_format is not None):
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
168
            test_intertree_permutations.append(
169
                (optimiser.__name__,
170
                 optimiser,
171
                 optimiser._matching_from_tree_format,
172
                 optimiser._matching_to_tree_format,
173
                 optimiser._test_mutable_trees_to_test_trees))
3696.4.15 by Robert Collins
Merge bzr.dev.
174
    # PreviewTree does not have an InterTree optimiser class.
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
175
    test_intertree_permutations.append(
3696.4.15 by Robert Collins
Merge bzr.dev.
176
        (InterTree.__name__ + "(PreviewTree)",
177
         InterTree,
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
178
         default_tree_format,
179
         default_tree_format,
180
         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.
181
    scenarios = make_scenarios(
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
182
        default_transport,
183
        # None here will cause a readonly decorator to be created
184
        # by the TestCaseWithTransport.get_readonly_transport method.
185
        None,
186
        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.
187
    # add the tests for the sub modules to the standard tests.
188
    return multiply_tests(submod_tests, scenarios, standard_tests)