/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.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
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
37
from breezy.tests.per_tree import (
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
38
    return_parameter,
39
    revision_tree_from_workingtree,
40
    TestCaseWithTree,
41
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
42
from breezy.tree import InterTree
6670.4.1 by Jelmer Vernooij
Update imports.
43
from breezy.bzr.workingtree_3 import WorkingTreeFormat3
44
from breezy.bzr.workingtree_4 import WorkingTreeFormat4
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
45
46
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
47
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.
48
    """Return the source and target tree unaltered."""
49
    return source, target
50
51
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
52
class TestCaseWithTwoTrees(TestCaseWithTree):
53
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
54
    def not_applicable_if_cannot_represent_unversioned(self, tree):
55
        if isinstance(tree, revisiontree.RevisionTree):
56
            # The locked test trees conversion could not preserve the
57
            # unversioned file status. This is normal (e.g. InterDirstateTree
58
            # falls back to InterTree if the basis is not a
59
            # DirstateRevisionTree, and revision trees cannot have unversioned
60
            # files.
61
            raise tests.TestNotApplicable('cannot represent unversioned files')
62
63
    def not_applicable_if_missing_in(self, relpath, tree):
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
64
        if not tree.is_versioned(relpath):
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
65
            # The locked test trees conversion could not preserve the missing
66
            # file status. This is normal (e.g. InterDirstateTree falls back
67
            # to InterTree if the basis is not a DirstateRevisionTree, and
3735.2.99 by John Arbash Meinel
Merge bzr.dev 4034. Whitespace cleanup
68
            # revision trees cannot have missing files.
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
69
            raise tests.TestNotApplicable('cannot represent missing files')
70
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
71
    def make_to_branch_and_tree(self, relpath):
72
        """Make a to_workingtree_format branch and tree."""
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
73
        made_control = self.make_controldir(relpath,
7143.15.2 by Jelmer Vernooij
Run autopep8.
74
                                            format=self.workingtree_format_to._matchingcontroldir)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
75
        made_control.create_repository()
76
        made_control.create_branch()
77
        return self.workingtree_format_to.initialize(made_control)
78
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
79
4084.5.1 by Robert Collins
Bulk update all test adaptation into a single approach, using multiply_tests rather than test adapters.
80
def make_scenarios(transport_server, transport_readonly_server, formats):
81
    """Transform the input formats to a list of scenarios.
82
83
    :param formats: A list of tuples:.
84
        (intertree_class,
85
         workingtree_format,
86
         workingtree_format_to,
87
         mutable_trees_to_test_trees)
88
    """
89
    result = []
90
    for (label, intertree_class,
7143.15.2 by Jelmer Vernooij
Run autopep8.
91
         workingtree_format,
92
         workingtree_format_to,
93
         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.
94
        scenario = (label, {
95
            "transport_server": transport_server,
96
            "transport_readonly_server": transport_readonly_server,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
97
            "bzrdir_format": workingtree_format._matchingcontroldir,
98
            "workingtree_format": workingtree_format,
99
            "intertree_class": intertree_class,
100
            "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.
101
            # mutable_trees_to_test_trees takes two trees and converts them to,
102
            # whatever relationship the optimiser under test requires.,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
103
            "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.
104
            # workingtree_to_test_tree is set to disable changing individual,
105
            # trees: instead the mutable_trees_to_test_trees helper is used.,
106
            "_workingtree_to_test_tree": return_parameter,
107
            })
108
        result.append(scenario)
109
    return result
110
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
111
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
112
def mutable_trees_to_preview_trees(test_case, source, target):
7490.77.2 by Jelmer Vernooij
Split out git and bzr-specific transforms.
113
    preview = target.preview_transform()
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
114
    test_case.addCleanup(preview.finalize)
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
115
    return source, preview.get_preview_tree()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
116
7143.15.2 by Jelmer Vernooij
Run autopep8.
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),
7143.15.2 by Jelmer Vernooij
Run autopep8.
121
            revision_tree_from_workingtree(test_case, target))
