~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Ross Lagerwall
  • Date: 2012-08-07 06:32:51 UTC
  • mto: (6437.63.5 2.5)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: rosslagerwall@gmail.com-20120807063251-x9p03ghg2ws8oqjc
Add bzrlib/locale to .bzrignore

bzrlib/locale is generated with ./setup.py build_mo which is in turn called
by ./setup.py build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
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
45
45
    )
46
46
from bzrlib import (
47
47
    bzrdir,
48
 
    controldir,
49
48
    errors,
50
49
    inventory,
51
50
    osutils,
67
66
class TestDefaultFormat(TestCase):
68
67
 
69
68
    def test_get_set_default_format(self):
70
 
        old_default = controldir.format_registry.get('default')
 
69
        old_default = bzrdir.format_registry.get('default')
71
70
        private_default = old_default().repository_format.__class__
72
71
        old_format = repository.format_registry.get_default()
73
72
        self.assertTrue(isinstance(old_format, private_default))
75
74
            my_bzrdir = bzrdir.BzrDirMetaFormat1()
76
75
            my_bzrdir.repository_format = SampleRepositoryFormat()
77
76
            return my_bzrdir
78
 
        controldir.format_registry.remove('default')
79
 
        controldir.format_registry.register('sample', make_sample_bzrdir, '')
80
 
        controldir.format_registry.set_default('sample')
 
77
        bzrdir.format_registry.remove('default')
 
78
        bzrdir.format_registry.register('sample', make_sample_bzrdir, '')
 
79
        bzrdir.format_registry.set_default('sample')
81
80
        # creating a repository should now create an instrumented dir.
82
81
        try:
83
82
            # the default branch format is used by the meta dir format
86
85
            result = dir.create_repository()
87
86
            self.assertEqual(result, 'A bzr repository dir')
88
87
        finally:
89
 
            controldir.format_registry.remove('default')
90
 
            controldir.format_registry.remove('sample')
91
 
            controldir.format_registry.register('default', old_default, '')
 
88
            bzrdir.format_registry.remove('default')
 
89
            bzrdir.format_registry.remove('sample')
 
90
            bzrdir.format_registry.register('default', old_default, '')
92
91
        self.assertIsInstance(repository.format_registry.get_default(),
93
92
                              old_format.__class__)
94
93
 
170
169
        tree.branch.repository.update_feature_flags({"name": "necessity"})
171
170
        found_format = repository.RepositoryFormatMetaDir.find_format(tree.bzrdir)
172
171
        self.assertIsInstance(found_format, repository.RepositoryFormatMetaDir)
173
 
        self.assertEqual(found_format.features.get("name"), "necessity")
 
172
        self.assertEquals(found_format.features.get("name"), "necessity")
174
173
        self.assertRaises(errors.MissingFeature, found_format.check_support_status,
175
174
            True)
176
175
        self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
178
177
        repository.RepositoryFormatMetaDir.register_feature("name")
179
178
        found_format.check_support_status(True)
180
179
 
 
180
    def test_register_unregister_format(self):
 
181
        # Test deprecated format registration functions
 
182
        format = SampleRepositoryFormat()
 
183
        # make a control dir
 
184
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
185
        # make a repo
 
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,
 
192
            self.get_url())
 
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)
 
198
 
181
199
 
182
200
class TestRepositoryFormatRegistry(TestCase):
183
201
 
188
206
    def test_register_unregister_format(self):
189
207
        format = SampleRepositoryFormat()
190
208
        self.registry.register(format)
191
 
        self.assertEqual(format, self.registry.get("Sample .bzr repository format."))
 
209
        self.assertEquals(format, self.registry.get("Sample .bzr repository format."))
192
210
        self.registry.remove(format)
193
211
        self.assertRaises(KeyError, self.registry.get, "Sample .bzr repository format.")
194
212
 
195
213
    def test_get_all(self):
196
214
        format = SampleRepositoryFormat()
197
 
        self.assertEqual([], self.registry._get_all())
 
215
        self.assertEquals([], self.registry._get_all())
198
216
        self.registry.register(format)
199
 
        self.assertEqual([format], self.registry._get_all())
 
217
        self.assertEquals([format], self.registry._get_all())
200
218
 
201
219
    def test_register_extra(self):
202
220
        format = SampleExtraRepositoryFormat()
203
 
        self.assertEqual([], self.registry._get_all())
 
221
        self.assertEquals([], self.registry._get_all())
204
222
        self.registry.register_extra(format)
205
 
        self.assertEqual([format], self.registry._get_all())
 
223
        self.assertEquals([format], self.registry._get_all())
206
224
 
207
225
    def test_register_extra_lazy(self):
208
 
        self.assertEqual([], self.registry._get_all())
 
226
        self.assertEquals([], self.registry._get_all())
209
227
        self.registry.register_extra_lazy("bzrlib.tests.test_repository",
210
228
            "SampleExtraRepositoryFormat")
211
229
        formats = self.registry._get_all()
212
 
        self.assertEqual(1, len(formats))
 
230
        self.assertEquals(1, len(formats))
213
231
        self.assertIsInstance(formats[0], SampleExtraRepositoryFormat)
214
232
 
215
233
 
218
236
    def test_attribute__fetch_order(self):
219
237
        """Knits need topological data insertion."""
220
238
        repo = self.make_repository('.',
221
 
                format=controldir.format_registry.get('knit')())
 
239
                format=bzrdir.format_registry.get('knit')())
222
240
        self.assertEqual('topological', repo._format._fetch_order)
223
241
 
224
242
    def test_attribute__fetch_uses_deltas(self):
225
243
        """Knits reuse deltas."""
226
244
        repo = self.make_repository('.',
227
 
                format=controldir.format_registry.get('knit')())
 
245
                format=bzrdir.format_registry.get('knit')())
228
246
        self.assertEqual(True, repo._format._fetch_uses_deltas)
229
247
 
230
248
    def test_disk_layout(self):
316
334
        is valid when the api is not being abused.
317
335
        """
318
336
        repo = self.make_repository('.',
319
 
                format=controldir.format_registry.get('knit')())
 
337
                format=bzrdir.format_registry.get('knit')())
320
338
        inv_xml = '<inventory format="5">\n</inventory>\n'
321
339
        inv = repo._deserialise_inventory('test-rev-id', inv_xml)
322
340
        self.assertEqual('test-rev-id', inv.root.revision)
324
342
    def test_deserialise_uses_global_revision_id(self):
325
343
        """If it is set, then we re-use the global revision id"""
326
344
        repo = self.make_repository('.',
327
 
                format=controldir.format_registry.get('knit')())
 
345
                format=bzrdir.format_registry.get('knit')())
328
346
        inv_xml = ('<inventory format="5" revision_id="other-rev-id">\n'
329
347
                   '</inventory>\n')
330
348
        # Arguably, the deserialise_inventory should detect a mismatch, and
337
355
 
338
356
    def test_supports_external_lookups(self):
339
357
        repo = self.make_repository('.',
340
 
                format=controldir.format_registry.get('knit')())
 
358
                format=bzrdir.format_registry.get('knit')())
341
359
        self.assertFalse(repo._format.supports_external_lookups)
342
360
 
343
361
 
506
524
        revision_tree.lock_read()
507
525
        try:
508
526
            self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
509
 
                revision_tree.get_root_id())
 
527
                revision_tree.inventory.root.file_id)
510
528
        finally:
511
529
            revision_tree.unlock()
512
530
        format = bzrdir.BzrDirMetaFormat1()
516
534
        revision_tree = tree.branch.repository.revision_tree('dull')
517
535
        revision_tree.lock_read()
518
536
        try:
519
 
            revision_tree.get_file_lines(revision_tree.get_root_id())
 
537
            revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
520
538
        finally:
521
539
            revision_tree.unlock()
522
540
        tree.commit("Another dull commit", rev_id='dull2')
523
541
        revision_tree = tree.branch.repository.revision_tree('dull2')
524
542
        revision_tree.lock_read()
525
543
        self.addCleanup(revision_tree.unlock)
526
 
        self.assertEqual('dull',
527
 
                revision_tree.get_file_revision(revision_tree.get_root_id()))
 
544
        self.assertEqual('dull', revision_tree.inventory.root.revision)
528
545
 
529
546
    def test_supports_external_lookups(self):
530
547
        format = bzrdir.BzrDirMetaFormat1()
976
993
class TestRepositoryPackCollection(TestCaseWithTransport):
977
994
 
978
995
    def get_format(self):
979
 
        return controldir.format_registry.make_bzrdir('pack-0.92')
 
996
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
980
997
 
981
998
    def get_packs(self):
982
999
        format = self.get_format()