69
69
def test_get_set_default_format(self):
70
70
old_default = bzrdir.format_registry.get('default')
71
71
private_default = old_default().repository_format.__class__
72
old_format = repository.RepositoryFormat.get_default_format()
72
old_format = repository.format_registry.get_default()
73
73
self.assertTrue(isinstance(old_format, private_default))
74
74
def make_sample_bzrdir():
75
75
my_bzrdir = bzrdir.BzrDirMetaFormat1()
149
158
def test_register_unregister_format(self):
159
# Test deprecated format registration functions
150
160
format = SampleRepositoryFormat()
151
161
# make a control dir
152
162
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
154
164
format.initialize(dir)
155
165
# register a format for it.
156
repository.RepositoryFormat.register_format(format)
166
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
167
repository.RepositoryFormat.register_format, format)
157
168
# which repository.Open will refuse (not supported)
158
self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url())
169
self.assertRaises(UnsupportedFormatError, repository.Repository.open,
159
171
# but open(unsupported) will work
160
172
self.assertEqual(format.open(dir), "opened repository.")
161
173
# unregister the format
162
repository.RepositoryFormat.unregister_format(format)
174
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
175
repository.RepositoryFormat.unregister_format, format)
178
class TestRepositoryFormatRegistry(TestCase):
181
super(TestRepositoryFormatRegistry, self).setUp()
182
self.registry = repository.RepositoryFormatRegistry()
184
def test_register_unregister_format(self):
185
format = SampleRepositoryFormat()
186
self.registry.register(format)
187
self.assertEquals(format, self.registry.get("Sample .bzr repository format."))
188
self.registry.remove(format)
189
self.assertRaises(KeyError, self.registry.get, "Sample .bzr repository format.")
191
def test_get_all(self):
192
format = SampleRepositoryFormat()
193
self.assertEquals([], self.registry._get_all())
194
self.registry.register(format)
195
self.assertEquals([format], self.registry._get_all())
197
def test_register_extra(self):
198
format = SampleExtraRepositoryFormat()
199
self.assertEquals([], self.registry._get_all())
200
self.registry.register_extra(format)
201
self.assertEquals([format], self.registry._get_all())
203
def test_register_extra_lazy(self):
204
self.assertEquals([], self.registry._get_all())
205
self.registry.register_extra_lazy("bzrlib.tests.test_repository",
206
"SampleExtraRepositoryFormat")
207
formats = self.registry._get_all()
208
self.assertEquals(1, len(formats))
209
self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
165
212
class TestFormat6(TestCaseWithTransport):