/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_intertree/__init__.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""InterTree implementation tests for bzr.
23
23
"""
24
24
 
25
25
import bzrlib
26
 
import bzrlib.errors as errors
 
26
from bzrlib import (
 
27
    errors,
 
28
    revisiontree,
 
29
    tests,
 
30
    )
27
31
from bzrlib.transport import get_transport
28
32
from bzrlib.transform import TransformPreview
29
33
from bzrlib.tests import (
30
 
                          adapt_modules,
31
 
                          default_transport,
32
 
                          )
33
 
from bzrlib.tests.tree_implementations import (
 
34
    default_transport,
 
35
    multiply_tests,
 
36
    )
 
37
from bzrlib.tests.per_tree import (
34
38
    return_parameter,
35
39
    revision_tree_from_workingtree,
36
40
    TestCaseWithTree,
37
41
    )
38
 
from bzrlib.tests.workingtree_implementations import (
39
 
    WorkingTreeTestProviderAdapter,
40
 
    )
41
42
from bzrlib.tree import InterTree
42
43
from bzrlib.workingtree import (
43
44
    WorkingTreeFormat3,
44
45
    )
 
46
from bzrlib.workingtree_4 import WorkingTreeFormat4
45
47
 
46
48
 
47
49
def return_provided_trees(test_case, source, target):
51
53
 
52
54
class TestCaseWithTwoTrees(TestCaseWithTree):
53
55
 
 
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
 
70
            # revision trees cannot have missing files.
 
71
            raise tests.TestNotApplicable('cannot represent missing files')
 
72
 
54
73
    def make_to_branch_and_tree(self, relpath):
55
74
        """Make a to_workingtree_format branch and tree."""
56
 
        made_control = self.make_bzrdir(relpath, 
 
75
        made_control = self.make_bzrdir(relpath,
57
76
            format=self.workingtree_format_to._matchingbzrdir)
58
77
        made_control.create_repository()
59
78
        made_control.create_branch()
60
79
        return self.workingtree_format_to.initialize(made_control)
61
80
 
62
81
 
63
 
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
64
 
    """Generate test suites for each InterTree implementation in bzrlib."""
65
 
 
66
 
    def formats_to_scenarios(self, formats):
67
 
        """Transform the input formats to a list of scenarios.
68
 
 
69
 
        :param formats: A list of tuples:.
70
 
            (intertree_class,
71
 
             workingtree_format,
72
 
             workingtree_format_to,
73
 
             mutable_trees_to_test_trees)
74
 
        """
75
 
        result = []
76
 
        for (label, intertree_class,
77
 
            workingtree_format,
78
 
            workingtree_format_to,
79
 
            mutable_trees_to_test_trees) in formats:
80
 
            scenario = (label, {
81
 
                "transport_server":self._transport_server,
82
 
                "transport_readonly_server":self._transport_readonly_server,
83
 
                "bzrdir_format":workingtree_format._matchingbzrdir,
84
 
                "workingtree_format":workingtree_format,
85
 
                "intertree_class":intertree_class,
86
 
                "workingtree_format_to":workingtree_format_to,
87
 
                # mutable_trees_to_test_trees takes two trees and converts them to,
88
 
                # whatever relationship the optimiser under test requires.,
89
 
                "mutable_trees_to_test_trees":mutable_trees_to_test_trees,
90
 
                # workingtree_to_test_tree is set to disable changing individual,
91
 
                # trees: instead the mutable_trees_to_test_trees helper is used.,
92
 
                "_workingtree_to_test_tree": return_parameter,
93
 
                })
94
 
            result.append(scenario)
95
 
        return result
 
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
 
96
113
 
97
114
def mutable_trees_to_preview_trees(test_case, source, target):
98
115
    preview = TransformPreview(target)
99
116
    test_case.addCleanup(preview.finalize)
100
117
    return source, preview.get_preview_tree()
101
118
 
102
 
def load_tests(basic_tests, module, loader):
103
 
    result = loader.suiteClass()
104
 
    # load the tests of the infrastructure for these tests
105
 
    result.addTests(basic_tests)
106
 
 
 
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
 
 
125
def load_tests(standard_tests, module, loader):
107
126
    default_tree_format = WorkingTreeFormat3()
108
 
    test_intertree_implementations = [
109
 
        'bzrlib.tests.intertree_implementations.test_compare',
110
 
        ]
 
127
    submod_tests = loader.loadTestsFromModuleNames([
 
128
        'bzrlib.tests.per_intertree.test_compare',
 
129
        ])
111
130
    test_intertree_permutations = [
112
131
        # test InterTree with two default-format working trees.
113
 
        (InterTree.__name__, InterTree, default_tree_format, default_tree_format,
 
132
        (InterTree.__name__, InterTree,
 
133
         default_tree_format, default_tree_format,
114
134
         return_provided_trees)]
115
135
    for optimiser in InterTree._optimisers:
116
 
        if optimiser is bzrlib.workingtree_4.InterDirStateTree:
 
136
        if optimiser is revisiontree.InterCHKRevisionTree:
 
137
            # XXX: we shouldn't use an Intertree object to detect inventories
 
138
            # -- vila 20090311
 
139
            chk_tree_format = WorkingTreeFormat4()
 
140
            chk_tree_format._get_matchingbzrdir = \
 
141
                lambda:bzrlib.bzrdir.format_registry.make_bzrdir(
 
142
                    'development6-rich-root')
 
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))
 
149
        elif optimiser is bzrlib.workingtree_4.InterDirStateTree:
117
150
            # Its a little ugly to be conditional here, but less so than having
118
151
            # the optimiser listed twice.
119
152
            # Add once, compiled version
130
163
                 optimiser._matching_from_tree_format,
131
164
                 optimiser._matching_to_tree_format,
132
165
                 optimiser.make_source_parent_tree_python_dirstate))
133
 
        else:
 
166
        elif (optimiser._matching_from_tree_format is not None and 
 
167
              optimiser._matching_to_tree_format is not None):
134
168
            test_intertree_permutations.append(
135
169
                (optimiser.__name__,
136
170
                 optimiser,
144
178
         default_tree_format,
145
179
         default_tree_format,
146
180
         mutable_trees_to_preview_trees))
147
 
    adapter = InterTreeTestProviderAdapter(
 
181
    scenarios = make_scenarios(
148
182
        default_transport,
149
183
        # None here will cause a readonly decorator to be created
150
184
        # by the TestCaseWithTransport.get_readonly_transport method.
151
185
        None,
152
186
        test_intertree_permutations)
153
 
    # add the tests for the sub modules
154
 
    adapt_modules(test_intertree_implementations, adapter, loader, result)
155
 
    return result
 
187
    # add the tests for the sub modules to the standard tests.
 
188
    return multiply_tests(submod_tests, scenarios, standard_tests)