~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2008-10-16 21:27:10 UTC
  • mfrom: (0.15.26 unshelve)
  • mto: (0.16.74 shelf-ui)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081016212710-h9av3nhk76dvmsv5
Merge with unshelve

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
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
 
 
25
import bzrlib
 
26
import bzrlib.errors as errors
 
27
from bzrlib.transport import get_transport
 
28
from bzrlib.transform import TransformPreview
 
29
from bzrlib.tests import (
 
30
                          adapt_modules,
 
31
                          default_transport,
 
32
                          )
 
33
from bzrlib.tests.tree_implementations import (
 
34
    return_parameter,
 
35
    revision_tree_from_workingtree,
 
36
    TestCaseWithTree,
 
37
    )
 
38
from bzrlib.tests.workingtree_implementations import (
 
39
    WorkingTreeTestProviderAdapter,
 
40
    )
 
41
from bzrlib.tree import InterTree
 
42
from bzrlib.workingtree import (
 
43
    WorkingTreeFormat3,
 
44
    )
 
45
 
 
46
 
 
47
def return_provided_trees(test_case, source, target):
 
48
    """Return the source and target tree unaltered."""
 
49
    return source, target
 
50
 
 
51
 
 
52
class TestCaseWithTwoTrees(TestCaseWithTree):
 
53
 
 
54
    def make_to_branch_and_tree(self, relpath):
 
55
        """Make a to_workingtree_format branch and tree."""
 
56
        made_control = self.make_bzrdir(relpath, 
 
57
            format=self.workingtree_format_to._matchingbzrdir)
 
58
        made_control.create_repository()
 
59
        made_control.create_branch()
 
60
        return self.workingtree_format_to.initialize(made_control)
 
61
 
 
62
 
 
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
 
96
 
 
97
def mutable_trees_to_preview_trees(test_case, source, target):
 
98
    preview = TransformPreview(target)
 
99
    test_case.addCleanup(preview.finalize)
 
100
    return source, preview.get_preview_tree()
 
101
 
 
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
 
 
107
    default_tree_format = WorkingTreeFormat3()
 
108
    test_intertree_implementations = [
 
109
        'bzrlib.tests.intertree_implementations.test_compare',
 
110
        ]
 
111
    test_intertree_permutations = [
 
112
        # test InterTree with two default-format working trees.
 
113
        (InterTree.__name__, InterTree, default_tree_format, default_tree_format,
 
114
         return_provided_trees)]
 
115
    for optimiser in InterTree._optimisers:
 
116
        if optimiser is bzrlib.workingtree_4.InterDirStateTree:
 
117
            # Its a little ugly to be conditional here, but less so than having
 
118
            # the optimiser listed twice.
 
119
            # Add once, compiled version
 
120
            test_intertree_permutations.append(
 
121
                (optimiser.__name__ + "(C)",
 
122
                 optimiser,
 
123
                 optimiser._matching_from_tree_format,
 
124
                 optimiser._matching_to_tree_format,
 
125
                 optimiser.make_source_parent_tree_compiled_dirstate))
 
126
            # python version
 
127
            test_intertree_permutations.append(
 
128
                (optimiser.__name__ + "(PY)",
 
129
                 optimiser,
 
130
                 optimiser._matching_from_tree_format,
 
131
                 optimiser._matching_to_tree_format,
 
132
                 optimiser.make_source_parent_tree_python_dirstate))
 
133
        else:
 
134
            test_intertree_permutations.append(
 
135
                (optimiser.__name__,
 
136
                 optimiser,
 
137
                 optimiser._matching_from_tree_format,
 
138
                 optimiser._matching_to_tree_format,
 
139
                 optimiser._test_mutable_trees_to_test_trees))
 
140
    # PreviewTree does not have an InterTree optimiser class.
 
141
    test_intertree_permutations.append(
 
142
        (InterTree.__name__ + "(PreviewTree)",
 
143
         InterTree,
 
144
         default_tree_format,
 
145
         default_tree_format,
 
146
         mutable_trees_to_preview_trees))
 
147
    adapter = InterTreeTestProviderAdapter(
 
148
        default_transport,
 
149
        # None here will cause a readonly decorator to be created
 
150
        # by the TestCaseWithTransport.get_readonly_transport method.
 
151
        None,
 
152
        test_intertree_permutations)
 
153
    # add the tests for the sub modules
 
154
    adapt_modules(test_intertree_implementations, adapter, loader, result)
 
155
    return result