~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2008-08-20 02:07:36 UTC
  • mfrom: (3640 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20080820020736-g2xe4921zzxtymle
Merge bzr.dev

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.errors as errors
 
26
from bzrlib.transport import get_transport
 
27
from bzrlib.tests import (
 
28
                          adapt_modules,
 
29
                          default_transport,
 
30
                          )
 
31
from bzrlib.tests.tree_implementations import (
 
32
    return_parameter,
 
33
    revision_tree_from_workingtree,
 
34
    TestCaseWithTree,
 
35
    )
 
36
from bzrlib.tests.workingtree_implementations import (
 
37
    WorkingTreeTestProviderAdapter,
 
38
    )
 
39
from bzrlib.tree import InterTree
 
40
from bzrlib.workingtree import (
 
41
    WorkingTreeFormat3,
 
42
    )
 
43
 
 
44
 
 
45
def return_provided_trees(source, target):
 
46
    """Return the source and target tree unaltered."""
 
47
    return source, target
 
48
 
 
49
 
 
50
class TestCaseWithTwoTrees(TestCaseWithTree):
 
51
 
 
52
    def make_to_branch_and_tree(self, relpath):
 
53
        """Make a to_workingtree_format branch and tree."""
 
54
        made_control = self.make_bzrdir(relpath, 
 
55
            format=self.workingtree_format_to._matchingbzrdir)
 
56
        made_control.create_repository()
 
57
        made_control.create_branch()
 
58
        return self.workingtree_format_to.initialize(made_control)
 
59
 
 
60
 
 
61
class InterTreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
 
62
    """Generate test suites for each InterTree implementation in bzrlib."""
 
63
 
 
64
    def formats_to_scenarios(self, formats):
 
65
        """Transform the input formats to a list of scenarios.
 
66
 
 
67
        :param formats: A list of tuples:.
 
68
            (intertree_class,
 
69
             workingtree_format,
 
70
             workingtree_format_to,
 
71
             mutable_trees_to_test_trees)
 
72
        """
 
73
        result = []
 
74
        for (intertree_class,
 
75
            workingtree_format,
 
76
            workingtree_format_to,
 
77
            mutable_trees_to_test_trees) in formats:
 
78
            scenario = (intertree_class.__name__, {
 
79
                "transport_server":self._transport_server,
 
80
                "transport_readonly_server":self._transport_readonly_server,
 
81
                "bzrdir_format":workingtree_format._matchingbzrdir,
 
82
                "workingtree_format":workingtree_format,
 
83
                "intertree_class":intertree_class,
 
84
                "workingtree_format_to":workingtree_format_to,
 
85
                # mutable_trees_to_test_trees takes two trees and converts them to,
 
86
                # whatever relationship the optimiser under test requires.,
 
87
                "mutable_trees_to_test_trees":mutable_trees_to_test_trees,
 
88
                # workingtree_to_test_tree is set to disable changing individual,
 
89
                # trees: instead the mutable_trees_to_test_trees helper is used.,
 
90
                "_workingtree_to_test_tree": return_parameter,
 
91
                })
 
92
            result.append(scenario)
 
93
        return result
 
94
 
 
95
 
 
96
def load_tests(basic_tests, module, loader):
 
97
    result = loader.suiteClass()
 
98
    # load the tests of the infrastructure for these tests
 
99
    result.addTests(basic_tests)
 
100
 
 
101
    default_tree_format = WorkingTreeFormat3()
 
102
    test_intertree_implementations = [
 
103
        'bzrlib.tests.intertree_implementations.test_compare',
 
104
        ]
 
105
    test_intertree_permutations = [
 
106
        # test InterTree with two default-format working trees.
 
107
        (InterTree, default_tree_format, default_tree_format,
 
108
         return_provided_trees)]
 
109
    for optimiser in InterTree._optimisers:
 
110
        test_intertree_permutations.append(
 
111
            (optimiser,
 
112
             optimiser._matching_from_tree_format,
 
113
             optimiser._matching_to_tree_format,
 
114
             optimiser._test_mutable_trees_to_test_trees))
 
115
    adapter = InterTreeTestProviderAdapter(
 
116
        default_transport,
 
117
        # None here will cause a readonly decorator to be created
 
118
        # by the TestCaseWithTransport.get_readonly_transport method.
 
119
        None,
 
120
        test_intertree_permutations)
 
121
    # add the tests for the sub modules
 
122
    adapt_modules(test_intertree_implementations, adapter, loader, result)
 
123
    return result