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