/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1687.1.7 by Robert Collins
Teach Repository about break_lock.
16
17
"""Tests for repository break-lock."""
18
19
from cStringIO import StringIO
20
21
import bzrlib
22
import bzrlib.errors as errors
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
23
from bzrlib.tests.per_repository.test_repository import TestCaseWithRepository
1687.1.7 by Robert Collins
Teach Repository about break_lock.
24
from bzrlib.transport import get_transport
25
from bzrlib.workingtree import WorkingTree
4449.3.27 by Martin Pool
More test updates to use CannedInputUIFactory
26
from bzrlib.ui import (
27
    CannedInputUIFactory,
28
    )
1687.1.7 by Robert Collins
Teach Repository about break_lock.
29
30
31
class TestBreakLock(TestCaseWithRepository):
32
33
    def setUp(self):
34
        super(TestBreakLock, self).setUp()
35
        self.unused_repo = self.make_repository('.')
36
        self.repo = self.unused_repo.bzrdir.open_repository()
37
        # we want a UI factory that accepts canned input for the tests:
38
        # while SilentUIFactory still accepts stdin, we need to customise
39
        # ours
40
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
41
        self.addCleanup(self.restoreFactory)
4449.3.27 by Martin Pool
More test updates to use CannedInputUIFactory
42
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1687.1.7 by Robert Collins
Teach Repository about break_lock.
43
1687.1.15 by Robert Collins
Review comments.
44
    def restoreFactory(self):
1687.1.7 by Robert Collins
Teach Repository about break_lock.
45
        bzrlib.ui.ui_factory = self.old_factory
46
47
    def test_unlocked(self):
48
        # break lock when nothing is locked should just return
49
        try:
50
            self.repo.break_lock()
51
        except NotImplementedError:
52
            pass
53
54
    def test_locked(self):
55
        # break_lock when locked should
56
        self.repo.lock_write()
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
57
        self.assertEqual(self.repo.get_physical_lock_status(),
58
            self.unused_repo.get_physical_lock_status())
59
        if not self.unused_repo.get_physical_lock_status():
60
            # 'lock_write' has not taken a physical mutex out.
1687.1.7 by Robert Collins
Teach Repository about break_lock.
61
            self.repo.unlock()
62
            return
2592.3.188 by Robert Collins
Allow pack repositories to have multiple writers active at one time, for greater concurrency.
63
        self.unused_repo.break_lock()
1687.1.7 by Robert Collins
Teach Repository about break_lock.
64
        self.assertRaises(errors.LockBroken, self.repo.unlock)