1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
66
67
class TestDefaultFormat(TestCase):
68
69
def test_get_set_default_format(self):
69
old_default = bzrdir.format_registry.get('default')
70
old_default = controldir.format_registry.get('default')
70
71
private_default = old_default().repository_format.__class__
71
72
old_format = repository.format_registry.get_default()
72
73
self.assertTrue(isinstance(old_format, private_default))
74
75
my_bzrdir = bzrdir.BzrDirMetaFormat1()
75
76
my_bzrdir.repository_format = SampleRepositoryFormat()
77
bzrdir.format_registry.remove('default')
78
bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
79
bzrdir.format_registry.set_default('sample')
78
controldir.format_registry.remove('default')
79
controldir.format_registry.register('sample', make_sample_bzrdir, '')
80
controldir.format_registry.set_default('sample')
80
81
# creating a repository should now create an instrumented dir.
82
83
# the default branch format is used by the meta dir format
85
86
result = dir.create_repository()
86
87
self.assertEqual(result, 'A bzr repository dir')
88
bzrdir.format_registry.remove('default')
89
bzrdir.format_registry.remove('sample')
90
bzrdir.format_registry.register('default', old_default, '')
89
controldir.format_registry.remove('default')
90
controldir.format_registry.remove('sample')
91
controldir.format_registry.register('default', old_default, '')
91
92
self.assertIsInstance(repository.format_registry.get_default(),
92
93
old_format.__class__)
169
170
tree.branch.repository.update_feature_flags({"name": "necessity"})
170
171
found_format = repository.RepositoryFormatMetaDir.find_format(tree.bzrdir)
171
172
self.assertIsInstance(found_format, repository.RepositoryFormatMetaDir)
172
self.assertEquals(found_format.features.get("name"), "necessity")
173
self.assertEqual(found_format.features.get("name"), "necessity")
173
174
self.assertRaises(errors.MissingFeature, found_format.check_support_status,
175
176
self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
177
178
repository.RepositoryFormatMetaDir.register_feature("name")
178
179
found_format.check_support_status(True)
180
def test_register_unregister_format(self):
181
# Test deprecated format registration functions
182
format = SampleRepositoryFormat()
184
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
186
format.initialize(dir)
187
# register a format for it.
188
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
189
repository.RepositoryFormat.register_format, format)
190
# which repository.Open will refuse (not supported)
191
self.assertRaises(UnsupportedFormatError, repository.Repository.open,
193
# but open(unsupported) will work
194
self.assertEqual(format.open(dir), "opened repository.")
195
# unregister the format
196
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
197
repository.RepositoryFormat.unregister_format, format)
200
182
class TestRepositoryFormatRegistry(TestCase):
206
188
def test_register_unregister_format(self):
207
189
format = SampleRepositoryFormat()
208
190
self.registry.register(format)
209
self.assertEquals(format, self.registry.get("Sample .bzr repository format."))
191
self.assertEqual(format, self.registry.get("Sample .bzr repository format."))
210
192
self.registry.remove(format)
211
193
self.assertRaises(KeyError, self.registry.get, "Sample .bzr repository format.")
213
195
def test_get_all(self):
214
196
format = SampleRepositoryFormat()
215
self.assertEquals([], self.registry._get_all())
197
self.assertEqual([], self.registry._get_all())
216
198
self.registry.register(format)
217
self.assertEquals([format], self.registry._get_all())
199
self.assertEqual([format], self.registry._get_all())
219
201
def test_register_extra(self):
220
202
format = SampleExtraRepositoryFormat()
221
self.assertEquals([], self.registry._get_all())
203
self.assertEqual([], self.registry._get_all())
222
204
self.registry.register_extra(format)
223
self.assertEquals([format], self.registry._get_all())
205
self.assertEqual([format], self.registry._get_all())
225
207
def test_register_extra_lazy(self):
226
self.assertEquals([], self.registry._get_all())
208
self.assertEqual([], self.registry._get_all())
227
209
self.registry.register_extra_lazy("bzrlib.tests.test_repository",
228
210
"SampleExtraRepositoryFormat")
229
211
formats = self.registry._get_all()
230
self.assertEquals(1, len(formats))
212
self.assertEqual(1, len(formats))
231
213
self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
236
218
def test_attribute__fetch_order(self):
237
219
"""Knits need topological data insertion."""
238
220
repo = self.make_repository('.',
239
format=bzrdir.format_registry.get('knit')())
221
format=controldir.format_registry.get('knit')())
240
222
self.assertEqual('topological', repo._format._fetch_order)
242
224
def test_attribute__fetch_uses_deltas(self):
243
225
"""Knits reuse deltas."""
244
226
repo = self.make_repository('.',
245
format=bzrdir.format_registry.get('knit')())
227
format=controldir.format_registry.get('knit')())
246
228
self.assertEqual(True, repo._format._fetch_uses_deltas)
248
230
def test_disk_layout(self):
334
316
is valid when the api is not being abused.
336
318
repo = self.make_repository('.',
337
format=bzrdir.format_registry.get('knit')())
319
format=controldir.format_registry.get('knit')())
338
320
inv_xml = '<inventory format="5">\n</inventory>\n'
339
321
inv = repo._deserialise_inventory('test-rev-id', inv_xml)
340
322
self.assertEqual('test-rev-id', inv.root.revision)
342
324
def test_deserialise_uses_global_revision_id(self):
343
325
"""If it is set, then we re-use the global revision id"""
344
326
repo = self.make_repository('.',
345
format=bzrdir.format_registry.get('knit')())
327
format=controldir.format_registry.get('knit')())
346
328
inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
347
329
'</inventory>\n')
348
330
# Arguably, the deserialise_inventory should detect a mismatch, and
356
338
def test_supports_external_lookups(self):
357
339
repo = self.make_repository('.',
358
format=bzrdir.format_registry.get('knit')())
340
format=controldir.format_registry.get('knit')())
359
341
self.assertFalse(repo._format.supports_external_lookups)
524
506
revision_tree.lock_read()
526
508
self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
527
revision_tree.inventory.root.file_id)
509
revision_tree.get_root_id())
529
511
revision_tree.unlock()
530
512
format = bzrdir.BzrDirMetaFormat1()
534
516
revision_tree = tree.branch.repository.revision_tree('dull')
535
517
revision_tree.lock_read()
537
revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
519
revision_tree.get_file_lines(revision_tree.get_root_id())
539
521
revision_tree.unlock()
540
522
tree.commit("Another dull commit", rev_id='dull2')
541
523
revision_tree = tree.branch.repository.revision_tree('dull2')
542
524
revision_tree.lock_read()
543
525
self.addCleanup(revision_tree.unlock)
544
self.assertEqual('dull', revision_tree.inventory.root.revision)
526
self.assertEqual('dull',
527
revision_tree.get_file_revision(revision_tree.get_root_id()))
546
529
def test_supports_external_lookups(self):
547
530
format = bzrdir.BzrDirMetaFormat1()