/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/per_branch/test_break_lock.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
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
12
12
#
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
16
16
 
17
17
"""Tests for branch break-lock behaviour."""
18
18
 
19
 
from cStringIO import StringIO
20
 
 
21
 
import bzrlib
22
 
import bzrlib.errors as errors
23
 
from bzrlib.tests import TestCase, TestCaseWithTransport, TestNotApplicable
24
 
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
25
 
 
26
 
 
27
 
class TestBreakLock(TestCaseWithBranch):
 
19
from  bzrlib import (
 
20
    errors,
 
21
    ui,
 
22
    tests,
 
23
    )
 
24
from bzrlib.tests import per_branch
 
25
 
 
26
 
 
27
class TestBreakLock(per_branch.TestCaseWithBranch):
28
28
 
29
29
    def setUp(self):
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
35
 
        # ours
36
 
        self.old_factory = bzrlib.ui.ui_factory
37
 
        self.addCleanup(self.restoreFactory)
38
 
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
39
 
 
40
 
    def restoreFactory(self):
41
 
        bzrlib.ui.ui_factory = self.old_factory
42
33
 
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()
54
45
        if token is None:
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])
63
56
        try:
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])
75
68
        try:
76
69
            self.unused_branch.break_lock()
77
70
        except NotImplementedError:
81
74
        self.assertRaises(errors.LockBroken, self.branch.unlock)
82
75
 
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
85
78
        # unlock it.
86
79
        master = self.make_branch('master')
87
80
        try:
90
83
            # this branch does not support binding.
91
84
            return
92
85
        master.lock_write()
93
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\n")
 
86
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
94
87
        try:
95
88
            self.unused_branch.break_lock()
96
89
        except NotImplementedError: