~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_branch.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012 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
205
205
    def test_public_branch(self):
206
206
        """public location can be queried and set"""
207
207
        branch = self.make_branch('branch')
 
208
        self.addCleanup(branch.lock_write().unlock)
208
209
        self.assertEqual(branch.get_public_branch(), None)
209
210
        branch.set_public_branch('sftp://example.com')
210
211
        self.assertEqual(branch.get_public_branch(), 'sftp://example.com')
348
349
 
349
350
    def test_get_set_append_revisions_only(self):
350
351
        branch = self.make_branch('.')
 
352
        self.addCleanup(branch.lock_write().unlock)
351
353
        if branch._format.supports_set_append_revisions_only():
352
354
            branch.set_append_revisions_only(True)
353
355
            self.assertTrue(branch.get_append_revisions_only())
638
640
 
639
641
    def test_set_push_location(self):
640
642
        branch = self.get_branch()
 
643
        self.addCleanup(branch.lock_write().unlock)
641
644
        branch.set_push_location('foo')
642
645
        self.assertEqual('foo', branch.get_push_location())
643
646
 
651
654
 
652
655
    def test_get_child_submit_format(self):
653
656
        branch = self.get_branch()
 
657
        self.addCleanup(branch.lock_write().unlock)
654
658
        branch.get_config().set_user_option('child_submit_format', '10')
655
659
        branch = self.get_branch()
656
660
        self.assertEqual('10', branch.get_child_submit_format())
774
778
        branch.unbind()
775
779
        self.assertEqual(None, branch.get_master_branch())
776
780
 
777
 
    def test_unlocked_does_not_cache_master_branch(self):
778
 
        """Unlocked branches do not cache the result of get_master_branch."""
779
 
        master = self.make_branch('master')
780
 
        branch1 = self.make_branch('branch')
781
 
        try:
782
 
            branch1.bind(master)
783
 
        except errors.UpgradeRequired:
784
 
            raise tests.TestNotApplicable('Format does not support binding')
785
 
        # Open branch1 again
786
 
        branch2 = branch1.bzrdir.open_branch()
787
 
        self.assertNotEqual(None, branch1.get_master_branch())
788
 
        # Unbind the branch via branch2.  branch1 isn't locked so will
789
 
        # immediately return the new value for get_master_branch.
790
 
        branch2.unbind()
791
 
        self.assertEqual(None, branch1.get_master_branch())
792
 
 
793
781
    def test_bind_clears_cached_master_branch(self):
794
782
        """b.bind clears any cached value of b.get_master_branch."""
795
783
        master1 = self.make_branch('master1')
827
815
    def test_strict_history(self):
828
816
        tree1 = self.make_branch_and_tree('tree1')
829
817
        try:
830
 
            tree1.branch.set_append_revisions_only(True)
 
818
            tree1.branch.lock_write()
 
819
            try:
 
820
                tree1.branch.set_append_revisions_only(True)
 
821
            finally:
 
822
                tree1.branch.unlock()
831
823
        except errors.UpgradeRequired:
832
824
            raise tests.TestSkipped('Format does not support strict history')
833
825
        tree1.commit('empty commit')