~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge Tree.changes_from work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by 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.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
 
 
44
class TestCaseWithTwoTrees(TestCaseWithTree):
 
45
 
 
46
    def make_to_branch_and_tree(self, relpath):
 
47
        """Make a to_workingtree_format branch and tree."""
 
48
        made_control = self.make_bzrdir(relpath, 
 
49
            format=self.workingtree_format_to._matchingbzrdir)
 
50
        made_control.create_repository()
 
51
        made_control.create_branch()
 
52
        return self.workingtree_format_to.initialize(made_control)
 
53
 
 
54
    def get_to_tree_no_parents_no_content(self, empty_tree):
 
55
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_no_content(empty_tree, converter=self.workingtree_to_test_tree_to)
 
56
 
 
57
    def get_to_tree_no_parents_abc_content(self, empty_tree):
 
58
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_abc_content(empty_tree, converter=self.workingtree_to_test_tree_to)
 
59
 
 
60
    def get_to_tree_no_parents_abc_content_2(self, empty_tree):
 
61
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_abc_content_2(empty_tree, converter=self.workingtree_to_test_tree_to)
 
62
 
 
63
    def get_to_tree_no_parents_abc_content_3(self, empty_tree):
 
64
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_abc_content_3(empty_tree, converter=self.workingtree_to_test_tree_to)
 
65
 
 
66
    def get_to_tree_no_parents_abc_content_4(self, empty_tree):
 
67
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_abc_content_4(empty_tree, converter=self.workingtree_to_test_tree_to)
 
68
 
 
69
    def get_to_tree_no_parents_abc_content_5(self, empty_tree):
 
70
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_abc_content_5(empty_tree, converter=self.workingtree_to_test_tree_to)
 
71
 
 
72
    def get_to_tree_no_parents_abc_content_6(self, empty_tree):
 
73
        return super(TestCaseWithTwoTrees, self).get_tree_no_parents_abc_content_6(empty_tree, converter=self.workingtree_to_test_tree_to)
 
74
 
 
75
 
 
76
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
 
77
    """Generate test suites for each InterTree implementation in bzrlib."""
 
78
 
 
79
    def adapt(self, test):
 
80
        result = TestSuite()
 
81
        for (intertree_class,
 
82
            workingtree_format,
 
83
            workingtree_to_test_tree,
 
84
            workingtree_format_to,
 
85
            workingtree_to_test_tree_to) in self._formats:
 
86
            new_test = self._clone_test(
 
87
                test,
 
88
                workingtree_format._matchingbzrdir,
 
89
                workingtree_format,
 
90
                intertree_class.__name__)
 
91
            new_test.intertree_class = intertree_class
 
92
            new_test.workingtree_to_test_tree = workingtree_to_test_tree
 
93
            new_test.workingtree_format_to = workingtree_format_to
 
94
            new_test.workingtree_to_test_tree_to = workingtree_to_test_tree_to
 
95
            result.addTest(new_test)
 
96
        return result
 
97
 
 
98
 
 
99
def test_suite():
 
100
    result = TestSuite()
 
101
    loader = TestLoader()
 
102
    # load the tests of the infrastructure for these tests
 
103
    result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.intertree_implementations']))
 
104
 
 
105
    default_tree_format = WorkingTreeFormat.get_default_format()
 
106
    test_intertree_implementations = [
 
107
        'bzrlib.tests.intertree_implementations.test_compare',
 
108
        ]
 
109
    test_intertree_permutations = [
 
110
        # test InterTree with two default-format working trees.
 
111
        (InterTree, default_tree_format, return_parameter,
 
112
         default_tree_format, return_parameter)]
 
113
    for optimiser in InterTree._optimisers:
 
114
        test_intertree_permutations.append(
 
115
            (optimiser,
 
116
             optimiser._matching_from_tree_format, optimiser._from_tree_converter,
 
117
             optimiser._matching_to_tree_format, optimiser._to_tree_converter))
 
118
    adapter = InterTreeTestProviderAdapter(
 
119
        default_transport,
 
120
        # None here will cause a readonly decorator to be created
 
121
        # by the TestCaseWithTransport.get_readonly_transport method.
 
122
        None,
 
123
        test_intertree_permutations)
 
124
    adapt_modules(test_intertree_implementations, adapter, loader, result)
 
125
    return result