1
# Copyright (C) 2006-2012 Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
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
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
17
17
"""Tests for branch break-lock behaviour."""
20
branch as _mod_branch,
25
from bzrlib.tests import per_branch
28
class TestBreakLock(per_branch.TestCaseWithBranch):
19
from cStringIO import StringIO
22
import bzrlib.errors as errors
23
from bzrlib.tests import TestCase, TestCaseWithTransport, TestNotApplicable
24
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
27
class TestBreakLock(TestCaseWithBranch):
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
36
self.old_factory = bzrlib.ui.ui_factory
37
self.addCleanup(self.restoreFactory)
38
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
40
def restoreFactory(self):
41
bzrlib.ui.ui_factory = self.old_factory
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
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")
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")
70
71
self.unused_branch.break_lock()
71
72
except NotImplementedError:
75
76
self.assertRaises(errors.LockBroken, self.branch.unlock)
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
80
81
master = self.make_branch('master')
84
85
# this branch does not support binding.
86
87
master.lock_write()
87
ui.ui_factory = ui.CannedInputUIFactory([True, True])
88
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
89
fresh = _mod_branch.Branch.open(self.unused_branch.base)
90
self.unused_branch.break_lock()
91
91
except NotImplementedError:
92
92
# branch does not support break_lock