/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2011-04-01 03:07:34 UTC
  • mfrom: (5609.29.3 2.3)
  • mto: (5609.29.4 2.3)
  • mto: This revision was merged to the branch mainline in revision 5755.
  • Revision ID: mbp@canonical.com-20110401030734-wip8a66uf8aphgud
merge up to bzr 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for lock-breaking user interface"""
18
18
 
19
 
import os
20
 
 
21
 
import bzrlib
22
19
from bzrlib import (
 
20
    branch,
 
21
    bzrdir,
 
22
    config,
23
23
    errors,
24
 
    lockdir,
25
 
    )
26
 
from bzrlib.branch import Branch
27
 
from bzrlib.bzrdir import BzrDir
28
 
from bzrlib.tests import TestCaseWithTransport
29
 
 
30
 
 
31
 
class TestBreakLock(TestCaseWithTransport):
 
24
    osutils,
 
25
    tests,
 
26
    )
 
27
from bzrlib.tests.script import (
 
28
    run_script,
 
29
    )
 
30
 
 
31
 
 
32
class TestBreakLock(tests.TestCaseWithTransport):
32
33
 
33
34
    # General principal for break-lock: All the elements that might be locked
34
35
    # by a bzr operation on PATH, are candidates that break-lock may unlock.
52
53
             'repo/',
53
54
             'repo/branch/',
54
55
             'checkout/'])
55
 
        bzrlib.bzrdir.BzrDir.create('master-repo').create_repository()
56
 
        self.master_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
56
        bzrdir.BzrDir.create('master-repo').create_repository()
 
57
        self.master_branch = bzrdir.BzrDir.create_branch_convenience(
57
58
            'master-repo/master-branch')
58
 
        bzrlib.bzrdir.BzrDir.create('repo').create_repository()
59
 
        local_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('repo/branch')
 
59
        bzrdir.BzrDir.create('repo').create_repository()
 
60
        local_branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
60
61
        local_branch.bind(self.master_branch)
61
 
        checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout')
62
 
        bzrlib.branch.BranchReferenceFormat().initialize(
 
62
        checkoutdir = bzrdir.BzrDir.create('checkout')
 
63
        branch.BranchReferenceFormat().initialize(
63
64
            checkoutdir, target_branch=local_branch)
64
65
        self.wt = checkoutdir.create_workingtree()
65
66
 
68
69
        # shouldn't fail and should not produce error output
69
70
        self.assertEqual('', err)
70
71
 
 
72
    def test_break_lock_no_interaction(self):
 
73
        """With --force, the user isn't asked for confirmation"""
 
74
        self.master_branch.lock_write()
 
75
        run_script(self, """
 
76
        $ bzr break-lock --force master-repo/master-branch
 
77
        Broke lock ...master-branch/.bzr/...
 
78
        """)
 
79
        # lock should now be dead
 
80
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
 
81
 
71
82
    def test_break_lock_everything_locked(self):
72
83
        ### if everything is locked, we should be able to unlock the lot.
73
84
        # however, we dont test breaking the working tree because we
74
85
        # cannot accurately do so right now: the dirstate lock is held
75
86
        # by an os lock, and we need to spawn a separate process to lock it
76
 
        # thne kill -9 it.
 
87
        # then kill -9 it.
77
88
        # sketch of test:
78
89
        # lock most of the dir:
79
90
        self.wt.branch.lock_write()
82
93
        # we need 5 yes's - wt, branch, repo, bound branch, bound repo.
83
94
        self.run_bzr('break-lock checkout', stdin="y\ny\ny\ny\n")
84
95
        # a new tree instance should be lockable
85
 
        branch = bzrlib.branch.Branch.open('checkout')
86
 
        branch.lock_write()
87
 
        branch.unlock()
 
96
        br = branch.Branch.open('checkout')
 
97
        br.lock_write()
 
98
        br.unlock()
88
99
        # and a new instance of the master branch
89
 
        mb = branch.get_master_branch()
 
100
        mb = br.get_master_branch()
90
101
        mb.lock_write()
91
102
        mb.unlock()
92
103
        self.assertRaises(errors.LockBroken, self.wt.unlock)
93
104
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
94
105
 
95
106
 
96
 
class TestBreakLockOldBranch(TestCaseWithTransport):
 
107
class TestBreakLockOldBranch(tests.TestCaseWithTransport):
97
108
 
98
109
    def test_break_lock_format_5_bzrdir(self):
99
110
        # break lock on a format 5 bzrdir should just return
100
 
        self.make_branch_and_tree('foo', format=bzrlib.bzrdir.BzrDirFormat5())
 
111
        self.make_branch_and_tree('foo', format=bzrdir.BzrDirFormat5())
101
112
        out, err = self.run_bzr('break-lock foo')
102
113
        self.assertEqual('', out)
103
114
        self.assertEqual('', err)
 
115
 
 
116
class TestConfigBreakLock(tests.TestCaseWithTransport):
 
117
 
 
118
    def setUp(self):
 
119
        super(TestConfigBreakLock, self).setUp()
 
120
        self.config_file_name = './my.conf'
 
121
        self.build_tree_contents([(self.config_file_name,
 
122
                                   '[DEFAULT]\none=1\n')])
 
123
        self.config = config.LockableConfig(file_name=self.config_file_name)
 
124
        self.config.lock_write()
 
125
 
 
126
    def test_create_pending_lock(self):
 
127
        self.addCleanup(self.config.unlock)
 
128
        self.assertTrue(self.config._lock.is_held)
 
129
 
 
130
    def test_break_lock(self):
 
131
        self.run_bzr('break-lock --config %s'
 
132
                     % osutils.dirname(self.config_file_name),
 
133
                     stdin="y\n")
 
134
        self.assertRaises(errors.LockBroken, self.config.unlock)
 
135