/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1687.1.8 by Robert Collins
Teach Branch about break_lock.
1
# (C) 2006 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1687.1.8 by Robert Collins
Teach Branch about break_lock.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1687.1.8 by Robert Collins
Teach Branch about break_lock.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1687.1.8 by Robert Collins
Teach Branch about break_lock.
13
# You should have received a copy of the GNU General Public License
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
16
17
"""Tests for branch break-lock behaviour."""
18
19
from cStringIO import StringIO
20
21
import bzrlib
22
import bzrlib.errors as errors
23
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
24
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
25
26
27
class TestBreakLock(TestCaseWithBranch):
28
29
    def setUp(self):
30
        super(TestBreakLock, self).setUp()
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
31
        self.unused_branch = self.make_branch('branch')
1687.1.8 by Robert Collins
Teach Branch about break_lock.
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
1687.1.15 by Robert Collins
Review comments.
37
        self.addCleanup(self.restoreFactory)
1687.1.8 by Robert Collins
Teach Branch about break_lock.
38
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
39
1687.1.15 by Robert Collins
Review comments.
40
    def restoreFactory(self):
1687.1.8 by Robert Collins
Teach Branch about break_lock.
41
        bzrlib.ui.ui_factory = self.old_factory
42
43
    def test_unlocked(self):
44
        # break lock when nothing is locked should just return
45
        try:
46
            self.branch.break_lock()
47
        except NotImplementedError:
48
            pass
49
50
    def test_unlocked_repo_locked(self):
51
        # break lock on the branch should try on the repository even
52
        # if the branch isn't locked
53
        self.branch.repository.lock_write()
54
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
55
        try:
56
            self.unused_branch.break_lock()
57
        except NotImplementedError:
58
            # branch does not support break_lock
59
            self.branch.repository.unlock()
60
            return
61
        self.assertRaises(errors.LockBroken, self.branch.repository.unlock)
62
63
    def test_locked(self):
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
64
        # break_lock when locked should unlock the branch and repo
1687.1.8 by Robert Collins
Teach Branch about break_lock.
65
        self.branch.lock_write()
66
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
67
        try:
68
            self.unused_branch.break_lock()
69
        except NotImplementedError:
70
            # branch does not support break_lock
71
            self.branch.unlock()
72
            return
73
        self.assertRaises(errors.LockBroken, self.branch.unlock)
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
74
75
    def test_unlocks_master_branch(self):
76
        # break_lock when when the master branch is locked should offer to
77
        # unlock it.
78
        master = self.make_branch('master')
79
        try:
80
            self.branch.bind(master)
81
        except errors.UpgradeRequired:
82
            # this branch does not support binding.
83
            return
84
        master.lock_write()
85
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
86
        try:
87
            self.unused_branch.break_lock()
88
        except NotImplementedError:
89
            # branch does not support break_lock
90
            master.unlock()
91
            return
92
        self.assertRaises(errors.LockBroken, master.unlock)
93
        # can we lock it now ?
94
        master.lock_write()
95
        master.unlock()
96