~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

(gz) Fix deprecations of win32utils path function unicode wrappers (Martin
 Packman)

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
 
136
137
        def check_format(format, url):
137
138
            dir = format._matchingbzrdir.initialize(url)
138
139
            format.initialize(dir)
139
 
            t = transport.get_transport(url)
140
 
            found_format = repository.RepositoryFormat.find_format(dir)
 
140
            t = transport.get_transport_from_path(url)
 
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(ValueError,
 
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
 
157
167
    def test_register_unregister_format(self):
438
448
 
439
449
class TestRepositoryFormat1(knitrepo.RepositoryFormatKnit1):
440
450
 
441
 
    def get_format_string(self):
 
451
    @classmethod
 
452
    def get_format_string(cls):
442
453
        return "Test Format 1"
443
454
 
444
455
 
445
456
class TestRepositoryFormat2(knitrepo.RepositoryFormatKnit1):
446
457
 
447
 
    def get_format_string(self):
 
458
    @classmethod
 
459
    def get_format_string(cls):
448
460
        return "Test Format 2"
449
461
 
450
462
 
706
718
 
707
719
        # On a regular pass, getting the inventories and chk pages for rev-2
708
720
        # would only get the newly created chk pages
709
 
        search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
 
721
        search = vf_search.SearchResult(set(['rev-2']), set(['rev-1']), 1,
710
722
                                    set(['rev-2']))
711
723
        simple_chk_records = []
712
724
        for vf_name, substream in source.get_stream(search):
893
905
            revision = _mod_revision.Revision('rev1a',
894
906
                committer='jrandom@example.com', timestamp=0,
895
907
                inventory_sha1='', timezone=0, message='foo', parent_ids=[])
896
 
            repo.add_revision('rev1a',revision, inv)
 
908
            repo.add_revision('rev1a', revision, inv)
897
909
 
898
910
            # make rev1b, which has no Revision, but has an Inventory, and
899
911
            # file1
934
946
        revision = _mod_revision.Revision(revision_id,
935
947
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
936
948
            timezone=0, message='foo', parent_ids=parent_ids)
937
 
        repo.add_revision(revision_id,revision, inv)
 
949
        repo.add_revision(revision_id, revision, inv)
938
950
 
939
951
    def add_file(self, repo, inv, filename, revision, parents):
940
952
        file_id = filename + '-id'
1070
1082
            sorted(set([osutils.splitext(n)[0] for n in
1071
1083
                        packs._index_transport.list_dir('.')])))
1072
1084
 
 
1085
    def test__obsolete_packs_missing_directory(self):
 
1086
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1087
        r.control_transport.rmdir('obsolete_packs')
 
1088
        names = packs.names()
 
1089
        pack = packs.get_pack_by_name(names[0])
 
1090
        # Schedule this one for removal
 
1091
        packs._remove_pack_from_memory(pack)
 
1092
        # Now trigger the obsoletion, and ensure that all the remaining files
 
1093
        # are still renamed
 
1094
        packs._obsolete_packs([pack])
 
1095
        self.assertEqual([n + '.pack' for n in names[1:]],
 
1096
                         sorted(packs._pack_transport.list_dir('.')))
 
1097
        # names[0] should not be present in the index anymore
 
1098
        self.assertEqual(names[1:],
 
1099
            sorted(set([osutils.splitext(n)[0] for n in
 
1100
                        packs._index_transport.list_dir('.')])))
 
1101
 
1073
1102
    def test_pack_distribution_zero(self):
1074
1103
        packs = self.get_packs()
1075
1104
        self.assertEqual([0], packs.pack_distribution(0))
1345
1374
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
1346
1375
        self.assertEqual([pack.name], sorted(obsolete_names))
1347
1376
 
 
1377
    def test_pack_no_obsolete_packs_directory(self):
 
1378
        """Bug #314314, don't fail if obsolete_packs directory does
 
1379
        not exist."""
 
1380
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1381
        r.control_transport.rmdir('obsolete_packs')
 
1382
        packs._clear_obsolete_packs()
1348
1383
 
1349
1384
 
1350
1385
class TestPack(TestCaseWithTransport):
1660
1695
    def test_IDS_format_same_no(self):
1661
1696
        # When the formats are the same, pack is not called.
1662
1697
        self.run_fetch('2a', '2a', False)
 
1698
 
 
1699
 
 
1700
class Test_LazyListJoin(tests.TestCase):
 
1701
 
 
1702
    def test__repr__(self):
 
1703
        lazy = repository._LazyListJoin(['a'], ['b'])
 
1704
        self.assertEqual("bzrlib.repository._LazyListJoin((['a'], ['b']))",
 
1705
                         repr(lazy))