~greatmay12/+junk/test1

« back to all changes in this revision

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

  • Committer: thitipong at ndrsolution
  • Date: 2011-11-14 06:31:02 UTC
  • Revision ID: thitipong@ndrsolution.com-20111114063102-9obte3yfi2azku7d
ndr redirect version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
# Authors:  Robert Collins <robert.collins@canonical.com>
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
from cStringIO import StringIO
 
19
import os
 
20
 
 
21
from bzrlib import (
 
22
    errors,
 
23
    ui,
 
24
    )
 
25
from bzrlib.tests import TestNotApplicable
 
26
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
 
27
 
 
28
 
 
29
class TestBreakLock(TestCaseWithWorkingTree):
 
30
 
 
31
    def setUp(self):
 
32
        super(TestBreakLock, self).setUp()
 
33
        self.unused_workingtree = self.make_branch_and_tree('.')
 
34
        self.workingtree = self.unused_workingtree.bzrdir.open_workingtree()
 
35
 
 
36
    def test_unlocked(self):
 
37
        # break lock when nothing is locked should just return
 
38
        try:
 
39
            self.workingtree.break_lock()
 
40
        except NotImplementedError:
 
41
            pass
 
42
 
 
43
    def test_unlocked_repo_locked(self):
 
44
        # break lock on the workingtree should try on the branch even
 
45
        # if the workingtree isn't locked - and the easiest way
 
46
        # to see if that happened is to lock the repo.
 
47
        self.workingtree.branch.repository.lock_write()
 
48
        ui.ui_factory = ui.CannedInputUIFactory([True])
 
49
        try:
 
50
            self.unused_workingtree.break_lock()
 
51
        except NotImplementedError:
 
52
            # workingtree does not support break_lock
 
53
            self.workingtree.branch.repository.unlock()
 
54
            return
 
55
        if ui.ui_factory.responses == [True]:
 
56
            raise TestNotApplicable("repository does not physically lock.")
 
57
        self.assertRaises(errors.LockBroken,
 
58
            self.workingtree.branch.repository.unlock)
 
59
 
 
60
    def test_locked(self):
 
61
        # break_lock when locked should
 
62
        self.workingtree.lock_write()
 
63
        ui.ui_factory = ui.CannedInputUIFactory([True, True, True])
 
64
        try:
 
65
            self.unused_workingtree.break_lock()
 
66
        except (NotImplementedError, errors.LockActive):
 
67
            # workingtree does not support break_lock,
 
68
            # or does not support breaking a lock held by an alive
 
69
            # object/process.
 
70
            self.workingtree.unlock()
 
71
            return
 
72
        self.assertRaises(errors.LockBroken, self.workingtree.unlock)