~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_counted_lock.py

  • Committer: Martin Pool
  • Date: 2008-06-05 07:59:29 UTC
  • mto: This revision was merged to the branch mainline in revision 3479.
  • Revision ID: mbp@sourcefrog.net-20080605075929-j5pet0dpcnj32r7x
CountedLock.unlock should raise LockNotHeld if appropriate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
from bzrlib.counted_lock import CountedLock
20
20
from bzrlib.errors import (
21
21
    LockError,
 
22
    LockNotHeld,
22
23
    ReadOnlyError,
 
24
    TokenMismatch,
23
25
    )
24
26
from bzrlib.tests import TestCase
25
27
 
62
64
            raise LockError("%s is already locked in mode %r" %
63
65
                (self, self._lock_mode))
64
66
 
 
67
    def validate_token(self, token):
 
68
        if token == 'token':
 
69
            # already held by this caller
 
70
            return 'token'
 
71
        else:
 
72
            raise TokenMismatch(token, 'token')
 
73
 
65
74
 
66
75
class TestDummyLock(TestCase):
67
76
 
131
140
    def test_unlock_not_locked(self):
132
141
        real_lock = DummyLock()
133
142
        l = CountedLock(real_lock)
134
 
        self.assertRaises(LockError, l.unlock)
 
143
        self.assertRaises(LockNotHeld, l.unlock)
135
144
 
136
145
    def test_read_lock_while_write_locked(self):
137
146
        real_lock = DummyLock()