~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-03-11 20:21:17 UTC
  • mfrom: (5712.3.23 lazy-bzrdir)
  • Revision ID: pqm@pqm.ubuntu.com-20110311202117-tvicdu07o2x7jh8b
(jelmer) Add Prober.known_formats() in favour of
 BzrDirFormat.register_format() and ControlDirFormat.register_format().
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
272
272
    def test_find_format(self):
273
273
        # is the right format object found for a branch?
274
274
        # create a branch with a few known format objects.
275
 
        bzrdir.BzrDirFormat.register_format(BzrDirFormatTest1())
276
 
        self.addCleanup(bzrdir.BzrDirFormat.unregister_format, BzrDirFormatTest1())
277
 
        bzrdir.BzrDirFormat.register_format(BzrDirFormatTest2())
278
 
        self.addCleanup(bzrdir.BzrDirFormat.unregister_format, BzrDirFormatTest2())
 
275
        bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
 
276
            BzrDirFormatTest1())
 
277
        self.addCleanup(bzrdir.BzrProber.formats.remove,
 
278
            BzrDirFormatTest1.get_format_string())
 
279
        bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
 
280
            BzrDirFormatTest2())
 
281
        self.addCleanup(bzrdir.BzrProber.formats.remove,
 
282
            BzrDirFormatTest2.get_format_string())
279
283
        t = self.get_transport()
280
284
        self.build_tree(["foo/", "bar/"], transport=t)
281
285
        def check_format(format, url):
305
309
        # make a bzrdir
306
310
        format.initialize(url)
307
311
        # register a format for it.
308
 
        bzrdir.BzrDirFormat.register_format(format)
 
312
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
309
313
        # which bzrdir.Open will refuse (not supported)
310
314
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
311
315
        # which bzrdir.open_containing will refuse (not supported)
314
318
        t = _mod_transport.get_transport(url)
315
319
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
316
320
        # unregister the format
317
 
        bzrdir.BzrDirFormat.unregister_format(format)
 
321
        bzrdir.BzrProber.formats.remove(format.get_format_string())
318
322
        # now open_downlevel should fail too.
319
323
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
320
324
 
1071
1075
            bzrdir.BzrDirFormat.get_default_format()))
1072
1076
 
1073
1077
 
1074
 
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1075
 
    """A non .bzr based control directory."""
1076
 
 
1077
 
    def __init__(self, transport, format):
1078
 
        self._format = format
1079
 
        self.root_transport = transport
1080
 
        self.transport = transport.clone('.not')
1081
 
 
1082
 
 
1083
 
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
1084
 
    """A test class representing any non-.bzr based disk format."""
1085
 
 
1086
 
    def initialize_on_transport(self, transport):
1087
 
        """Initialize a new .not dir in the base directory of a Transport."""
1088
 
        transport.mkdir('.not')
1089
 
        return self.open(transport)
1090
 
 
1091
 
    def open(self, transport):
1092
 
        """Open this directory."""
1093
 
        return NotBzrDir(transport, self)
1094
 
 
1095
 
    @classmethod
1096
 
    def _known_formats(self):
1097
 
        return set([NotBzrDirFormat()])
1098
 
 
1099
 
 
1100
 
class NotBzrDirProber(controldir.Prober):
1101
 
 
1102
 
    def probe_transport(self, transport):
1103
 
        """Our format is present if the transport ends in '.not/'."""
1104
 
        if transport.has('.not'):
1105
 
            return NotBzrDirFormat()
1106
 
 
1107
 
 
1108
 
class TestNotBzrDir(TestCaseWithTransport):
1109
 
    """Tests for using the bzrdir api with a non .bzr based disk format.
1110
 
 
1111
 
    If/when one of these is in the core, we can let the implementation tests
1112
 
    verify this works.
1113
 
    """
1114
 
 
1115
 
    def test_create_and_find_format(self):
1116
 
        # create a .notbzr dir
1117
 
        format = NotBzrDirFormat()
1118
 
        dir = format.initialize(self.get_url())
1119
 
        self.assertIsInstance(dir, NotBzrDir)
1120
 
        # now probe for it.
1121
 
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1122
 
        try:
1123
 
            found = bzrlib.bzrdir.BzrDirFormat.find_format(self.get_transport())
1124
 
            self.assertIsInstance(found, NotBzrDirFormat)
1125
 
        finally:
1126
 
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1127
 
 
1128
 
    def test_included_in_known_formats(self):
1129
 
        not_format = NotBzrDirFormat()
1130
 
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
1131
 
        try:
1132
 
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1133
 
            for format in formats:
1134
 
                if isinstance(format, NotBzrDirFormat):
1135
 
                    return
1136
 
            self.fail("No NotBzrDirFormat in %s" % formats)
1137
 
        finally:
1138
 
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1139
 
 
1140
 
 
1141
1078
class NonLocalTests(TestCaseWithTransport):
1142
1079
    """Tests for bzrdir static behaviour on non local paths."""
1143
1080