~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

Merge pt1 hooks branch.

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 (NoSuchFile,
30
 
                           UnknownFormatError,
31
 
                           UnsupportedFormatError,
32
 
                           )
 
29
from bzrlib.errors import (
 
30
    NoSuchFile,
 
31
    UnknownFormatError,
 
32
    UnsupportedFormatError,
 
33
    )
33
34
from bzrlib import (
34
35
    btree_index,
35
36
    graph,
 
37
    symbol_versioning,
36
38
    tests,
 
39
    transport,
37
40
    )
38
41
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
39
42
from bzrlib.index import GraphIndex
42
45
    TestCase,
43
46
    TestCaseWithTransport,
44
47
    )
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.RepositoryFormat.get_default_format()
 
72
        old_format = repository.format_registry.get_default()
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.RepositoryFormat.get_default_format(),
 
92
        self.assertIsInstance(repository.format_registry.get_default(),
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
 
120
129
class TestRepositoryFormat(TestCaseWithTransport):
121
130
    """Tests for the Repository format detection used by the bzr meta dir facility.BzrBranchFormat facility."""
122
131
 
128
137
        def check_format(format, url):
129
138
            dir = format._matchingbzrdir.initialize(url)
130
139
            format.initialize(dir)
131
 
            t = get_transport(url)
 
140
            t = transport.get_transport(url)
132
141
            found_format = repository.RepositoryFormat.find_format(dir)
133
142
            self.failUnless(isinstance(found_format, format.__class__))
134
143
        check_format(weaverepo.RepositoryFormat7(), "bar")
147
156
                          dir)
148
157
 
149
158
    def test_register_unregister_format(self):
 
159
        # Test deprecated format registration functions
150
160
        format = SampleRepositoryFormat()
151
161
        # make a control dir
152
162
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
153
163
        # make a repo
154
164
        format.initialize(dir)
155
165
        # register a format for it.
156
 
        repository.RepositoryFormat.register_format(format)
 
166
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
167
            repository.RepositoryFormat.register_format, format)
157
168
        # which repository.Open will refuse (not supported)
158
 
        self.assertRaises(UnsupportedFormatError, repository.Repository.open, self.get_url())
 
169
        self.assertRaises(UnsupportedFormatError, repository.Repository.open,
 
170
            self.get_url())
159
171
        # but open(unsupported) will work
160
172
        self.assertEqual(format.open(dir), "opened repository.")
161
173
        # unregister the format
162
 
        repository.RepositoryFormat.unregister_format(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)
163
210
 
164
211
 
165
212
class TestFormat6(TestCaseWithTransport):
606
653
class TestRepositoryConverter(TestCaseWithTransport):
607
654
 
608
655
    def test_convert_empty(self):
609
 
        t = get_transport(self.get_url('.'))
 
656
        t = self.get_transport()
610
657
        t.mkdir('repository')
611
658
        repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
612
659
        repo = weaverepo.RepositoryFormat7().initialize(repo_dir)