21
21
from bzrlib.branch import Branch
22
22
from bzrlib.bzrdir import BzrDir
23
from bzrlib.tests import TestCaseInTempDir
25
class TestBreakLock(TestCaseInTempDir):
23
from bzrlib.tests.blackbox import ExternalBase
26
class TestBreakLock(ExternalBase):
28
# General principal for break-lock: All the elements that might be locked
29
# by a bzr operation on PATH, are candidates that break-lock may unlock.
30
# so pathologically if we have a lightweight checkout A, of branch B, which
31
# is bound to location C, the following things should be checked for locks
35
# wt.branch.repository
36
# wt.branch.get_master_branch()
37
# wt.branch.get_master_branch().repository
38
# so for smoke tests all we need is a bound branch with a checkout of that
39
# and we can then use different urls to test individual cases, for as much
40
# granularity as needed.
43
super(TestBreakLock, self).setUp()
46
'master-repo/master-branch/',
50
bzrlib.bzrdir.BzrDir.create('master-repo').create_repository()
51
self.master_branch = bzrlib.bzrdir.create_branch_convenience(
52
'master-repo/master-branch')
53
bzrlib.bzrdir.BzrDir.create('repo').create_repository()
54
bzrlib.bzrdir.create_branch_convenience('repo/branch')
55
local_branch = bzrlib.bzrdir.create_branch_convenience('repo/branch')
56
local_branch.bind(self.master_branch)
57
checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout')
58
bzrlib.branch.BranchReferenceFormat().initialize(
59
checkoutdir, local_branch)
60
self.wt = bzrlib.workingtree.WorkingTree.open('checkout')
26
62
def test_break_lock_help(self):
27
self.run_bzr('break-lock', '--help')
30
def test_show_no_lock(self):
31
wt = BzrDir.create_standalone_workingtree('.')
32
# out, err = self.run_bzr('break-lock', '--show', '.', retcode=3)
33
# shouldn't see any information
34
# self.assertContainsRe(err, 'not locked')
63
out, err = self.run_bzr('break-lock', '--help')
64
# shouldn't fail and should not produce error output
65
self.assertEqual('', err)
67
def test_break_lock_everything_locked(self):
68
### if everything is locked, we should be able to unlock the lot.
70
# setup a ui factory with precanned answers to the 'should I break lock
72
bzrlib.ui.ui_factory = ...
75
self.master_branch.lock_write()
77
self.run_bzr('break-lock', 'checkout')
78
# restore (in a finally) the ui
79
bzrlib.ui.ui_factory = originalfactory