~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    )
32
32
from bzrlib import (
33
33
    btree_index,
34
 
    graph,
35
34
    symbol_versioning,
36
35
    tests,
37
36
    transport,
 
37
    vf_search,
38
38
    )
39
39
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
40
40
from bzrlib.index import GraphIndex
92
92
                              old_format.__class__)
93
93
 
94
94
 
95
 
class SampleRepositoryFormat(repository.RepositoryFormat):
 
95
class SampleRepositoryFormat(repository.RepositoryFormatMetaDir):
96
96
    """A sample format
97
97
 
98
98
    this format is initializable, unsupported to aid in testing the
99
99
    open and open(unsupported=True) routines.
100
100
    """
101
101
 
102
 
    def get_format_string(self):
 
102
    @classmethod
 
103
    def get_format_string(cls):
103
104
        """See RepositoryFormat.get_format_string()."""
104
105
        return "Sample .bzr repository format."
105
106
 
137
138
            dir = format._matchingbzrdir.initialize(url)
138
139
            format.initialize(dir)
139
140
            t = transport.get_transport_from_path(url)
140
 
            found_format = repository.RepositoryFormat.find_format(dir)
 
141
            found_format = repository.RepositoryFormatMetaDir.find_format(dir)
141
142
            self.assertIsInstance(found_format, format.__class__)
142
143
        check_format(repository.format_registry.get_default(), "bar")
143
144
 
144
145
    def test_find_format_no_repository(self):
145
146
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
146
147
        self.assertRaises(errors.NoRepositoryPresent,
147
 
                          repository.RepositoryFormat.find_format,
 
148
                          repository.RepositoryFormatMetaDir.find_format,
148
149
                          dir)
149
150
 
 
151
    def test_from_string(self):
 
152
        self.assertIsInstance(
 
153
            SampleRepositoryFormat.from_string(
 
154
                "Sample .bzr repository format."),
 
155
            SampleRepositoryFormat)
 
156
        self.assertRaises(AssertionError,
 
157
            SampleRepositoryFormat.from_string,
 
158
                "Different .bzr repository format.")
 
159
 
150
160
    def test_find_format_unknown_format(self):
151
161
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
152
162
        SampleRepositoryFormat().initialize(dir)
153
163
        self.assertRaises(UnknownFormatError,
154
 
                          repository.RepositoryFormat.find_format,
 
164
                          repository.RepositoryFormatMetaDir.find_format,
155
165
                          dir)
156
166
 
 
167
    def test_find_format_with_features(self):
 
168
        tree = self.make_branch_and_tree('.', format='2a')
 
169
        tree.branch.repository.update_feature_flags({"name": "necessity"})
 
170
        found_format = repository.RepositoryFormatMetaDir.find_format(tree.bzrdir)
 
171
        self.assertIsInstance(found_format, repository.RepositoryFormatMetaDir)
 
172
        self.assertEquals(found_format.features.get("name"), "necessity")
 
173
        self.assertRaises(errors.MissingFeature, found_format.check_support_status,
 
174
            True)
 
175
        self.addCleanup(repository.RepositoryFormatMetaDir.unregister_feature,
 
176
            "name")
 
177
        repository.RepositoryFormatMetaDir.register_feature("name")
 
178
        found_format.check_support_status(True)
 
179
 
157
180
    def test_register_unregister_format(self):
158
181
        # Test deprecated format registration functions
159
182
        format = SampleRepositoryFormat()
438
461
 
439
462
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
440
463
 
441
 
    def get_format_string(self):
 
464
    @classmethod
 
465
    def get_format_string(cls):
442
466
        return "Test Format 1"
443
467
 
444
468
 
445
469
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
446
470
 
447
 
    def get_format_string(self):
 
471
    @classmethod
 
472
    def get_format_string(cls):
448
473
        return "Test Format 2"
449
474
 
450
475
 
706
731
 
707
732
        # On a regular pass, getting the inventories and chk pages for rev-2
708
733
        # would only get the newly created chk pages
709
 
        search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
 
