1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
from bzrlib import (
branch,
builtins,
errors,
lock,
)
from bzrlib.tests import transport_util
class TestRevert(
transport_util.TestCaseWithConnectionHookedTransport):
def setUp(self):
super(TestRevert, self).setUp()
self.local_wt = self.make_branch_and_tree('local')
def test_revert_tree_write_lock_and_branch_read_lock(self):
self.start_logging_connections()
# make sure that the cwd is the branch
os.chdir('local')
# install lock hooks to find out about cmd_revert's locking actions
locks_acquired = []
locks_released = []
lock.Lock.hooks.install_named_hook('lock_acquired',
locks_acquired.append, None)
lock.Lock.hooks.install_named_hook('lock_released',
locks_released.append, None)
# execute the revert command (There is nothing to actually revert,
# but locks are acquired either way.)
revert = builtins.cmd_revert()
revert.run()
# make sure that only one lock is acquired and released.
self.assertEqual(1, len(locks_acquired))
self.assertEqual(1, len(locks_released))
# make sure that the nonces are the same, since otherwise
# this would not be the same lock.
self.assertEqual(locks_acquired[0].details, locks_released[0].details)
# make sure that the locks are checkout locks.
self.assertEndsWith(locks_acquired[0].lock_url, "/checkout/lock")
self.assertEndsWith(locks_released[0].lock_url, "/checkout/lock")
|