~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge cleanup into description

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
import os
20
20
 
21
 
import bzrlib
22
 
import bzrlib.errors as errors
 
21
from bzrlib import (
 
22
    errors,
 
23
    ui,
 
24
    )
23
25
from bzrlib.tests import TestNotApplicable
24
26
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
25
27
 
30
32
        super(TestBreakLock, self).setUp()
31
33
        self.unused_workingtree = self.make_branch_and_tree('.')
32
34
        self.workingtree = self.unused_workingtree.bzrdir.open_workingtree()
33
 
        self.old_factory = bzrlib.ui.ui_factory
34
 
        self.addCleanup(self.restoreFactory)
35
 
 
36
 
    def restoreFactory(self):
37
 
        bzrlib.ui.ui_factory = self.old_factory
38
35
 
39
36
    def test_unlocked(self):
40
37
        # break lock when nothing is locked should just return
48
45
        # if the workingtree isn't locked - and the easiest way
49
46
        # to see if that happened is to lock the repo.
50
47
        self.workingtree.branch.repository.lock_write()
51
 
        bzrlib.ui.ui_factory = bzrlib.ui.CannedInputUIFactory([True])
 
48
        ui.ui_factory = ui.CannedInputUIFactory([True])
52
49
        try:
53
50
            self.unused_workingtree.break_lock()
54
51
        except NotImplementedError:
55
52
            # workingtree does not support break_lock
56
53
            self.workingtree.branch.repository.unlock()
57
54
            return
58
 
        if bzrlib.ui.ui_factory.responses == [True]:
 
55
        if ui.ui_factory.responses == [True]:
59
56
            raise TestNotApplicable("repository does not physically lock.")
60
57
        self.assertRaises(errors.LockBroken,
61
58
            self.workingtree.branch.repository.unlock)
63
60
    def test_locked(self):
64
61
        # break_lock when locked should
65
62
        self.workingtree.lock_write()
66
 
        bzrlib.ui.ui_factory = bzrlib.ui.CannedInputUIFactory([True, True, True])
 
63
        ui.ui_factory = ui.CannedInputUIFactory([True, True, True])
67
64
        try:
68
65
            self.unused_workingtree.break_lock()
69
66
        except (NotImplementedError, errors.LockActive):