2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2006 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1687.1.7
by Robert Collins
Teach Repository about break_lock. |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1687.1.7
by Robert Collins
Teach Repository about break_lock. |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1687.1.7
by Robert Collins
Teach Repository about break_lock. |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Tests for repository break-lock."""
|
|
18 |
||
19 |
from cStringIO import StringIO |
|
20 |
||
21 |
import bzrlib |
|
22 |
import bzrlib.errors as errors |
|
23 |
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository |
|
24 |
from bzrlib.transport import get_transport |
|
25 |
from bzrlib.workingtree import WorkingTree |
|
26 |
||
27 |
||
28 |
class TestBreakLock(TestCaseWithRepository): |
|
29 |
||
30 |
def setUp(self): |
|
31 |
super(TestBreakLock, self).setUp() |
|
32 |
self.unused_repo = self.make_repository('.') |
|
33 |
self.repo = self.unused_repo.bzrdir.open_repository() |
|
34 |
# we want a UI factory that accepts canned input for the tests:
|
|
35 |
# while SilentUIFactory still accepts stdin, we need to customise
|
|
36 |
# ours
|
|
37 |
self.old_factory = bzrlib.ui.ui_factory |
|
1687.1.15
by Robert Collins
Review comments. |
38 |
self.addCleanup(self.restoreFactory) |
1687.1.7
by Robert Collins
Teach Repository about break_lock. |
39 |
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory() |
40 |
bzrlib.ui.ui_factory.stdin = StringIO("y\n") |
|
41 |
||
1687.1.15
by Robert Collins
Review comments. |
42 |
def restoreFactory(self): |
1687.1.7
by Robert Collins
Teach Repository about break_lock. |
43 |
bzrlib.ui.ui_factory = self.old_factory |
44 |
||
45 |
def test_unlocked(self): |
|
46 |
# break lock when nothing is locked should just return
|
|
47 |
try: |
|
48 |
self.repo.break_lock() |
|
49 |
except NotImplementedError: |
|
50 |
pass
|
|
51 |
||
52 |
def test_locked(self): |
|
53 |
# break_lock when locked should
|
|
54 |
self.repo.lock_write() |
|
55 |
try: |
|
56 |
self.unused_repo.break_lock() |
|
57 |
except NotImplementedError: |
|
58 |
# repository does not support break_lock
|
|
59 |
self.repo.unlock() |
|
60 |
return
|
|
61 |
self.assertRaises(errors.LockBroken, self.repo.unlock) |