1
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006-2010 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Tests for branch break-lock behaviour."""
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):
24
from bzrlib.tests import per_branch
27
class TestBreakLock(per_branch.TestCaseWithBranch):
30
30
super(TestBreakLock, self).setUp()
31
31
self.unused_branch = self.make_branch('branch')
32
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
43
34
def test_unlocked(self):
44
35
# break lock when nothing is locked should just return
53
44
token = self.branch.repository.lock_write()
55
46
self.branch.repository.unlock()
56
raise TestNotApplicable('Repository does not use physical locks.')
47
raise tests.TestNotApplicable(
48
'Repository does not use physical locks.')
57
49
self.branch.repository.leave_lock_in_place()
58
50
self.branch.repository.unlock()
59
51
other_instance = self.branch.repository.bzrdir.open_repository()
60
52
if not other_instance.get_physical_lock_status():
61
raise TestNotApplicable("Repository does not lock persistently.")
62
bzrlib.ui.ui_factory.stdin = StringIO("y\n")
53
raise tests.TestNotApplicable(
54
'Repository does not lock persistently.')
55
ui.ui_factory = ui.CannedInputUIFactory([True])
64
57
self.unused_branch.break_lock()
65
58
except NotImplementedError:
71
64
def test_locked(self):
72
65
# break_lock when locked should unlock the branch and repo
73
66
self.branch.lock_write()
74
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
67
ui.ui_factory = ui.CannedInputUIFactory([True, True])
76
69
self.unused_branch.break_lock()
77
70
except NotImplementedError:
81
74
self.assertRaises(errors.LockBroken, self.branch.unlock)
83
76
def test_unlocks_master_branch(self):
84
# break_lock when when the master branch is locked should offer to
77
# break_lock when the master branch is locked should offer to
86
79
master = self.make_branch('master')
90
83
# this branch does not support binding.
92
85
master.lock_write()
93
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
86
ui.ui_factory = ui.CannedInputUIFactory([True, True])
95
88
self.unused_branch.break_lock()
96
89
except NotImplementedError: