~bzr-pqm/bzr/bzr.dev

4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2006-2010 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
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
19
from  bzrlib import (
20
    errors,
21
    ui,
5010.2.11 by Vincent Ladeuil
Fix imports in per_branch/test_break_lock.py.
22
    tests,
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
23
    )
5010.2.11 by Vincent Ladeuil
Fix imports in per_branch/test_break_lock.py.
24
from bzrlib.tests import per_branch
25
26
27
class TestBreakLock(per_branch.TestCaseWithBranch):
1687.1.8 by Robert Collins
Teach Branch about break_lock.
28
29
    def setUp(self):
30
        super(TestBreakLock, self).setUp()
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
31
        self.unused_branch = self.make_branch('branch')
1687.1.8 by Robert Collins
Teach Branch about break_lock.
32
        self.branch = self.unused_branch.bzrdir.open_branch()
33
34
    def test_unlocked(self):
35
        # break lock when nothing is locked should just return
36
        try:
37
            self.branch.break_lock()
38
        except NotImplementedError:
39
            pass
40
41
    def test_unlocked_repo_locked(self):
42
        # break lock on the branch should try on the repository even
43
        # if the branch isn't locked
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
44
        token = self.branch.repository.lock_write().repository_token
1551.19.52 by Aaron Bentley
Fix test kipple by unlocking repo
45
        if token is None:
46
            self.branch.repository.unlock()
5010.2.11 by Vincent Ladeuil
Fix imports in per_branch/test_break_lock.py.
47
            raise tests.TestNotApplicable(
48
                'Repository does not use physical locks.')
1551.19.52 by Aaron Bentley
Fix test kipple by unlocking repo
49
        self.branch.repository.leave_lock_in_place()
50
        self.branch.repository.unlock()
3015.2.4 by Robert Collins
Handle repositories that cannot be remotely locked in branch_implementations.test_break_lock.
51
        other_instance = self.branch.repository.bzrdir.open_repository()
52
        if not other_instance.get_physical_lock_status():
5010.2.11 by Vincent Ladeuil
Fix imports in per_branch/test_break_lock.py.
53
            raise tests.TestNotApplicable(
54
                'Repository does not lock persistently.')
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
55
        ui.ui_factory = ui.CannedInputUIFactory([True])
1687.1.8 by Robert Collins
Teach Branch about break_lock.
56
        try:
57
            self.unused_branch.break_lock()
58
        except NotImplementedError:
59
            # branch does not support break_lock
60
            self.branch.repository.unlock()
61
            return
62
        self.assertRaises(errors.LockBroken, self.branch.repository.unlock)
63
64
    def test_locked(self):
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
65
        # break_lock when locked should unlock the branch and repo
1687.1.8 by Robert Collins
Teach Branch about break_lock.
66
        self.branch.lock_write()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
67
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
1687.1.8 by Robert Collins
Teach Branch about break_lock.
68
        try:
69
            self.unused_branch.break_lock()
70
        except NotImplementedError:
71
            # branch does not support break_lock
72
            self.branch.unlock()
73
            return
74
        self.assertRaises(errors.LockBroken, self.branch.unlock)
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
75
76
    def test_unlocks_master_branch(self):
4031.3.1 by Frank Aspell
Fixing various typos
77
        # 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
78
        # unlock it.
79
        master = self.make_branch('master')
80
        try:
81
            self.branch.bind(master)
82
        except errors.UpgradeRequired:
83
            # this branch does not support binding.
84
            return
85
        master.lock_write()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
86
        ui.ui_factory = ui.CannedInputUIFactory([True, True])
1687.1.10 by Robert Collins
Branch.break_lock should handle bound branches too
87
        try:
88
            self.unused_branch.break_lock()
89
        except NotImplementedError:
90
            # branch does not support break_lock
91
            master.unlock()
92
            return
93
        self.assertRaises(errors.LockBroken, master.unlock)
94
        # can we lock it now ?
95
        master.lock_write()
96
        master.unlock()
97