~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-08 13:45:51 UTC
  • mfrom: (5532.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101108134551-sxvk77ehmegkrwmm
(vila) Fix news entry

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import sys
27
27
 
28
28
import bzrlib
29
 
from bzrlib.errors import (
30
 
    NoSuchFile,
31
 
    UnknownFormatError,
32
 
    UnsupportedFormatError,
33
 
    )
 
29
from bzrlib.errors import (NoSuchFile,
 
30
                           UnknownFormatError,
 
31
                           UnsupportedFormatError,
 
32
                           )
34
33
from bzrlib import (
35
34
    btree_index,
36
35
    graph,
37
 
    symbol_versioning,
38
36
    tests,
39
 
    transport,
40
37
    )
41
38
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
42
39
from bzrlib.index import GraphIndex
45
42
    TestCase,
46
43
    TestCaseWithTransport,
47
44
    )
 
45
from bzrlib.transport import (
 
46
    get_transport,
 
47
    )
48
48
from bzrlib import (
49
49
    bzrdir,
50
50
    errors,
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.format_registry.get_default()
 
72
        old_format = repository.RepositoryFormat.get_default_format()
73
73
        self.assertTrue(isinstance(old_format, private_default))
74
74
        def make_sample_bzrdir():
75
75
            my_bzrdir = bzrdir.BzrDirMetaFormat1()
89
89
            bzrdir.format_registry.remove('default')
90
90
            bzrdir.format_registry.remove('sample')
91
91
            bzrdir.format_registry.register('default', old_default, '')
92
 
        self.assertIsInstance(repository.format_registry.get_default(),
 
92
        self.assertIsInstance(repository.RepositoryFormat.get_default_format(),
93
93
                              old_format.__class__)
94
94
 
95
95
 
117
117
        return "opened repository."
118
118
 
119
119
 
120
 
class SampleExtraRepositoryFormat(repository.RepositoryFormat):
121
 
    """A sample format that can not be used in a metadir
122
 
 
123
 
    """
124
 
 
125
 
    def get_format_string(self):
126
 
        raise NotImplementedError
127
 
 
128
 
 
129
120
class TestRepositoryFormat(TestCaseWithTransport):
130
121
    """Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility."""
131
122
 
137
128
        def check_format(format, url):
138
129
            dir = format._matchingbzrdir.initialize(url)
139
130
            format.initialize(dir)
140
 
            t = transport.get_transport(url)
 
131
            t = get_transport(url)
141
132
            found_format = repository.RepositoryFormat.find_format(dir)
142
133
            self.failUnless(isinstance(found_format, format.__class__))
143
134
        check_format(weaverepo.RepositoryFormat7(), "bar")
156
147
                          dir)
157
148
 
158
149
    def test_register_unregister_format(self):
159
 
        # Test deprecated format registration functions
160
150
        format = SampleRepositoryFormat()
161
151
        # make a control dir
162
152
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
163
153
        # make a repo
164
154
        format.initialize(dir)
165
155
        # register a format for it.
166
 
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
167
 
            repository.RepositoryFormat.register_format, format)
 
156
        repository.RepositoryFormat.register_format(format)
168
157
        # which repository.Open will refuse (not supported)
169
 
        self.assertRaises(UnsupportedFormatError, repository.Repository.open,
170
 
            self.get_url())
 
158
        self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url())
171
159
        # but open(unsupported) will work
172
160
        self.assertEqual(format.open(dir), "opened repository.")
173
161
        # unregister the format
174
 
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
175
 
            repository.RepositoryFormat.unregister_format, format)
176
 
 
177
 
 
178
 
class TestRepositoryFormatRegistry(TestCase):
179
 
 
180
 
    def setUp(self):
181
 
        super(TestRepositoryFormatRegistry, self).setUp()
182
 
        self.registry = repository.RepositoryFormatRegistry()
183
 
 
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.")
190
 
 
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())
196
 
 
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())
202
 
 
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)
 
162
        repository.RepositoryFormat.unregister_format(format)
210
163
 
211
164
 
212
165
class TestFormat6(TestCaseWithTransport):
633
586
                                ]
634
587
        repo_a = self.make_repository('a')
635
588
        repo_b = self.make_repository('b')
636
 
        is_compatible = weaverepo.InterWeaveRepo.is_compatible
 
589
        is_compatible = repository.InterWeaveRepo.is_compatible
637
590
        for source in incompatible_formats:
638
591
            # force incompatible left then right
639
592
            repo_a._format = source
645
598
            for target in formats:
646
599
                repo_b._format = target
647
600
                self.assertTrue(is_compatible(repo_a, repo_b))
648
 
        self.assertEqual(weaverepo.InterWeaveRepo,
 
601
        self.assertEqual(repository.InterWeaveRepo,
649
602
                         repository.InterRepository.get(repo_a,
650
603
                                                        repo_b).__class__)
651
604
 
653
606
class TestRepositoryConverter(TestCaseWithTransport):
654
607
 
655
608
    def test_convert_empty(self):
656
 
        t = self.get_transport()
 
609
        t = get_transport(self.get_url('.'))
657
610
        t.mkdir('repository')
658
611
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
659
612
        repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
1019
972
 
1020
973
    def setUp(self):
1021
974
        super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
1022
 
        self.builder = self.make_branch_builder('source')
 
975
        self.builder = self.make_branch_builder('source',
 
976
            format='development6-rich-root')
1023
977
        self.builder.start_series()
1024
978
        self.builder.build_snapshot('initial', None,
1025
979
            [('add', ('', 'tree-root', 'directory', None))])
1706
1660
        self.orig_pack = target.pack
1707
1661
        target.pack = self.log_pack
1708
1662
        search = target.search_missing_revision_ids(
1709
 
            source_tree.branch.repository, revision_ids=[tip])
 
1663
            source_tree.branch.repository, tip)
1710
1664
        stream = source.get_stream(search)
1711
1665
        from_format = source_tree.branch.repository._format
1712
1666
        sink = target._get_sink()