734
        search = vf_search.SearchResult(set(['rev-2']), set(['rev-1']), 1,
710
735
                                    set(['rev-2']))
711
736
        simple_chk_records = []
712
737
        for vf_name, substream in source.get_stream(search):
893
918
            revision = _mod_revision.Revision('rev1a',
894
919
                committer='jrandom@example.com', timestamp=0,
895
920
                inventory_sha1='', timezone=0, message='foo', parent_ids=[])
896
 
            repo.add_revision('rev1a',revision, inv)
 
921
            repo.add_revision('rev1a', revision, inv)
897
922
 
898
923
            # make rev1b, which has no Revision, but has an Inventory, and
899
924
            # file1
934
959
        revision = _mod_revision.Revision(revision_id,
935
960
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
936
961
            timezone=0, message='foo', parent_ids=parent_ids)
937
 
        repo.add_revision(revision_id,revision, inv)
 
962
        repo.add_revision(revision_id, revision, inv)
938
963
 
939
964
    def add_file(self, repo, inv, filename, revision, parents):
940
965
        file_id = filename + '-id'
1070
1095
            sorted(set([osutils.splitext(n)[0] for n in
1071
1096
                        packs._index_transport.list_dir('.')])))
1072
1097
 
 
1098
    def test__obsolete_packs_missing_directory(self):
 
1099
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1100
        r.control_transport.rmdir('obsolete_packs')
 
1101
        names = packs.names()
 
1102
        pack = packs.get_pack_by_name(names[0])
 
1103
        # Schedule this one for removal
 
1104
        packs._remove_pack_from_memory(pack)
 
1105
        # Now trigger the obsoletion, and ensure that all the remaining files
 
1106
        # are still renamed
 
1107
        packs._obsolete_packs([pack])
 
1108
        self.assertEqual([n + '.pack' for n in names[1:]],
 
1109
                         sorted(packs._pack_transport.list_dir('.')))
 
1110
        # names[0] should not be present in the index anymore
 
1111
        self.assertEqual(names[1:],
 
1112
            sorted(set([osutils.splitext(n)[0] for n in
 
1113
                        packs._index_transport.list_dir('.')])))
 
1114
 
1073
1115
    def test_pack_distribution_zero(self):
1074
1116
        packs = self.get_packs()
1075
1117
        self.assertEqual([0], packs.pack_distribution(0))
1345
1387
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1346
1388
        self.assertEqual([pack.name], sorted(obsolete_names))
1347
1389
 
 
1390
    def test_pack_no_obsolete_packs_directory(self):
 
1391
        """Bug #314314, don't fail if obsolete_packs directory does
 
1392
        not exist."""
 
1393
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1394
        r.control_transport.rmdir('obsolete_packs')
 
1395
        packs._clear_obsolete_packs()
1348
1396
 
1349
1397
 
1350
1398
class TestPack(TestCaseWithTransport):
1668
1716
        lazy = repository._LazyListJoin(['a'], ['b'])
1669
1717
        self.assertEqual("bzrlib.repository._LazyListJoin((['a'], ['b']))",
1670
1718
                         repr(lazy))
 
1719
 
 
1720
 
 
1721
class TestFeatures(tests.TestCaseWithTransport):
 
1722
 
 
1723
    def test_open_with_present_feature(self):
 
1724
        self.addCleanup(
 
1725
            repository.RepositoryFormatMetaDir.unregister_feature,
 
1726
            "makes-cheese-sandwich")
 
1727
        repository.RepositoryFormatMetaDir.register_feature(
 
1728
            "makes-cheese-sandwich")
 
1729
        repo = self.make_repository('.')
 
1730
        repo.lock_write()
 
1731
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1732
        repo._format.check_support_status(False)
 
1733
        repo.unlock()
 
1734
 
 
1735
    def test_open_with_missing_required_feature(self):
 
1736
        repo = self.make_repository('.')
 
1737
        repo.lock_write()
 
1738
        repo._format.features["makes-cheese-sandwich"] = "required"
 
1739
        self.assertRaises(errors.MissingFeature,
 
1740
            repo._format.check_support_status, False)