~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
    branch as _mod_branch,
29
29
    bzrdir,
30
30
    config,
 
31
    controldir,
31
32
    errors,
32
 
    symbol_versioning,
33
33
    tests,
34
34
    trace,
35
35
    urlutils,
36
36
    )
 
37
from bzrlib.branchfmt.fullhistory import (
 
38
    BzrBranch5,
 
39
    BzrBranchFormat5,
 
40
    )
37
41
 
38
42
 
39
43
class TestDefaultFormat(tests.TestCase):
74
78
        url = self.get_url()
75
79
        bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
76
80
        bdir.create_repository()
77
 
        branch = _mod_branch.BzrBranchFormat5().initialize(bdir)
 
81
        branch = BzrBranchFormat5().initialize(bdir)
78
82
        t = self.get_transport()
79
83
        self.log("branch instance is %r" % branch)
80
 
        self.assert_(isinstance(branch, _mod_branch.BzrBranch5))
 
84
        self.assertTrue(isinstance(branch, BzrBranch5))
81
85
        self.assertIsDirectory('.', t)
82
86
        self.assertIsDirectory('.bzr/branch', t)
83
87
        self.assertIsDirectory('.bzr/branch/lock', t)
184
188
            format.initialize(dir)
185
189
            found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
186
190
            self.assertIsInstance(found_format, format.__class__)
187
 
        check_format(_mod_branch.BzrBranchFormat5(), "bar")
 
191
        check_format(BzrBranchFormat5(), "bar")
188
192
 
189
193
    def test_find_format_factory(self):
190
194
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
222
226
        tree.branch.update_feature_flags({"name": "optional"})
223
227
        found_format = _mod_branch.BranchFormatMetadir.find_format(tree.bzrdir)
224
228
        self.assertIsInstance(found_format, _mod_branch.BranchFormatMetadir)
225
 
        self.assertEquals(found_format.features.get("name"), "optional")
 
229
        self.assertEqual(found_format.features.get("name"), "optional")
226
230
        tree.branch.update_feature_flags({"name": None})
227
231
        branch = _mod_branch.Branch.open('.')
228
 
        self.assertEquals(branch._format.features, {})
229
 
 
230
 
    def test_register_unregister_format(self):
231
 
        # Test the deprecated format registration functions
232
 
        format = SampleBranchFormat()
233
 
        # make a control dir
234
 
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
235
 
        # make a branch
236
 
        format.initialize(dir)
237
 
        # register a format for it.
238
 
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
239
 
            _mod_branch.BranchFormat.register_format, format)
240
 
        # which branch.Open will refuse (not supported)
241
 
        self.assertRaises(errors.UnsupportedFormatError,
242
 
                          _mod_branch.Branch.open, self.get_url())
243
 
        self.make_branch_and_tree('foo')
244
 
        # but open_downlevel will work
245
 
        self.assertEqual(
246
 
            format.open(dir),
247
 
            bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
248
 
        # unregister the format
249
 
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
250
 
            _mod_branch.BranchFormat.unregister_format, format)
251
 
        self.make_branch_and_tree('bar')
 
232
        self.assertEqual(branch._format.features, {})
252
233
 
253
234
 
254
235
class TestBranchFormatRegistry(tests.TestCase):
261
242
        self.assertIs(None, self.registry.get_default())
262
243
        format = SampleBranchFormat()
263
244
        self.registry.set_default(format)
264
 
        self.assertEquals(format, self.registry.get_default())
 
245
        self.assertEqual(format, self.registry.get_default())
265
246
 
266
247
    def test_register_unregister_format(self):
267
248
        format = SampleBranchFormat()
268
249
        self.registry.register(format)
269
 
        self.assertEquals(format,
 
250
        self.assertEqual(format,
270
251
            self.registry.get("Sample branch format."))
271
252
        self.registry.remove(format)
272
253
        self.assertRaises(KeyError, self.registry.get,
274
255
 
275
256
    def test_get_all(self):
276
257
        format = SampleBranchFormat()
277
 
        self.assertEquals([], self.registry._get_all())
 
258
        self.assertEqual([], self.registry._get_all())
278
259
        self.registry.register(format)
279
 
        self.assertEquals([format], self.registry._get_all())
 
260
        self.assertEqual([format], self.registry._get_all())
280
261
 
281
262
    def test_register_extra(self):
282
263
        format = SampleExtraBranchFormat()
283
 
        self.assertEquals([], self.registry._get_all())
 
264
        self.assertEqual([], self.registry._get_all())
284
265
        self.registry.register_extra(format)
285
 
        self.assertEquals([format], self.registry._get_all())
 
266
        self.assertEqual([format], self.registry._get_all())
286
267
 
287
268
    def test_register_extra_lazy(self):
288
 
        self.assertEquals([], self.registry._get_all())
 
269
        self.assertEqual([], self.registry._get_all())
289
270
        self.registry.register_extra_lazy("bzrlib.tests.test_branch",
290
271
            "SampleExtraBranchFormat")
291
272
        formats = self.registry._get_all()
292
 
        self.assertEquals(1, len(formats))
 
273
        self.assertEqual(1, len(formats))
293
274
        self.assertIsInstance(formats[0], SampleExtraBranchFormat)
294
275
 
295
276
 
356
337
        self.assertPathDoesNotExist('a/.bzr/branch/parent')
357
338
        self.assertEqual('http://example.com', branch.get_parent())
358
339
        branch.set_push_location('sftp://example.com')
359
 
        config = branch.get_config_stack()
360
 
        self.assertEqual('sftp://example.com', config.get('push_location'))
 
340
        conf = branch.get_config_stack()
 
341
        self.assertEqual('sftp://example.com', conf.get('push_location'))
361
342
        branch.set_bound_location('ftp://example.com')
362
343
        self.assertPathDoesNotExist('a/.bzr/branch/bound')
363
344
        self.assertEqual('ftp://example.com', branch.get_bound_location())
364
345
 
365
 
    def test_set_revision_history(self):
366
 
        builder = self.make_branch_builder('.', format=self.get_format_name())
367
 
        builder.build_snapshot('foo', None,
368
 
            [('add', ('', None, 'directory', None))],
369
 
            message='foo')
370
 
        builder.build_snapshot('bar', None, [], message='bar')
371
 
        branch = builder.get_branch()
372
 
        branch.lock_write()
373
 
        self.addCleanup(branch.unlock)
374
 
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
375
 
            branch.set_revision_history, ['foo', 'bar'])
376
 
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
377
 
                branch.set_revision_history, ['foo'])
