/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
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
27
from bzrlib.transform import TransformPreview
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
28
from bzrlib.tests import (
29
                          adapt_modules,
30
                          default_transport,
31
                          )
32
from bzrlib.tests.tree_implementations import (
33
    return_parameter,
34
    revision_tree_from_workingtree,
35
    TestCaseWithTree,
36
    )
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
37
from bzrlib.tests.workingtree_implementations import (
38
    WorkingTreeTestProviderAdapter,
39
    )
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
40
from bzrlib.tree import InterTree
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
41
from bzrlib.workingtree import (
42
    WorkingTreeFormat3,
43
    )
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
44
45
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
46
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.
47
    """Return the source and target tree unaltered."""
48
    return source, target
49
50
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
51
class TestCaseWithTwoTrees(TestCaseWithTree):
52
53
    def make_to_branch_and_tree(self, relpath):
54
        """Make a to_workingtree_format branch and tree."""
55
        made_control = self.make_bzrdir(relpath, 
56
            format=self.workingtree_format_to._matchingbzrdir)
57
        made_control.create_repository()
58
        made_control.create_branch()
59
        return self.workingtree_format_to.initialize(made_control)
60
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
61
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
62
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
63
    """Generate test suites for each InterTree implementation in bzrlib."""
64
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
65
    def formats_to_scenarios(self, formats):
66
        """Transform the input formats to a list of scenarios.
67
68
        :param formats: A list of tuples:.
69
            (intertree_class,
70
             workingtree_format,
71
             workingtree_format_to,
72
             mutable_trees_to_test_trees)
73
        """
74
        result = []
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
75
        for (intertree_class,
76
            workingtree_format,
77
            workingtree_format_to,
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
78
            mutable_trees_to_test_trees) in formats:
79
            scenario = (intertree_class.__name__, {
80
                "transport_server":self._transport_server,
81
                "transport_readonly_server":self._transport_readonly_server,
82
                "bzrdir_format":workingtree_format._matchingbzrdir,
83
                "workingtree_format":workingtree_format,
84
                "intertree_class":intertree_class,
85
                "workingtree_format_to":workingtree_format_to,
86
                # mutable_trees_to_test_trees takes two trees and converts them to,
87
                # whatever relationship the optimiser under test requires.,
88
                "mutable_trees_to_test_trees":mutable_trees_to_test_trees,
89
                # workingtree_to_test_tree is set to disable changing individual,
90
                # trees: instead the mutable_trees_to_test_trees helper is used.,
3363.1.6 by Aaron Bentley
Add docs
91
                "_workingtree_to_test_tree": return_parameter,
2553.2.10 by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too.
92
                })
93
            result.append(scenario)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
94
        return result
95
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
96
def mutable_trees_to_preview_trees(test_case, source, target):
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
97
    preview = TransformPreview(target)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
98
    test_case.addCleanup(preview.finalize)
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
99
    return source, preview.get_preview_tree()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
100
3302.9.12 by Vincent Ladeuil
bzrlib.tests.intertree_implementations switched from test_suite()
101
def load_tests(basic_tests, module, loader):
102
    result = loader.suiteClass()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
103
    # load the tests of the infrastructure for these tests
3302.9.12 by Vincent Ladeuil
bzrlib.tests.intertree_implementations switched from test_suite()
104
    result.addTests(basic_tests)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
105
2255.2.164 by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3
106
    default_tree_format = WorkingTreeFormat3()
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
107
    test_intertree_implementations = [
108
        'bzrlib.tests.intertree_implementations.test_compare',
109
        ]
110
    test_intertree_permutations = [
111
        # 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.
112
        (InterTree, default_tree_format, default_tree_format,
113
         return_provided_trees)]
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
114
    for optimiser in InterTree._optimisers:
115
        test_intertree_permutations.append(
116
            (optimiser,
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
117
             optimiser._matching_from_tree_format,
118
             optimiser._matching_to_tree_format,
119
             optimiser._test_mutable_trees_to_test_trees))
3363.14.2 by Aaron Bentley
Get iter_changes running to completion
120
121
    # test PreviewTree
122
    test_intertree_permutations.append(
123
        (InterTree,
124
         default_tree_format,
125
         default_tree_format,
126
         mutable_trees_to_preview_trees))
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
127
    adapter = InterTreeTestProviderAdapter(
128
        default_transport,
129
        # None here will cause a readonly decorator to be created
130
        # by the TestCaseWithTransport.get_readonly_transport method.
131
        None,
132
        test_intertree_permutations)
3302.9.27 by Vincent Ladeuil
Fixed as per Ian's review.
133
    # add the tests for the sub modules
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
134
    adapt_modules(test_intertree_implementations, adapter, loader, result)
135
    return result