/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
25
import bzrlib.errors as errors
26
from bzrlib.transport import get_transport
27
from bzrlib.tests import (
28
                          adapt_modules,
29
                          default_transport,
30
                          TestLoader,
31
                          TestSuite,
32
                          )
33
from bzrlib.tests.tree_implementations import (
34
    return_parameter,
35
    revision_tree_from_workingtree,
36
    TestCaseWithTree,
37
    )
38
from bzrlib.tree import InterTree
39
from bzrlib.workingtree import (WorkingTreeFormat,
40
                                WorkingTreeTestProviderAdapter,
41
                                )
42
43
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
44
def return_provided_trees(source, target):
45
    """Return the source and target tree unaltered."""
46
    return source, target
47
48
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
49
class TestCaseWithTwoTrees(TestCaseWithTree):
50
51
    def make_to_branch_and_tree(self, relpath):
52
        """Make a to_workingtree_format branch and tree."""
53
        made_control = self.make_bzrdir(relpath, 
54
            format=self.workingtree_format_to._matchingbzrdir)
55
        made_control.create_repository()
56
        made_control.create_branch()
57
        return self.workingtree_format_to.initialize(made_control)
58
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
59
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
60
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
61
    """Generate test suites for each InterTree implementation in bzrlib."""
62
63
    def adapt(self, test):
64
        result = TestSuite()
65
        for (intertree_class,
66
            workingtree_format,
67
            workingtree_format_to,
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
68
            mutable_trees_to_test_trees) in self._formats:
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
69
            new_test = self._clone_test(
70
                test,
71
                workingtree_format._matchingbzrdir,
72
                workingtree_format,
73
                intertree_class.__name__)
74
            new_test.intertree_class = intertree_class
75
            new_test.workingtree_format_to = workingtree_format_to
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
76
            # mutable_trees_to_test_trees takes two trees and converts them to
77
            # whatever relationship the optimiser under test requires.
78
            new_test.mutable_trees_to_test_trees = mutable_trees_to_test_trees
79
            # workingtree_to_test_tree is set to disable changing individual
80
            # trees: instead the mutable_trees_to_test_trees helper is used.
81
            new_test.workingtree_to_test_tree = return_parameter
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
82
            result.addTest(new_test)
83
        return result
84
85
86
def test_suite():
87
    result = TestSuite()
88
    loader = TestLoader()
89
    # load the tests of the infrastructure for these tests
90
    result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.intertree_implementations']))
91
92
    default_tree_format = WorkingTreeFormat.get_default_format()
93
    test_intertree_implementations = [
94
        'bzrlib.tests.intertree_implementations.test_compare',
95
        ]
96
    test_intertree_permutations = [
97
        # test InterTree with two default-format working trees.
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
98
        (InterTree, default_tree_format, default_tree_format,
99
         return_provided_trees)]
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
100
    for optimiser in InterTree._optimisers:
101
        test_intertree_permutations.append(
102
            (optimiser,
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
103
             optimiser._matching_from_tree_format,
104
             optimiser._matching_to_tree_format,
105
             optimiser._test_mutable_trees_to_test_trees))
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
106
    adapter = InterTreeTestProviderAdapter(
107
        default_transport,
108
        # None here will cause a readonly decorator to be created
109
        # by the TestCaseWithTransport.get_readonly_transport method.
110
        None,
111
        test_intertree_permutations)
112
    adapt_modules(test_intertree_implementations, adapter, loader, result)
113
    return result