/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/per_branch/__init__.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
3
#          and others
4
4
#
14
14
#
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
 
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 
24
 
rather than in tests/branch_implementations/*.py.
 
23
Specific tests for individual formats are in the tests/test_branch file
 
24
rather than in tests/per_branch/*.py.
25
25
"""
26
26
 
27
27
from bzrlib import (
32
32
                           _legacy_formats,
33
33
                           )
34
34
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
35
 
from bzrlib.smart.server import (
36
 
    ReadonlySmartTCPServer_for_testing,
37
 
    ReadonlySmartTCPServer_for_testing_v2_only,
38
 
    SmartTCPServer_for_testing,
39
 
    SmartTCPServer_for_testing_v2_only,
40
 
    )
41
 
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
42
 
from bzrlib.transport.memory import MemoryServer
43
 
 
44
 
 
45
 
class BranchTestProviderAdapter(tests.TestScenarioApplier):
46
 
    """A tool to generate a suite testing multiple branch formats at once.
47
 
 
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.
 
35
from bzrlib.tests import test_server
 
36
from bzrlib.tests.per_bzrdir.test_bzrdir import TestCaseWithBzrDir
 
37
from bzrlib.transport import memory
 
38
 
 
39
 
 
40
def make_scenarios(transport_server, transport_readonly_server,
 
41
    formats, vfs_transport_factory=None, name_suffix=''):
 
42
    """Transform the input formats to a list of scenarios.
 
43
 
 
44
    :param formats: A list of (branch_format, bzrdir_format).
52
45
    """
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
 
46
    result = []
 
47
    for branch_format, bzrdir_format in formats:
 
48
        # some branches don't have separate format objects.
 
49
        # so we have a conditional here to handle them.
 
50
        scenario_name = getattr(branch_format, '__name__',
 
51
            branch_format.__class__.__name__)
 
52
        scenario_name += name_suffix
 
53
        scenario = (scenario_name, {
 
54
            "transport_server":transport_server,
 
55
            "transport_readonly_server":transport_readonly_server,
 
56
            "bzrdir_format":bzrdir_format,
 
57
            "branch_format":branch_format,
 
58
                })
 
59
        result.append(scenario)
 
60
    return result
81
61
 
82
62
 
83
63
class TestCaseWithBranch(TestCaseWithBzrDir):
84
 
    """This helper will be adapted for each branch_implementation test."""
 
64
    """This helper will be parameterised in each per_branch test."""
85
65
 
86
66
    def setUp(self):
87
67
        super(TestCaseWithBranch, self).setUp()
93
73
        return self.branch
94
74
 
95
75
    def make_branch(self, relpath, format=None):
96
 
        repo = self.make_repository(relpath, format=format)
 
76
        if format is not None:
 
77
            return TestCaseWithBzrDir.make_branch(self, relpath, format)
 
78
        repo = self.make_repository(relpath)
97
79
        # fixme RBC 20060210 this isnt necessarily a fixable thing,
98
80
        # Skipped is the wrong exception to raise.
99
81
        try:
101
83
        except errors.UninitializableFormat:
102
84
            raise tests.TestSkipped('Uninitializable branch format')
103
85
 
 
86
    def make_branch_builder(self, relpath, format=None):
 
87
        if format is None:
 
88
            format = self.branch_format._matchingbzrdir
 
89
        return super(TestCaseWithBranch, self).make_branch_builder(
 
90
            relpath, format=format)
 
91
 
104
92
    def make_repository(self, relpath, shared=False, format=None):
105
93
        made_control = self.make_bzrdir(relpath, format=format)
106
94
        return made_control.create_repository(shared=shared)
139
127
        return tree
140
128
 
141
129
 
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
 
 
147
 
    test_branch_implementations = [
148
 
        'bzrlib.tests.branch_implementations.test_bound_sftp',
149
 
        'bzrlib.tests.branch_implementations.test_branch',
150
 
        'bzrlib.tests.branch_implementations.test_break_lock',
151
 
        'bzrlib.tests.branch_implementations.test_check',
152
 
        'bzrlib.tests.branch_implementations.test_create_checkout',
153
 
        'bzrlib.tests.branch_implementations.test_commit',
154
 
        'bzrlib.tests.branch_implementations.test_get_revision_id_to_revno_map',
155
 
        'bzrlib.tests.branch_implementations.test_hooks',
156
 
        'bzrlib.tests.branch_implementations.test_http',
157
 
        'bzrlib.tests.branch_implementations.test_last_revision_info',
158
 
        'bzrlib.tests.branch_implementations.test_locking',
159
 
        'bzrlib.tests.branch_implementations.test_parent',
160
 
        'bzrlib.tests.branch_implementations.test_permissions',
161
 
        'bzrlib.tests.branch_implementations.test_pull',
162
 
        'bzrlib.tests.branch_implementations.test_push',
163
 
        'bzrlib.tests.branch_implementations.test_reconcile',
164
 
        'bzrlib.tests.branch_implementations.test_revision_history',
165
 
        'bzrlib.tests.branch_implementations.test_revision_id_to_revno',
166
 
        'bzrlib.tests.branch_implementations.test_sprout',
167
 
        'bzrlib.tests.branch_implementations.test_stacking',
168
 
        'bzrlib.tests.branch_implementations.test_tags',
169
 
        'bzrlib.tests.branch_implementations.test_uncommit',
170
 
        'bzrlib.tests.branch_implementations.test_update',
171
 
        ]
 
130
def branch_scenarios():
 
131
    """ """
172
132
    # Generate a list of branch formats and their associated bzrdir formats to
173
133
    # use.
174
 
    combinations = [(format, format._matchingbzrdir) for format in 
 
134
    combinations = [(format, format._matchingbzrdir) for format in
175
135
         BranchFormat._formats.values() + _legacy_formats]
176
 
    adapter = BranchTestProviderAdapter(
 
136
    scenarios = make_scenarios(
177
137
        # None here will cause the default vfs transport server to be used.
178
138
        None,
179
139
        # None here will cause a readonly decorator to be created
180
140
        # by the TestCaseWithTransport.get_readonly_transport method.
181
141
        None,
182
142
        combinations)
183
 
    # add the tests for the sub modules
184
 
    tests.adapt_modules(test_branch_implementations, adapter, loader, result)
185
 
 
186
143
    # 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
 
 
 
144
    remote_branch_format = RemoteBranchFormat()
 
145
    scenarios.extend(make_scenarios(
 
146
        test_server.SmartTCPServer_for_testing,
 
147
        test_server.ReadonlySmartTCPServer_for_testing,
 
148
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
 
149
        memory.MemoryServer,
 
150
        name_suffix='-default'))
198
151
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
199
152
    # 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
 
153
    scenarios.extend(make_scenarios(
 
154
        test_server.SmartTCPServer_for_testing_v2_only,
 
155
        test_server.ReadonlySmartTCPServer_for_testing_v2_only,
 
156
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
 
157
        memory.MemoryServer,
 
158
        name_suffix='-v2'))
 
159
    return scenarios
 
160
 
 
161
 
 
162
def load_tests(standard_tests, module, loader):
 
163
    per_branch_mod_names = [
 
164
        'bound_sftp',
 
165
        'branch',
 
166
        'break_lock',
 
167
        'check',
 
168
        'create_checkout',
 
169
        'create_clone',
 
170
        'commit',
 
171
        'dotted_revno_to_revision_id',
 
172
        'get_revision_id_to_revno_map',
 
173
        'hooks',
 
174
        'http',
 
175
        'iter_merge_sorted_revisions',
 
176
        'last_revision_info',
 
177
        'locking',
 
178
        'parent',
 
179
        'permissions',
 
180
        'pull',
 
181
        'push',
 
182
        'reconcile',
 
183
        'revision_history',
 
184
        'revision_id_to_dotted_revno',
 
185
        'revision_id_to_revno',
 
186
        'sprout',
 
187
        'stacking',
 
188
        'tags',
 
189
        'uncommit',
 
190
        'update',
 
191
        ]
 
192
    sub_tests = loader.loadTestsFromModuleNames(
 
193
        ['bzrlib.tests.per_branch.test_' + name
 
194
         for name in per_branch_mod_names])
 
195
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)