~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: 2009-03-24 05:21:02 UTC
  • mfrom: (4192 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20090324052102-8kk087b32tep3d9h
merge trunk

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
 
45
47
                # already held by this caller
46
48
                return 'token'
47
49
            else:
48
 
                raise errors.TokenMismatch()
 
50
                raise TokenMismatch()
49
51
        self._assert_not_locked()
50
52
        self._lock_mode = 'w'
51
53
        self._calls.append('lock_write')
69
71
            raise LockError("%s is already locked in mode %r" %
70
72
                (self, self._lock_mode))
71
73
 
 
74
    def validate_token(self, token):
 
75
        if token == 'token':
 
76
            # already held by this caller
 
77
            return 'token'
 
78
        elif token is None:
 
79
            return
 
80
        else:
 
81
            raise TokenMismatch(token, 'token')
 
82
 
72
83
 
73
84
class TestDummyLock(TestCase):
74
85
 
139
150
    def test_unlock_not_locked(self):
140
151
        real_lock = DummyLock()
141
152
        l = CountedLock(real_lock)
142
 
        self.assertRaises(LockError, l.unlock)
 
153
        self.assertRaises(LockNotHeld, l.unlock)
143
154
 
144
155
    def test_read_lock_while_write_locked(self):
145
156
        real_lock = DummyLock()