~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/matchers.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
29
__all__ = [
30
 
    'ReturnsCallableLeavingObjectUnlocked',
 
30
    'ReturnsUnlockable',
31
31
    ]
32
32
 
33
33
from testtools.matchers import Mismatch, Matcher
34
34
 
35
35
 
36
 
class ReturnsCallableLeavingObjectUnlocked(Matcher):
 
36
class ReturnsUnlockable(Matcher):
37
37
    """A matcher that checks for the pattern we want lock* methods to have:
38
38
 
39
 
    They should return a callable.
40
 
    Calling that callable should unlock the original object.
 
39
    They should return an object with an unlock() method.
 
40
    Calling that method should unlock the original object.
41
41
 
42
42
    :ivar lockable_thing: The object which can be locked that will be
43
43
        inspected.
48
48
        self.lockable_thing = lockable_thing
49
49
 
50
50
    def __str__(self):
51
 
        return ('ReturnsCallableLeavingObjectUnlocked(lockable_thing=%s)' % 
 
51
        return ('ReturnsUnlockable(lockable_thing=%s)' % 
52
52
            self.lockable_thing)
53
53
 
54
54
    def match(self, lock_method):
55
 
        lock_method()()
 
55
        lock_method().unlock()
56
56
        if self.lockable_thing.is_locked():
57
57
            return _IsLocked(self.lockable_thing)
58
58
        return None