~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-02-04 18:06:54 UTC
  • mfrom: (5642.2.2 extra-branch-formats)
  • Revision ID: pqm@pqm.ubuntu.com-20110204180654-fmof6mad6s3aeam1
(jelmer) Allow the registration of "extra" branch formats in the branch
 format registry. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
        return "opened supported branch."
148
148
 
149
149
 
 
150
class SampleExtraBranchFormat(_mod_branch.BranchFormat):
 
151
    """A sample format that is not usable in a metadir."""
 
152
 
 
153
    def get_format_string(self):
 
154
        # This format is not usable in a metadir.
 
155
        return None
 
156
 
 
157
    def network_name(self):
 
158
        # Network name always has to be provided.
 
159
        return "extra"
 
160
 
 
161
    def initialize(self, a_bzrdir, name=None):
 
162
        raise NotImplementedError(self.initialize)
 
163
 
 
164
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
 
165
        raise NotImplementedError(self.open)
 
166
 
 
167
 
150
168
class TestBzrBranchFormat(tests.TestCaseWithTransport):
151
169
    """Tests for the BzrBranchFormat facility."""
152
170
 
163
181
            self.failUnless(isinstance(found_format, format.__class__))
164
182
        check_format(_mod_branch.BzrBranchFormat5(), "bar")
165
183
 
 
184
    def test_extra_format(self):
 
185
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
186
        SampleSupportedBranchFormat().initialize(dir)
 
187
        format = SampleExtraBranchFormat()
 
188
        _mod_branch.BranchFormat.register_extra_format(format)
 
189
        self.addCleanup(_mod_branch.BranchFormat.unregister_extra_format,
 
190
            format)
 
191
        self.assertTrue(format in _mod_branch.BranchFormat.get_formats())
 
192
        self.assertEquals(format,
 
193
            _mod_branch.network_format_registry.get("extra"))
 
194
 
166
195
    def test_find_format_factory(self):
167
196
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
168
197
        SampleSupportedBranchFormat().initialize(dir)