2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
1 |
# Copyright (C) 2006 Canonical Ltd
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
17 |
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
18 |
from bzrlib import ( |
19 |
errors, |
|
20 |
ui, |
|
21 |
)
|
|
3015.2.11
by Robert Collins
Handle repositories that do not physically lock in workingtree_implementation tests. |
22 |
from bzrlib.tests import TestNotApplicable |
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
23 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
24 |
|
25 |
||
26 |
class TestBreakLock(TestCaseWithWorkingTree): |
|
27 |
||
28 |
def setUp(self): |
|
29 |
super(TestBreakLock, self).setUp() |
|
30 |
self.unused_workingtree = self.make_branch_and_tree('.') |
|
31 |
self.workingtree = self.unused_workingtree.bzrdir.open_workingtree() |
|
32 |
||
33 |
def test_unlocked(self): |
|
34 |
# break lock when nothing is locked should just return
|
|
35 |
try: |
|
36 |
self.workingtree.break_lock() |
|
37 |
except NotImplementedError: |
|
38 |
pass
|
|
39 |
||
40 |
def test_unlocked_repo_locked(self): |
|
41 |
# break lock on the workingtree should try on the branch even
|
|
42 |
# if the workingtree isn't locked - and the easiest way
|
|
43 |
# to see if that happened is to lock the repo.
|
|
44 |
self.workingtree.branch.repository.lock_write() |
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
45 |
ui.ui_factory = ui.CannedInputUIFactory([True]) |
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
46 |
try: |
47 |
self.unused_workingtree.break_lock() |
|
48 |
except NotImplementedError: |
|
49 |
# workingtree does not support break_lock
|
|
50 |
self.workingtree.branch.repository.unlock() |
|
51 |
return
|
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
52 |
if ui.ui_factory.responses == [True]: |
3015.2.11
by Robert Collins
Handle repositories that do not physically lock in workingtree_implementation tests. |
53 |
raise TestNotApplicable("repository does not physically lock.") |
54 |
self.assertRaises(errors.LockBroken, |
|
55 |
self.workingtree.branch.repository.unlock) |
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
56 |
|
57 |
def test_locked(self): |
|
58 |
# break_lock when locked should
|
|
59 |
self.workingtree.lock_write() |
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
60 |
ui.ui_factory = ui.CannedInputUIFactory([True, True, True]) |
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
61 |
try: |
62 |
self.unused_workingtree.break_lock() |
|
2255.2.149
by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4. |
63 |
except (NotImplementedError, errors.LockActive): |
64 |
# workingtree does not support break_lock,
|
|
65 |
# or does not support breaking a lock held by an alive
|
|
66 |
# object/process.
|
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
67 |
self.workingtree.unlock() |
68 |
return
|
|
69 |
self.assertRaises(errors.LockBroken, self.workingtree.unlock) |