/brz/remove-bazaar

To get this branch, use:
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
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1687.1.8 by Robert Collins
Teach Branch 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.8 by Robert Collins
Teach Branch 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.8 by Robert Collins
Teach Branch 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.8 by Robert Collins
Teach Branch about break_lock.
16
17
"""Tests for branch break-lock behaviour."""
18
19
from cStringIO import StringIO
20
21
import bzrlib
22
import bzrlib.errors as errors
3015.2.4 by Robert Collins
Handle repositories that cannot be remotely locked in branch_implementations.test_break_lock.
23
from bzrlib.tests import TestCase, TestCaseWithTransport, TestNotApplicable
1687.1.8 by Robert Collins
Teach Branch about break_lock.
24
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
4449.3.26 by Martin Pool
Change branch break-lock tests to use CannedInputUIFactory
25
from bzrlib.ui import (
26
    CannedInputUIFactory,
27
    )
1687.1.8 by Robert Collins
Teach Branch about break_lock.
28
29
class TestBreakLock(TestCaseWithBranch):
30
31
    def setUp(self):
32
        super(TestBreakLock, self).setUp()
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
33
        self.unused_branch = self.make_branch('branch')
1687.1.8 by Robert Collins
Teach Branch about break_lock.
34
        self.branch = self.unused_branch.bzrdir.open_branch()
35
        # we want a UI factory that accepts canned input for the tests:
36
        # while SilentUIFactory still accepts stdin, we need to customise
37
        # ours
38
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
39
        self.addCleanup(self.restoreFactory)
1687.1.8 by Robert Collins
Teach Branch about break_lock.
40
1687.1.15 by Robert Collins
Review comments.
41
    def restoreFactory(self):
1687.1.8 by Robert Collins
Teach Branch about break_lock.
42
        bzrlib.ui.ui_factory = self.old_factory
43
44
    def test_unlocked(self):
45
        # break lock when nothing is locked should just return
46
        try:
47
            self.branch.break_lock()
48
        except NotImplementedError:
49
            pass
50
51
    def test_unlocked_repo_locked(self):
52
        # break lock on the branch should try on the repository even
53
        # if the branch isn't locked
1551.19.52 by Aaron Bentley
Fix test kipple by unlocking repo
54
        token = self.branch.repository.lock_write()
55
        if token is None:
56
            self.branch.repository.unlock()
57
            raise TestNotApplicable('Repository does not use physical locks.')
58
        self.branch.repository.leave_lock_in_place()
59
        self.branch.repository.unlock()
3015.2.4 by Robert Collins
Handle repositories that cannot be remotely locked in branch_implementations.test_break_lock.
60
        other_instance = self.branch.repository.bzrdir.open_repository()
61
        if not other_instance.get_physical_lock_status():
62
            raise TestNotApplicable("Repository does not lock persistently.")
4449.3.26 by Martin Pool
Change branch break-lock tests to use CannedInputUIFactory
63
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1687.1.8 by Robert Collins
Teach Branch about break_lock.
64
        try:
65
            self.unused_branch.break_lock()
66
        except NotImplementedError:
67
            # branch does not support break_lock
68
            self.branch.repository.unlock()
69
            return
70
        self.assertRaises(errors.LockBroken, self.branch.repository.unlock)
71
72
    def test_locked(self):
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
73
        # break_lock when locked should unlock the branch and repo
1687.1.8 by Robert Collins
Teach Branch about break_lock.
74
        self.branch.lock_write()
4449.3.26 by Martin Pool
Change branch break-lock tests to use CannedInputUIFactory
75
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True])
1687.1.8 by Robert Collins
Teach Branch about break_lock.
76
        try:
77
            self.unused_branch.break_lock()
78
        except NotImplementedError:
79
            # branch does not support break_lock
80
            self.branch.unlock()
81
            return
82
        self.assertRaises(errors.LockBroken, self.branch.unlock)
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
83
84
    def test_unlocks_master_branch(self):
4031.3.1 by Frank Aspell
Fixing various typos
85
        # break_lock when the master branch is locked should offer to
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
86
        # unlock it.
87
        master = self.make_branch('master')
88
        try:
89
            self.branch.bind(master)
90
        except errors.UpgradeRequired:
91
            # this branch does not support binding.
92
            return
93
        master.lock_write()
4449.3.26 by Martin Pool
Change branch break-lock tests to use CannedInputUIFactory
94
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True])
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
95
        try:
96
            self.unused_branch.break_lock()
97
        except NotImplementedError:
98
            # branch does not support break_lock
99
            master.unlock()
100
            return
101
        self.assertRaises(errors.LockBroken, master.unlock)
102
        # can we lock it now ?
103
        master.lock_write()
104
        master.unlock()
105