~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2009 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
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.per_branch.test_branch import TestCaseWithBranch
25
 
from bzrlib.ui import (
26
 
    CannedInputUIFactory,
 
19
from  bzrlib import (
 
20
    errors,
 
21
    ui,
 
22
    tests,
27
23
    )
28
 
 
29
 
 
30
 
class TestBreakLock(TestCaseWithBranch):
 
24
from bzrlib.tests import per_branch
 
25
 
 
26
 
 
27
class TestBreakLock(per_branch.TestCaseWithBranch):
31
28
 
32
29
    def setUp(self):
33
30
        super(TestBreakLock, self).setUp()
34
31
        self.unused_branch = self.make_branch('branch')
35
32
        self.branch = self.unused_branch.bzrdir.open_branch()
36
 
        # we want a UI factory that accepts canned input for the tests:
37
 
        # while SilentUIFactory still accepts stdin, we need to customise
38
 
        # ours
39
 
        self.old_factory = bzrlib.ui.ui_factory
40
 
        self.addCleanup(self.restoreFactory)
41
 
 
42
 
    def restoreFactory(self):
43
 
        bzrlib.ui.ui_factory = self.old_factory
44
33
 
45
34
    def test_unlocked(self):
46
35
        # break lock when nothing is locked should just return
55
44
        token = self.branch.repository.lock_write()
56
45
        if token is None:
57
46
            self.branch.repository.unlock()
58
 
            raise TestNotApplicable('Repository does not use physical locks.')
 
47
            raise tests.TestNotApplicable(
 
48
                'Repository does not use physical locks.')
59
49
        self.branch.repository.leave_lock_in_place()
60
50
        self.branch.repository.unlock()
61
51
        other_instance = self.branch.repository.bzrdir.open_repository()
62
52
        if not other_instance.get_physical_lock_status():
63
 
            raise TestNotApplicable("Repository does not lock persistently.")
64
 
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
 
53
            raise tests.TestNotApplicable(
 
54
                'Repository does not lock persistently.')
 
55
        ui.ui_factory = ui.CannedInputUIFactory([True])
65
56
        try:
66
57
            self.unused_branch.break_lock()
67
58
        except NotImplementedError:
73
64
    def test_locked(self):
74
65
        # break_lock when locked should unlock the branch and repo
75
66
        self.branch.lock_write()
76
 
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True])
 
67
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
77
68
        try:
78
69
            self.unused_branch.break_lock()
79
70
        except NotImplementedError:
92
83
            # this branch does not support binding.
93
84
            return
94
85
        master.lock_write()
95
 
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True])
 
86
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
96
87
        try:
97
88
            self.unused_branch.break_lock()
98
89
        except NotImplementedError: