~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_break_lock.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for branch break-lock behaviour."""
18
18
 
19
 
from bzrlib import (
20
 
    branch as _mod_branch,
21
 
    errors,
22
 
    ui,
23
 
    tests,
24
 
    )
25
 
from bzrlib.tests import per_branch
26
 
 
27
 
 
28
 
class TestBreakLock(per_branch.TestCaseWithBranch):
 
19
from cStringIO import StringIO
 
20
 
 
21
import bzrlib
 
22
import bzrlib.errors as errors
 
23
from bzrlib.tests import TestCase, TestCaseWithTransport, TestNotApplicable
 
24
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
25
 
 
26
 
 
27
class TestBreakLock(TestCaseWithBranch):
29
28
 
30
29
    def setUp(self):
31
30
        super(TestBreakLock, self).setUp()
32
31
        self.unused_branch = self.make_branch('branch')
33
 
        self.branch = _mod_branch.Branch.open(self.unused_branch.base)
 
32
        self.branch = self.unused_branch.bzrdir.open_branch()
 
33
        # we want a UI factory that accepts canned input for the tests:
 
34
        # while SilentUIFactory still accepts stdin, we need to customise
 
35
        # ours
 
36
        self.old_factory = bzrlib.ui.ui_factory
 
37
        self.addCleanup(self.restoreFactory)
 
38
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
 
39
 
 
40
    def restoreFactory(self):
 
41
        bzrlib.ui.ui_factory = self.old_factory
34
42
 
35
43
    def test_unlocked(self):
36
44
        # break lock when nothing is locked should just return
42
50
    def test_unlocked_repo_locked(self):
43
51
        # break lock on the branch should try on the repository even
44
52
        # if the branch isn't locked
45
 
        token = self.branch.repository.lock_write().repository_token
46
 
        if token is None:
47
 
            self.branch.repository.unlock()
48
 
            raise tests.TestNotApplicable(
49
 
                'Repository does not use physical locks.')
50
 
        self.branch.repository.leave_lock_in_place()
51
 
        self.branch.repository.unlock()
 
53
        self.branch.repository.lock_write()
52
54
        other_instance = self.branch.repository.bzrdir.open_repository()
53
55
        if not other_instance.get_physical_lock_status():
54
 
            raise tests.TestNotApplicable(
55
 
                'Repository does not lock persistently.')
56
 
        ui.ui_factory = ui.CannedInputUIFactory([True])
 
56
            raise TestNotApplicable("Repository does not lock persistently.")
 
57
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
57
58
        try:
58
59
            self.unused_branch.break_lock()
59
60
        except NotImplementedError:
65
66
    def test_locked(self):
66
67
        # break_lock when locked should unlock the branch and repo
67
68
        self.branch.lock_write()
68
 
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
 
69
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
69
70
        try:
70
71
            self.unused_branch.break_lock()
71
72
        except NotImplementedError:
75
76
        self.assertRaises(errors.LockBroken, self.branch.unlock)
76
77
 
77
78
    def test_unlocks_master_branch(self):
78
 
        # break_lock when the master branch is locked should offer to
 
79
        # break_lock when when the master branch is locked should offer to
79
80
        # unlock it.
80
81
        master = self.make_branch('master')
81
82
        try:
84
85
            # this branch does not support binding.
85
86
            return
86
87
        master.lock_write()
87
 
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
 
88
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
88
89
        try:
89
 
            fresh = _mod_branch.Branch.open(self.unused_branch.base)
90
 
            fresh.break_lock()
 
90
            self.unused_branch.break_lock()
91
91
        except NotImplementedError:
92
92
            # branch does not support break_lock
93
93
            master.unlock()