~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""WorkingTree implementation tests for bzr.
19
19
 
20
 
This test the conformance of all the workingtre variations to the expected API.
21
 
Specific tests for individual formats are in the tests/test_workingtree file
22
 
rather than in tests/per_workingtree/*.py.
 
20
These test the conformance of all the workingtre variations to the expected API.
 
21
Specific tests for individual formats are in the tests/test_workingtree file 
 
22
rather than in tests/workingtree_implementations/*.py.
23
23
"""
24
24
 
25
 
from bzrlib import (
26
 
    branchbuilder,
27
 
    tests,
28
 
    transport,
29
 
    workingtree,
30
 
    )
31
 
from bzrlib.transport import memory
 
25
import bzrlib.errors as errors
 
26
from bzrlib.transport import get_transport
32
27
from bzrlib.tests import (
33
 
    per_controldir,
34
 
    test_server,
35
 
    )
36
 
 
37
 
 
38
 
def make_scenarios(transport_server, transport_readonly_server, formats,
39
 
                   remote_server=None, remote_readonly_server=None,
40
 
                   remote_backing_server=None):
41
 
    result = []
42
 
    for workingtree_format in formats:
43
 
        result.append((workingtree_format.__class__.__name__,
44
 
                       make_scenario(transport_server,
45
 
                                     transport_readonly_server,
46
 
                                     workingtree_format)))
47
 
    default_wt_format = workingtree.format_registry.get_default()
48
 
    if remote_server is None:
49
 
        remote_server = test_server.SmartTCPServer_for_testing
50
 
    if remote_readonly_server is None:
51
 
        remote_readonly_server = test_server.ReadonlySmartTCPServer_for_testing
52
 
    if remote_backing_server is None:
53
 
        remote_backing_server = memory.MemoryServer
54
 
    scenario = make_scenario(remote_server, remote_readonly_server,
55
 
                             default_wt_format)
56
 
    scenario['repo_is_remote'] = True;
57
 
    scenario['vfs_transport_factory'] = remote_backing_server
58
 
    result.append((default_wt_format.__class__.__name__ + ',remote', scenario))
59
 
    return result
60
 
 
61
 
 
62
 
def make_scenario(transport_server, transport_readonly_server,
63
 
                  workingtree_format):
64
 
    return {
65
 
        "transport_server": transport_server,
66
 
        "transport_readonly_server": transport_readonly_server,
67
 
        "bzrdir_format": workingtree_format._matchingbzrdir,
68
 
        "workingtree_format": workingtree_format,
69
 
        }
70
 
 
71
 
 
72
 
def wt_scenarios():
73
 
    """Returns the scenarios for all registered working trees.
74
 
 
75
 
    This can used by plugins that want to define tests against these working
76
 
    trees.
 
28
                          adapt_modules,
 
29
                          default_transport,
 
30
                          TestScenarioApplier,
 
31
                          )
 
32
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
33
from bzrlib.workingtree import (WorkingTreeFormat,
 
34
                                _legacy_formats,
 
35
                                )
 
36
 
 
37
 
 
38
class WorkingTreeTestProviderAdapter(TestScenarioApplier):
 
39
    """A tool to generate a suite testing multiple workingtree formats at once.
 
40
 
 
41
    This is done by copying the test once for each transport and injecting
 
42
    the transport_server, transport_readonly_server, and workingtree_format
 
43
    classes into each copy. Each copy is also given a new id() to make it
 
44
    easy to identify.
77
45
    """
78
 
    scenarios = make_scenarios(
79
 
        tests.default_transport,
80
 
        # None here will cause a readonly decorator to be created
81
 
        # by the TestCaseWithTransport.get_readonly_transport method.
82
 
        None,
83
 
        workingtree.format_registry._get_all()
84
 
        )
85
 
    return scenarios
86
 
 
87
 
 
88
 
class TestCaseWithWorkingTree(per_controldir.TestCaseWithControlDir):
 
46
 
 
47
    def __init__(self, transport_server, transport_readonly_server, formats):
 
48
        self._transport_server = transport_server
 
49
        self._transport_readonly_server = transport_readonly_server
 
50
        self.scenarios = self.formats_to_scenarios(formats)
 
51
 
 
52
    def formats_to_scenarios(self, formats):
 
53
        """Transform the input formats to a list of scenarios.
 
54
 
 
55
        :param formats: A list [workingtree_format].
 
56
        """
 
57
 
 
58
        result = []
 
59
        for workingtree_format in formats:
 
60
            result.append(self.create_scenario(workingtree_format))
 
61
        return result
 
62
 
 
63
    def create_scenario(self, workingtree_format):
 
64
        """Create a scenario for the specified converter
 
65
 
 
66
        :param workingtree_format: The particular workingtree format to test.
 
67
        :param bzrdir_format: The bzrdir format to test.
 
68
        :return: a (name, options) tuple, where options is a dict of values
 
69
            to be used as members of the TestCase.
 
70
        """
 
71
        scenario_options = {
 
72
            "transport_server": self._transport_server,
 
73
            "transport_readonly_server": self._transport_readonly_server,
 
74
            "bzrdir_format": workingtree_format._matchingbzrdir,
 
75
            "workingtree_format": workingtree_format,
 
76
            }
 
77
        return workingtree_format.__class__.__name__, scenario_options
 
78
 
 
79
 
 
80
class TestCaseWithWorkingTree(TestCaseWithBzrDir):
89
81
 
90
82
    def make_branch_and_tree(self, relpath, format=None):
91
83
        made_control = self.make_bzrdir(relpath, format=format)
92
84
        made_control.create_repository()
93
 
        b = made_control.create_branch()
94
 
        if getattr(self, 'repo_is_remote', False):
95
 
            # If the repo is remote, then we just create a local lightweight
96
 
            # checkout
97
 
            # XXX: This duplicates a lot of Branch.create_checkout, but we know
98
 
            #      we want a) lightweight, and b) a specific WT format. We also
99
 
            #      know that nothing should already exist, etc.
100
 
            t = transport.get_transport(relpath)
101
 
            t.ensure_base()
102
 
            bzrdir_format = self.workingtree_format.get_controldir_for_branch()
103
 
            wt_dir = bzrdir_format.initialize_on_transport(t)
104
 
            branch_ref = wt_dir.set_branch_reference(b)
105
 
            wt = wt_dir.create_workingtree(None, from_branch=branch_ref)
106
 
        else:
107
 
            wt = self.workingtree_format.initialize(made_control)
108
 
        return wt
109
 
 
110
 
    def make_branch_builder(self, relpath, format=None):
111
 
        if format is None:
112
 
            format = self.workingtree_format.get_controldir_for_branch()
113
 
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath),
114
 
                                              format=format)
115
 
        return builder
116
 
 
117
 
 
118
 
def load_tests(standard_tests, module, loader):
119
 
    test_names = [
120
 
        'add_reference',
121
 
        'add',
122
 
        'annotate_iter',
123
 
        'basis_inventory',
124
 
        'basis_tree',
125
 
        'break_lock',
126
 
        'changes_from',
127
 
        'check',
128
 
        'check_state',
129
 
        'content_filters',
130
 
        'commit',
131
 
        'eol_conversion',
132
 
        'executable',
133
 
        'flush',
134
 
        'get_file_mtime',
135
 
        'get_parent_ids',
136
 
        'inv',
137
 
        'is_control_filename',
138
 
        'is_ignored',
139
 
        'locking',
140
 
        'merge_from_branch',
141
 
        'mkdir',
142
 
        'move',
143
 
        'nested_specifics',
144
 
        'parents',
145
 
        'paths2ids',
146
 
        'pull',
147
 
        'put_file',
148
 
        'readonly',
149
 
        'read_working_inventory',
150
 
        'remove',
151
 
        'rename_one',
152
 
        'revision_tree',
153
 
        'set_root_id',
154
 
        'smart_add',
155
 
        'symlinks',
156
 
        'uncommit',
157
 
        'unversion',
158
 
        'views',
159
 
        'walkdirs',
160
 
        'workingtree',
 
85
        made_control.create_branch()
 
86
        return self.workingtree_format.initialize(made_control)
 
87
 
 
88
 
 
89
def load_tests(basic_tests, module, loader):
 
90
    result = loader.suiteClass()
 
91
    # add the tests for this module
 
92
    result.addTests(basic_tests)
 
93
 
 
94
    test_workingtree_implementations = [
 
95
        'bzrlib.tests.workingtree_implementations.test_add_reference',
 
96
        'bzrlib.tests.workingtree_implementations.test_add',
 
97
        'bzrlib.tests.workingtree_implementations.test_basis_inventory',
 
98
        'bzrlib.tests.workingtree_implementations.test_basis_tree',
 
99
        'bzrlib.tests.workingtree_implementations.test_break_lock',
 
100
        'bzrlib.tests.workingtree_implementations.test_changes_from',
 
101
        'bzrlib.tests.workingtree_implementations.test_commit',
 
102
        'bzrlib.tests.workingtree_implementations.test_executable',
 
103
        'bzrlib.tests.workingtree_implementations.test_flush',
 
104
        'bzrlib.tests.workingtree_implementations.test_get_file_mtime',
 
105
        'bzrlib.tests.workingtree_implementations.test_get_parent_ids',
 
106
        'bzrlib.tests.workingtree_implementations.test_inv',
 
107
        'bzrlib.tests.workingtree_implementations.test_is_control_filename',
 
108
        'bzrlib.tests.workingtree_implementations.test_is_ignored',
 
109
        'bzrlib.tests.workingtree_implementations.test_locking',
 
110
        'bzrlib.tests.workingtree_implementations.test_merge_from_branch',
 
111
        'bzrlib.tests.workingtree_implementations.test_mkdir',
 
112
        'bzrlib.tests.workingtree_implementations.test_move',
 
113
        'bzrlib.tests.workingtree_implementations.test_nested_specifics',
 
114
        'bzrlib.tests.workingtree_implementations.test_parents',
 
115
        'bzrlib.tests.workingtree_implementations.test_paths2ids',
 
116
        'bzrlib.tests.workingtree_implementations.test_pull',
 
117
        'bzrlib.tests.workingtree_implementations.test_put_file',
 
118
        'bzrlib.tests.workingtree_implementations.test_readonly',
 
119
        'bzrlib.tests.workingtree_implementations.test_read_working_inventory',
 
120
        'bzrlib.tests.workingtree_implementations.test_remove',
 
121
        'bzrlib.tests.workingtree_implementations.test_rename_one',
 
122
        'bzrlib.tests.workingtree_implementations.test_revision_tree',
 
123
        'bzrlib.tests.workingtree_implementations.test_set_root_id',
 
124
        'bzrlib.tests.workingtree_implementations.test_smart_add',
 
125
        'bzrlib.tests.workingtree_implementations.test_uncommit',
 
126
        'bzrlib.tests.workingtree_implementations.test_unversion',
 
127
        'bzrlib.tests.workingtree_implementations.test_walkdirs',
 
128
        'bzrlib.tests.workingtree_implementations.test_workingtree',
161
129
        ]
162
 
    test_workingtree_implementations = [
163
 
        'bzrlib.tests.per_workingtree.test_' + name for
164
 
        name in test_names]
165
130
 
166
 
    scenarios = wt_scenarios()
 
131
    adapter = WorkingTreeTestProviderAdapter(
 
132
        default_transport,
 
133
        # None here will cause a readonly decorator to be created
 
134
        # by the TestCaseWithTransport.get_readonly_transport method.
 
135
        None,
 
136
        WorkingTreeFormat._formats.values() + _legacy_formats)
167
137
 
168
138
    # add the tests for the sub modules
169
 
    return tests.multiply_tests(
170
 
        loader.loadTestsFromModuleNames(test_workingtree_implementations),
171
 
        scenarios, standard_tests)
172
 
 
173
 
 
174
 
class TestWtScenarios(tests.TestCase):
175
 
 
176
 
    def test_protect_wt_scenarios(self):
177
 
        # Just make sure we don't accidentally delete the helper again
178
 
        scenarios = wt_scenarios()
 
139
    adapt_modules(test_workingtree_implementations, adapter, loader, result)
 
140
    return result