3735.2.35 by Robert Collins
Hook in CHKInventory to the intertree tests.
122
123
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
124
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
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([
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
127
        'breezy.tests.per_intertree.test_compare',
128
        'breezy.tests.per_intertree.test_file_content_matches',
7357.1.7 by Jelmer Vernooij
Add tests.
129
        'breezy.tests.per_intertree.test_find_path',
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.
7467.4.15 by Jelmer Vernooij
Split out InventoryInterTree.
133
        (inventorytree.InterInventoryTree.__name__,
134
         inventorytree.InterInventoryTree,
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
135
         default_tree_format, default_tree_format,
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
136
         return_provided_trees)]
7490.64.2 by Jelmer Vernooij
Fix optimiser iteration.
137
    for optimiser in InterTree.iter_optimisers():
6672.2.5 by Jelmer Vernooij
Fix remaining inventorytree reference.
138
        if optimiser is inventorytree.InterCHKRevisionTree:
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
139
            # XXX: we shouldn't use an Intertree object to detect inventories
140
            # -- vila 20090311
141
            chk_tree_format = WorkingTreeFormat4()
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
142
            chk_tree_format._get_matchingcontroldir = \
7143.15.2 by Jelmer Vernooij
Run autopep8.
143
                lambda: breezy.controldir.format_registry.make_controldir('2a')
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
144
            test_intertree_permutations.append(
7467.4.15 by Jelmer Vernooij
Split out InventoryInterTree.
145
                (inventorytree.InterInventoryTree.__name__ + "(CHKInventory)",
146
                 inventorytree.InterInventoryTree,
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
147
                 chk_tree_format,
148
                 chk_tree_format,
149
                 mutable_trees_to_revision_trees))
6670.4.1 by Jelmer Vernooij
Update imports.
150
        elif optimiser is breezy.bzr.workingtree_4.InterDirStateTree:
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
151
            # Its a little ugly to be conditional here, but less so than having
152
            # the optimiser listed twice.
153
            # Add once, compiled version
154
            test_intertree_permutations.append(
155
                (optimiser.__name__ + "(C)",
156
                 optimiser,
157
                 optimiser._matching_from_tree_format,
158
                 optimiser._matching_to_tree_format,
159
                 optimiser.make_source_parent_tree_compiled_dirstate))
160
            # python version
161
            test_intertree_permutations.append(
162
                (optimiser.__name__ + "(PY)",
163
                 optimiser,
164
                 optimiser._matching_from_tree_format,
165
                 optimiser._matching_to_tree_format,
166
                 optimiser.make_source_parent_tree_python_dirstate))
7143.15.2 by Jelmer Vernooij
Run autopep8.
167
        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).
168
              optimiser._matching_to_tree_format is not None):
3696.4.10 by Robert Collins
Basic first cut of full-pyrex iter_changes.
169
            test_intertree_permutations.append(
170
                (optimiser.__name__,
171
                 optimiser,
172
                 optimiser._matching_from_tree_format,
173
                 optimiser._matching_to_tree_format,
174
                 optimiser._test_mutable_trees_to_test_trees))
3696.4.15 by Robert Collins
Merge bzr.dev.
175
    # PreviewTree does not have an InterTree optimiser class.
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
176
    test_intertree_permutations.append(
7467.4.15 by Jelmer Vernooij
Split out InventoryInterTree.
177
        (inventorytree.InterInventoryTree.__name__ + "(PreviewTree)",
178
         inventorytree.InterInventoryTree,
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
179
         default_tree_format,
180
         default_tree_format,
181
         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.
182
    scenarios = make_scenarios(
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
183
        default_transport,
184
        # None here will cause a readonly decorator to be created
185
        # by the TestCaseWithTransport.get_readonly_transport method.
186
        None,
187
        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.
188
    # add the tests for the sub modules to the standard tests.
189
    return multiply_tests(submod_tests, scenarios, standard_tests)