62
63
class TestDefaultFormat(TestCaseWithTransport):
64
65
def test_get_set_default_format(self):
65
old_format = workingtree.WorkingTreeFormat.get_default_format()
66
old_format = workingtree.format_registry.get_default()
67
68
self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
68
workingtree.WorkingTreeFormat.set_default_format(SampleTreeFormat())
69
workingtree.format_registry.set_default(SampleTreeFormat())
70
71
# the default branch format is used by the meta dir format
71
72
# which is not the default bzrdir format at this point
185
186
format.initialize(dir)
186
187
# register a format for it.
187
workingtree.WorkingTreeFormat.register_format(format)
188
self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
188
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
189
workingtree.WorkingTreeFormat.register_format, format)
190
self.assertTrue(format in
191
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
192
workingtree.WorkingTreeFormat.get_formats))
189
193
# which branch.Open will refuse (not supported)
190
194
self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
191
195
# but open_downlevel will work
192
196
self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
193
197
# unregister the format
194
workingtree.WorkingTreeFormat.unregister_format(format)
195
self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
197
def test_register_unregister_extra_format(self):
198
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
199
workingtree.WorkingTreeFormat.unregister_format, format)
200
self.assertFalse(format in
201
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
202
workingtree.WorkingTreeFormat.get_formats))
205
class TestWorkingTreeFormatRegistry(TestCase):
208
super(TestWorkingTreeFormatRegistry, self).setUp()
209
self.registry = workingtree.WorkingTreeFormatRegistry()
211
def test_register_unregister_format(self):
212
format = SampleTreeFormat()
213
self.registry.register(format)
214
self.assertEquals(format, self.registry.get("Sample tree format."))
215
self.registry.remove(format)
216
self.assertRaises(KeyError, self.registry.get, "Sample tree format.")
218
def test_get_all(self):
219
format = SampleTreeFormat()
220
self.assertEquals([], self.registry._get_all())
221
self.registry.register(format)
222
self.assertEquals([format], self.registry._get_all())
224
def test_register_extra(self):
198
225
format = SampleExtraTreeFormat()
199
workingtree.WorkingTreeFormat.register_extra_format(format)
200
self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
201
workingtree.WorkingTreeFormat.unregister_extra_format(format)
202
self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
226
self.assertEquals([], self.registry._get_all())
227
self.registry.register_extra(format)
228
self.assertEquals([format], self.registry._get_all())
230
def test_register_extra_lazy(self):
231
self.assertEquals([], self.registry._get_all())
232
self.registry.register_extra_lazy("bzrlib.tests.test_workingtree",
233
"SampleExtraTreeFormat")
234
formats = self.registry._get_all()
235
self.assertEquals(1, len(formats))
236
self.assertIsInstance(formats[0], SampleExtraTreeFormat)
205
239
class TestWorkingTreeFormat3(TestCaseWithTransport):