/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: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 (
38
38
    SmartTCPServer_for_testing,
39
39
    SmartTCPServer_for_testing_v2_only,
40
40
    )
41
 
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
41
from bzrlib.tests.per_bzrdir.test_bzrdir import TestCaseWithBzrDir
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()
93
78
        return self.branch
94
79
 
95
80
    def make_branch(self, relpath, format=None):
96
 
        repo = self.make_repository(relpath, format=format)
 
81
        if format is not None:
 
82
            return TestCaseWithBzrDir.make_branch(self, relpath, format)
 
83
        repo = self.make_repository(relpath)
97
84
        # fixme RBC 20060210 this isnt necessarily a fixable thing,
98
85
        # Skipped is the wrong exception to raise.
99
86
        try:
145
132
        return tree
146
133
 
147
134
 
148
 
def load_tests(basic_tests, module, loader):
149
 
    result = loader.suiteClass()
150
 
    # add the tests for this module
151
 
    result.addTests(basic_tests)
152
 
 
153
 
    test_branch_implementations = [
154
 
        'bzrlib.tests.branch_implementations.test_bound_sftp',
155
 
        'bzrlib.tests.branch_implementations.test_branch',
156
 
        'bzrlib.tests.branch_implementations.test_break_lock',
157
 
        'bzrlib.tests.branch_implementations.test_check',
158
 
        'bzrlib.tests.branch_implementations.test_create_checkout',
159
 
        'bzrlib.tests.branch_implementations.test_commit',
160
 
        'bzrlib.tests.branch_implementations.test_dotted_revno_to_revision_id',
161
 
        'bzrlib.tests.branch_implementations.test_get_revision_id_to_revno_map',
162
 
        'bzrlib.tests.branch_implementations.test_hooks',
163
 
        'bzrlib.tests.branch_implementations.test_http',
164
 
        'bzrlib.tests.branch_implementations.test_iter_merge_sorted_revisions',
165
 
        'bzrlib.tests.branch_implementations.test_last_revision_info',
166
 
        'bzrlib.tests.branch_implementations.test_locking',
167
 
        'bzrlib.tests.branch_implementations.test_parent',
168
 
        'bzrlib.tests.branch_implementations.test_permissions',
169
 
        'bzrlib.tests.branch_implementations.test_pull',
170
 
        'bzrlib.tests.branch_implementations.test_push',
171
 
        'bzrlib.tests.branch_implementations.test_reconcile',
172
 
        'bzrlib.tests.branch_implementations.test_revision_history',
173
 
        'bzrlib.tests.branch_implementations.test_revision_id_to_dotted_revno',
174
 
        'bzrlib.tests.branch_implementations.test_revision_id_to_revno',
175
 
        'bzrlib.tests.branch_implementations.test_sprout',
176
 
        'bzrlib.tests.branch_implementations.test_stacking',
177
 
        'bzrlib.tests.branch_implementations.test_tags',
178
 
        'bzrlib.tests.branch_implementations.test_uncommit',
179
 
        'bzrlib.tests.branch_implementations.test_update',
180
 
        ]
 
135
def branch_scenarios():
 
136
    """ """
181
137
    # Generate a list of branch formats and their associated bzrdir formats to
182
138
    # use.
183
 
    combinations = [(format, format._matchingbzrdir) for format in 
 
139
    combinations = [(format, format._matchingbzrdir) for format in
184
140
         BranchFormat._formats.values() + _legacy_formats]
185
 
    adapter = BranchTestProviderAdapter(
 
141
    scenarios = make_scenarios(
186
142
        # None here will cause the default vfs transport server to be used.
187
143
        None,
188
144
        # None here will cause a readonly decorator to be created
189
145
        # by the TestCaseWithTransport.get_readonly_transport method.
190
146
        None,
191
147
        combinations)
192
 
    # add the tests for the sub modules
193
 
    tests.adapt_modules(test_branch_implementations, adapter, loader, result)
194
 
 
195
148
    # Add RemoteBranch tests, which need a special server.
196
149
    remote_branch_format = RemoteBranchFormat()
197
 
    adapt_to_smart_server = BranchTestProviderAdapter(
 
150
    scenarios.extend(make_scenarios(
198
151
        SmartTCPServer_for_testing,
199
152
        ReadonlySmartTCPServer_for_testing,
200
153
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
201
154
        MemoryServer,
202
 
        name_suffix='-default')
203
 
    tests.adapt_modules(test_branch_implementations,
204
 
                        adapt_to_smart_server,
205
 
                        loader,
206
 
                        result)
207
 
 
 
155
        name_suffix='-default'))
208
156
    # Also add tests for RemoteBranch with HPSS protocol v2 (i.e. bzr <1.6)
209
157
    # server.
210
 
    adapt_to_smart_server = BranchTestProviderAdapter(
 
158
    scenarios.extend(make_scenarios(
211
159
        SmartTCPServer_for_testing_v2_only,
212
160
        ReadonlySmartTCPServer_for_testing_v2_only,
213
161
        [(remote_branch_format, remote_branch_format._matchingbzrdir)],
214
162
        MemoryServer,
215
 
        name_suffix='-v2')
216
 
    tests.adapt_modules(test_branch_implementations,
217
 
                        adapt_to_smart_server,
218
 
                        loader,
219
 
                        result)
220
 
 
221
 
    return result
 
163
        name_suffix='-v2'))
 
164
    return scenarios
 
165
 
 
166
 
 
167
def load_tests(standard_tests, module, loader):
 
168
    per_branch_mod_names = [
 
169
        'bound_sftp',
 
170
        'branch',
 
171
        'break_lock',
 
172
        'check',
 
173
        'create_checkout',
 
174
        'create_clone',
 
175
        'commit',
 
176
        'dotted_revno_to_revision_id',
 
177
        'get_revision_id_to_revno_map',
 
178
        'hooks',
 
179
        'http',
 
180
        'iter_merge_sorted_revisions',
 
181
        'last_revision_info',
 
182
        'locking',
 
183
        'parent',
 
184
        'permissions',
 
185
        'pull',
 
186
        'push',
 
187
        'reconcile',
 
188
        'revision_history',
 
189
        'revision_id_to_dotted_revno',
 
190
        'revision_id_to_revno',
 
191
        'sprout',
 
192
        'stacking',
 
193
        'tags',
 
194
        'uncommit',
 
195
        'update',
 
196
        ]
 
197
    sub_tests = loader.loadTestsFromModuleNames(
 
198
        ['bzrlib.tests.per_branch.test_' + name
 
199
         for name in per_branch_mod_names])
 
200
    return tests.multiply_tests(sub_tests, branch_scenarios(), standard_tests)