bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
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
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
from cStringIO import StringIO |
|
19 |
import os |
|
20 |
||
21 |
import bzrlib |
|
22 |
import bzrlib.errors as errors |
|
23 |
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree |
|
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 |
# we want a UI factory that accepts canned input for the tests:
|
|
33 |
# while SilentUIFactory still accepts stdin, we need to customise
|
|
34 |
# ours
|
|
35 |
self.old_factory = bzrlib.ui.ui_factory |
|
|
1687.1.15
by Robert Collins
Review comments. |
36 |
self.addCleanup(self.restoreFactory) |
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
37 |
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory() |
38 |
||
|
1687.1.15
by Robert Collins
Review comments. |
39 |
def restoreFactory(self): |
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
40 |
bzrlib.ui.ui_factory = self.old_factory |
41 |
||
42 |
def test_unlocked(self): |
|
43 |
# break lock when nothing is locked should just return
|
|
44 |
try: |
|
45 |
self.workingtree.break_lock() |
|
46 |
except NotImplementedError: |
|
47 |
pass
|
|
48 |
||
49 |
def test_unlocked_repo_locked(self): |
|
50 |
# break lock on the workingtree should try on the branch even
|
|
51 |
# if the workingtree isn't locked - and the easiest way
|
|
52 |
# to see if that happened is to lock the repo.
|
|
53 |
self.workingtree.branch.repository.lock_write() |
|
54 |
bzrlib.ui.ui_factory.stdin = StringIO("y\n") |
|
55 |
try: |
|
56 |
self.unused_workingtree.break_lock() |
|
57 |
except NotImplementedError: |
|
58 |
# workingtree does not support break_lock
|
|
59 |
self.workingtree.branch.repository.unlock() |
|
60 |
return
|
|
61 |
self.assertRaises(errors.LockBroken, self.workingtree.branch.repository.unlock) |
|
62 |
||
63 |
def test_locked(self): |
|
64 |
# break_lock when locked should
|
|
65 |
self.workingtree.lock_write() |
|
66 |
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n") |
|
67 |
try: |
|
68 |
self.unused_workingtree.break_lock() |
|
|
2255.2.149
by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4. |
69 |
except (NotImplementedError, errors.LockActive): |
70 |
# workingtree does not support break_lock,
|
|
71 |
# or does not support breaking a lock held by an alive
|
|
72 |
# object/process.
|
|
|
1687.1.9
by Robert Collins
Teach WorkingTree about break-lock. |
73 |
self.workingtree.unlock() |
74 |
return
|
|
75 |
self.assertRaises(errors.LockBroken, self.workingtree.unlock) |