378
 
        self.assertRaises(errors.NotLefthandHistory,
379
 
            self.applyDeprecated, symbol_versioning.deprecated_in((2, 4, 0)),
380
 
            branch.set_revision_history, ['bar'])
381
 
 
382
346
    def do_checkout_test(self, lightweight=False):
383
347
        tree = self.make_branch_and_tree('source',
384
348
            format=self.get_format_name_subtree())
488
452
 
489
453
    def make_branch(self, location, format=None):
490
454
        if format is None:
491
 
            format = bzrdir.format_registry.make_bzrdir('1.9')
 
455
            format = controldir.format_registry.make_bzrdir('1.9')
492
456
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
493
457
        return tests.TestCaseWithTransport.make_branch(
494
458
            self, location, format=format)
591
555
    def test_constructor(self):
592
556
        """Check that creating a BranchHooks instance has the right defaults."""
593
557
        hooks = _mod_branch.BranchHooks()
594
 
        self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
595
558
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
596
559
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
597
560
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
671
634
                         self.branch.get_append_revisions_only())
672
635
 
673
636
    def test_valid_append_revisions_only(self):
674
 
        self.assertEquals(None,
 
637
        self.assertEqual(None,
675
638
                          self.config_stack.get('append_revisions_only'))
676
639
        self.check_append_revisions_only(None)
677
640
        self.check_append_revisions_only(False, 'False')
693
656
            'Value "not-a-bool" is not valid for "append_revisions_only"',
694
657
            self.warnings[0])
695
658
 
 
659
    def test_use_fresh_values(self):
 
660
        copy = _mod_branch.Branch.open(self.branch.base)
 
661
        copy.lock_write()
 
662
        try:
 
663
            copy.get_config_stack().set('foo', 'bar')
 
664
        finally:
 
665
            copy.unlock()
 
666
        self.assertFalse(self.branch.is_locked())
 
667
        # Since the branch is locked, the option value won't be saved on disk
 
668
        # so trying to access the config of locked branch via another older
 
669
        # non-locked branch object pointing to the same branch is not supported
 
670
        self.assertEqual(None, self.branch.get_config_stack().get('foo'))
 
671
        # Using a newly created branch object works as expected
 
672
        fresh = _mod_branch.Branch.open(self.branch.base)
 
673
        self.assertEqual('bar', fresh.get_config_stack().get('foo'))
 
674
 
 
675
    def test_set_from_config_get_from_config_stack(self):
 
676
        self.branch.lock_write()
 
677
        self.addCleanup(self.branch.unlock)
 
678
        self.branch.get_config().set_user_option('foo', 'bar')
 
679
        result = self.branch.get_config_stack().get('foo')
 
680
        # https://bugs.launchpad.net/bzr/+bug/948344
 
681
        self.expectFailure('BranchStack uses cache after set_user_option',
 
682
                           self.assertEqual, 'bar', result)
 
683
 
 
684
    def test_set_from_config_stack_get_from_config(self):
 
685
        self.branch.lock_write()
 
686
        self.addCleanup(self.branch.unlock)
 
687
        self.branch.get_config_stack().set('foo', 'bar')
 
688
        # Since the branch is locked, the option value won't be saved on disk
 
689
        # so mixing get() and get_user_option() is broken by design.
 
690
        self.assertEqual(None,
 
691
                         self.branch.get_config().get_user_option('foo'))
 
692
 
 
693
    def test_set_delays_write_when_branch_is_locked(self):
 
694
        self.branch.lock_write()
 
695
        self.addCleanup(self.branch.unlock)
 
696
        self.branch.get_config_stack().set('foo', 'bar')
 
697
        copy = _mod_branch.Branch.open(self.branch.base)
 
698
        result = copy.get_config_stack().get('foo')
 
699
        # Accessing from a different branch object is like accessing from a
 
700
        # different process: the option has not been saved yet and the new
 
701
        # value cannot be seen.
 
702
        self.assertIs(None, result)
 
703
 
696
704
 
697
705
class TestPullResult(tests.TestCase):
698
706
 
699
 
    def test_pull_result_to_int(self):
700
 
        # to support old code, the pull result can be used as an int
701
 
        r = _mod_branch.PullResult()
702
 
        r.old_revno = 10
703
 
        r.new_revno = 20
704
 
        # this usage of results is not recommended for new code (because it
705
 
        # doesn't describe very well what happened), but for api stability
706
 
        # it's still supported
707
 
        self.assertEqual(self.applyDeprecated(
708
 
            symbol_versioning.deprecated_in((2, 3, 0)),
709
 
            r.__int__),
710
 
            10)
711
 
 
712
707
    def test_report_changed(self):
713
708
        r = _mod_branch.PullResult()
714
709
        r.old_revid = "old-revid"