/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2009-03-13 02:25:46 UTC
  • mfrom: (4133 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4183.
  • Revision ID: robertc@robertcollins.net-20090313022546-e7de5zsdkbay5okf
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
"""Branch implementation tests for bzr.
21
21
 
22
22
These test the conformance of all the branch variations to the expected API.
23
 
Specific tests for individual formats are in the tests/test_branch file 
 
23
Specific tests for individual formats are in the tests/test_branch file
24
24
rather than in tests/branch_implementations/*.py.
25
25
"""
26
26
 
42
42
from bzrlib.transport.memory import MemoryServer
43
43
 
44
44
 
45
 
class BranchTestProviderAdapter(tests.TestScenarioApplier):
46
 
    """A tool to generate a suite testing multiple branch formats at once.
 
45
def make_scenarios(transport_server, transport_readonly_server,
 
46
    formats, vfs_transport_factory=None, name_suffix=''):
 
47
    """Transform the input formats to a list of scenarios.
47
48
 
48
 
    This is done by copying the test once for each transport and injecting
49
 
    the transport_server, transport_readonly_server, and branch_format
50
 
    classes into each copy. Each copy is also given a new id() to make it
51
 
    easy to identify.
 
49
    :param formats: A list of (branch_format, bzrdir_format).
52
50
    """
53
 
 
54
 
    def __init__(self, transport_server, transport_readonly_server, formats,
55
 
        vfs_transport_factory=None, name_suffix=''):
56
 
        self._transport_server = transport_server
57
 
        self._transport_readonly_server = transport_readonly_server
58
 
        self._name_suffix = name_suffix
59
 
        self.scenarios = self.formats_to_scenarios(formats)
60
 
    
61
 
    def formats_to_scenarios(self, formats):
62
 
        """Transform the input formats to a list of scenarios.
63
 
 
64
 
        :param formats: A list of (branch_format, bzrdir_format).
65
 
        """
66
 
        result = []
67
 
        for branch_format, bzrdir_format in formats:
68
 
            # some branches don't have separate format objects.
69
 
            # so we have a conditional here to handle them.
70
 
            scenario_name = getattr(branch_format, '__name__',
71
 
                branch_format.__class__.__name__)
72
 
            scenario_name += self._name_suffix
73
 
            scenario = (scenario_name, {
74
 
                "transport_server":self._transport_server,
75
 
                "transport_readonly_server":self._transport_readonly_server,
76
 
                "bzrdir_format":bzrdir_format,
77
 
                "branch_format":branch_format,
78
 
                    })
79
 
            result.append(scenario)
80
 
        return result
 
51
    result = []
 
52
    for branch_format, bzrdir_format in formats:
 
53
        # some branches don't have separate format objects.
 
54
        # so we have a conditional here to handle them.
 
55
        scenario_name = getattr(branch_format, '__name__',
 
56
            branch_format.__class__.__name__)
 
57
        scenario_name += name_suffix
 
58
        scenario = (scenario_name, {
 
59
            "transport_server":transport_server,
 
60
            "transport_readonly_server":transport_readonly_server,
 
61
            "bzrdir_format":bzrdir_format,
 
62
            "branch_format":branch_format,
 
63
                })
 
64
        result.append(scenario)
 
65
    return result
81
66
 
82
67
 
83
68
class TestCaseWithBranch(TestCaseWithBzrDir):
84
 
    """This helper will be adapted for each branch_implementation test."""
 
69
    """This helper will be parameterised in each branch_implementation test."""
85
70
 
86
71
    def setUp(self):
87
72
        super(TestCaseWithBranch, self).setUp()
101
86
        except errors.UninitializableFormat:
102
87
            raise tests.TestSkipped('Uninitializable branch format')
103
88
 
 
89
    def make_branch_builder(self, relpath, format=None):
 
90
        if format is None:
 
91
            format = self.branch_format._matchingbzrdir
 
92
        return super(TestCaseWithBranch, self).make_branch_builder(
 
93
            relpath, format=format)
 
94
 
104
95
    def make_repository(self, relpath, shared=False, format=None):
105
96
        made_control = self.make_bzrdir(relpath, format=format)
106
97
        return made_control.create_repository(shared=shared)
139
130
        return tree
140
131
 
141
132
 
142
 
def load_tests(basic_tests, module, loader):
143
 
    result = loader.suiteClass()
144
 
    # add the tests for this module
145
 
    result.addTests(basic_tests)
146
 
 
 
133
def branch_scenarios():
 
134
    """ """
 
135
    # Generate a list of branch formats and their associated bzrdir formats to
 
136
    # use.
 
137
    combinations = [(format, format._matchingbzrdir) for format in
 
138
         BranchFormat._formats.values() + _legacy_formats]
 
139
    scenarios = make_scenarios(
 
140
        # None here will cause the default vfs transport server to be used.
 
141
        None,
 
142
        # None here will cause a readonly decorator to be created
 
143
        # by the TestCaseWithTransport.get_readonly_transport method.
 
144
        None,
 
145
        combinations)
 
146
    # Add RemoteBranch tests, which need a special server.
 
147
    remote_branch_format = RemoteBranchFormat()
 
148
    scenarios.extend(make_scenarios(
 
149
        SmartTCPServer_for_testing,
 
150
        ReadonlySmartTCPServer_for_testing,
 
151
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
 
152
        MemoryServer,
 
153
        name_suffix='-default'))
 
154
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
 
155
    # server.
 
156
    scenarios.extend(make_scenarios(
 
157
        SmartTCPServer_for_testing_v2_only,
 
158
        ReadonlySmartTCPServer_for_testing_v2_only,
 
159
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
 
160
        MemoryServer,
 
161
        name_suffix='-v2'))
 
162
    return scenarios
 
163
 
 
164
 
 
165
def load_tests(standard_tests, module, loader):
147
166
    test_branch_implementations = [
148
167
        'bzrlib.tests.branch_implementations.test_bound_sftp',
149
168
        'bzrlib.tests.branch_implementations.test_branch',
150
169
        'bzrlib.tests.branch_implementations.test_break_lock',
151
170
        'bzrlib.tests.branch_implementations.test_check',
152
171
        'bzrlib.tests.branch_implementations.test_create_checkout',
 
172
        'bzrlib.tests.branch_implementations.test_create_clone',
153
173
        'bzrlib.tests.branch_implementations.test_commit',
 
174
        'bzrlib.tests.branch_implementations.test_dotted_revno_to_revision_id',
154
175
        'bzrlib.tests.branch_implementations.test_get_revision_id_to_revno_map',
155
176
        'bzrlib.tests.branch_implementations.test_hooks',
156
177
        'bzrlib.tests.branch_implementations.test_http',
 
178
        'bzrlib.tests.branch_implementations.test_iter_merge_sorted_revisions',
157
179
        'bzrlib.tests.branch_implementations.test_last_revision_info',
158
180
        'bzrlib.tests.branch_implementations.test_locking',
159
181
        'bzrlib.tests.branch_implementations.test_parent',
162
184
        'bzrlib.tests.branch_implementations.test_push',
163
185
        'bzrlib.tests.branch_implementations.test_reconcile',
164
186
        'bzrlib.tests.branch_implementations.test_revision_history',
 
187
        'bzrlib.tests.branch_implementations.test_revision_id_to_dotted_revno',
165
188
        'bzrlib.tests.branch_implementations.test_revision_id_to_revno',
166
189
        'bzrlib.tests.branch_implementations.test_sprout',
167
190
        'bzrlib.tests.branch_implementations.test_stacking',
169
192
        'bzrlib.tests.branch_implementations.test_uncommit',
170
193
        'bzrlib.tests.branch_implementations.test_update',
171
194
        ]
172
 
    # Generate a list of branch formats and their associated bzrdir formats to
173
 
    # use.
174
 
    combinations = [(format, format._matchingbzrdir) for format in 
175
 
         BranchFormat._formats.values() + _legacy_formats]
176
 
    adapter = BranchTestProviderAdapter(
177
 
        # None here will cause the default vfs transport server to be used.
178
 
        None,
179
 
        # None here will cause a readonly decorator to be created
180
 
        # by the TestCaseWithTransport.get_readonly_transport method.
181
 
        None,
182
 
        combinations)
183
 
    # add the tests for the sub modules
184
 
    tests.adapt_modules(test_branch_implementations, adapter, loader, result)
185
 
 
186
 
    # Add RemoteBranch tests, which need a special server.
187
 
    adapt_to_smart_server = BranchTestProviderAdapter(
188
 
        SmartTCPServer_for_testing,
189
 
        ReadonlySmartTCPServer_for_testing,
190
 
        [(RemoteBranchFormat(), RemoteBzrDirFormat())],
191
 
        MemoryServer,
192
 
        name_suffix='-default')
193
 
    tests.adapt_modules(test_branch_implementations,
194
 
                        adapt_to_smart_server,
195
 
                        loader,
196
 
                        result)
197
 
 
198
 
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
199
 
    # server.
200
 
    adapt_to_smart_server = BranchTestProviderAdapter(
201
 
        SmartTCPServer_for_testing_v2_only,
202
 
        ReadonlySmartTCPServer_for_testing_v2_only,
203
 
        [(RemoteBranchFormat(), RemoteBzrDirFormat())],
204
 
        MemoryServer,
205
 
        name_suffix='-v2')
206
 
    tests.adapt_modules(test_branch_implementations,
207
 
                        adapt_to_smart_server,
208
 
                        loader,
209
 
                        result)
210
 
 
211
 
    return result
 
195
    sub_tests = loader.loadTestsFromModuleNames(test_branch_implementations)
 
196
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)