/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_branch.py

Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from .. import (
26
26
    branch as _mod_branch,
 
27
    bzrbranch as _mod_bzrbranch,
27
28
    bzrdir,
28
29
    config,
29
30
    controldir,
46
47
    def test_default_format(self):
47
48
        # update this if you change the default branch format
48
49
        self.assertIsInstance(_mod_branch.format_registry.get_default(),
49
 
                _mod_branch.BzrBranchFormat7)
 
50
                _mod_bzrbranch.BzrBranchFormat7)
50
51
 
51
52
    def test_default_format_is_same_as_bzrdir_default(self):
52
53
        # XXX: it might be nice if there was only one place the default was
59
60
    def test_get_set_default_format(self):
60
61
        # set the format and then set it back again
61
62
        old_format = _mod_branch.format_registry.get_default()
62
 
        _mod_branch.format_registry.set_default(SampleBranchFormat())
 
63
        _mod_branch.format_registry.set_default(
 
64
            SampleBranchFormat())
63
65
        try:
64
66
            # the default branch format is used by the meta dir format
65
67
            # which is not the default bzrdir format at this point
106
108
    # recursive section - that is, it appends the branch name.
107
109
 
108
110
 
109
 
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
 
111
class SampleBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
110
112
    """A sample format
111
113
 
112
114
    this format is initializable, unsupported to aid in testing the
138
140
SampleSupportedBranchFormatString = "Sample supported branch format."
139
141
 
140
142
# And the format class can then reference the constant to avoid skew.
141
 
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
 
143
class SampleSupportedBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
142
144
    """A sample supported format."""
143
145
 
144
146
    @classmethod
187
189
            dir = format._matchingbzrdir.initialize(url)
188
190
            dir.create_repository()
189
191
            format.initialize(dir)
190
 
            found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
 
192
            found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(dir)
191
193
            self.assertIsInstance(found_format, format.__class__)
192
194
        check_format(BzrBranchFormat5(), "bar")
193
195
 
194
 
    def test_find_format_factory(self):
195
 
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
196
 
        SampleSupportedBranchFormat().initialize(dir)
197
 
        factory = _mod_branch.MetaDirBranchFormatFactory(
198
 
            SampleSupportedBranchFormatString,
199
 
            "breezy.tests.test_branch", "SampleSupportedBranchFormat")
200
 
        _mod_branch.format_registry.register(factory)
201
 
        self.addCleanup(_mod_branch.format_registry.remove, factory)
202
 
        b = _mod_branch.Branch.open(self.get_url())
203
 
        self.assertEqual(b, "opened supported branch.")
204
 
 
205
196
    def test_from_string(self):
206
197
        self.assertIsInstance(
207
198
            SampleBranchFormat.from_string("Sample branch format."),
212
203
    def test_find_format_not_branch(self):
213
204
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
214
205
        self.assertRaises(errors.NotBranchError,
215
 
                          _mod_branch.BranchFormatMetadir.find_format,
 
206
                          _mod_bzrbranch.BranchFormatMetadir.find_format,
216
207
                          dir)
217
208
 
218
209
    def test_find_format_unknown_format(self):
219
210
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
220
211
        SampleBranchFormat().initialize(dir)
221
212
        self.assertRaises(errors.UnknownFormatError,
222
 
                          _mod_branch.BranchFormatMetadir.find_format,
 
213
                          _mod_bzrbranch.BranchFormatMetadir.find_format,
223
214
                          dir)
224
215
 
225
216
    def test_find_format_with_features(self):
226
217
        tree = self.make_branch_and_tree('.', format='2a')
227
218
        tree.branch.update_feature_flags({"name": "optional"})
228
 
        found_format = _mod_branch.BranchFormatMetadir.find_format(tree.bzrdir)
229
 
        self.assertIsInstance(found_format, _mod_branch.BranchFormatMetadir)
 
219
        found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(tree.bzrdir)
 
220
        self.assertIsInstance(found_format, _mod_bzrbranch.BranchFormatMetadir)
230
221
        self.assertEqual(found_format.features.get("name"), "optional")
231
222
        tree.branch.update_feature_flags({"name": None})
232
223
        branch = _mod_branch.Branch.open('.')
275
266
        self.assertIsInstance(formats[0], SampleExtraBranchFormat)
276
267
 
277
268
 
278
 
#Used by TestMetaDirBranchFormatFactory 
279
 
FakeLazyFormat = None
280
 
 
281
 
 
282
 
class TestMetaDirBranchFormatFactory(tests.TestCase):
283
 
 
284
 
    def test_get_format_string_does_not_load(self):
285
 
        """Formats have a static format string."""
286
 
        factory = _mod_branch.MetaDirBranchFormatFactory("yo", None, None)
287
 
        self.assertEqual("yo", factory.get_format_string())
288
 
 
289
 
    def test_call_loads(self):
290
 
        # __call__ is used by the network_format_registry interface to get a
291
 
        # Format.
292
 
        global FakeLazyFormat
293
 
        del FakeLazyFormat
294
 
        factory = _mod_branch.MetaDirBranchFormatFactory(None,
295
 
            "breezy.tests.test_branch", "FakeLazyFormat")
296
 
        self.assertRaises(AttributeError, factory)
297
 
 
298
 
    def test_call_returns_call_of_referenced_object(self):
299
 
        global FakeLazyFormat
300
 
        FakeLazyFormat = lambda:'called'
301
 
        factory = _mod_branch.MetaDirBranchFormatFactory(None,
302
 
            "breezy.tests.test_branch", "FakeLazyFormat")
303
 
        self.assertEqual('called', factory())
304
 
 
305
 
 
306
269
class TestBranch67(object):
307
270
    """Common tests for both branch 6 and 7 which are mostly the same."""
308
271
 
317
280
 
318
281
    def test_creation(self):
319
282
        format = bzrdir.BzrDirMetaFormat1()
320
 
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
 
283
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
321
284
        branch = self.make_branch('a', format=format)
322
285
        self.assertIsInstance(branch, self.get_class())
323
286
        branch = self.make_branch('b', format=self.get_format_name())
381
344
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
382
345
 
383
346
    def get_class(self):
384
 
        return _mod_branch.BzrBranch6
 
347
        return _mod_bzrbranch.BzrBranch6
385
348
 
386
349
    def get_format_name(self):
387
350
        return "dirstate-tags"
402
365
class TestBranch7(TestBranch67, tests.TestCaseWithTransport):
403
366
 
404
367
    def get_class(self):
405
 
        return _mod_branch.BzrBranch7
 
368
        return _mod_bzrbranch.BzrBranch7
406
369
 
407
370
    def get_format_name(self):
408
371
        return "1.9"
413
376
    def test_set_stacked_on_url_unstackable_repo(self):
414
377
        repo = self.make_repository('a', format='dirstate-tags')
415
378
        control = repo.bzrdir
416
 
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
 
379
        branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
417
380
        target = self.make_branch('b')
418
381
        self.assertRaises(errors.UnstackableRepositoryFormat,
419
382
            branch.set_stacked_on_url, target.base)
421
384
    def test_clone_stacked_on_unstackable_repo(self):
422
385
        repo = self.make_repository('a', format='dirstate-tags')
423
386
        control = repo.bzrdir
424
 
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
 
387
        branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
425
388
        # Calling clone should not raise UnstackableRepositoryFormat.
426
389
        cloned_bzrdir = control.clone('cloned')
427
390
 
454
417
    def make_branch(self, location, format=None):
455
418
        if format is None:
456
419
            format = controldir.format_registry.make_bzrdir('1.9')
457
 
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
 
420
            format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
458
421
        return tests.TestCaseWithTransport.make_branch(
459
422
            self, location, format=format)
460
423
 
533
496
        target_branch = dir.create_branch()
534
497
        t.mkdir('branch')
535
498
        branch_dir = bzrdirformat.initialize(self.get_url('branch'))
536
 
        made_branch = _mod_branch.BranchReferenceFormat().initialize(
 
499
        made_branch = _mod_bzrbranch.BranchReferenceFormat().initialize(
537
500
            branch_dir, target_branch=target_branch)
538
501
        self.assertEqual(made_branch.base, target_branch.base)
539
502
        opened_branch = branch_dir.open_branch()
548
511
        # then this file read will fail.
549
512
        self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
550
513
        self.assertEqual(reference_url,
551
 
            _mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
 
514
            _mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.bzrdir))
552
515
 
553
516
 
554
517
class TestHooks(tests.TestCaseWithTransport):