Rev 5202: Cleaner matcher matching revised unlocking protocol. in http://bazaar.launchpad.net/~lifeless/bzr/lock_return

Robert Collins robertc at robertcollins.net
Thu May 6 12:08:33 BST 2010


At http://bazaar.launchpad.net/~lifeless/bzr/lock_return

------------------------------------------------------------
revno: 5202
revision-id: robertc at robertcollins.net-20100506110810-h3j07fh5gmw54s25
parent: robertc at robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
committer: Robert Collins <robertc at robertcollins.net>
branch nick: lock_return
timestamp: Thu 2010-05-06 23:08:10 +1200
message:
  Cleaner matcher matching revised unlocking protocol.
=== modified file 'bzrlib/tests/matchers.py'
--- a/bzrlib/tests/matchers.py	2010-05-06 07:48:22 +0000
+++ b/bzrlib/tests/matchers.py	2010-05-06 11:08:10 +0000
@@ -27,17 +27,17 @@
 """
 
 __all__ = [
-    'ReturnsCallableLeavingObjectUnlocked',
+    'ReturnsUnlockable',
     ]
 
 from testtools.matchers import Mismatch, Matcher
 
 
-class ReturnsCallableLeavingObjectUnlocked(Matcher):
+class ReturnsUnlockable(Matcher):
     """A matcher that checks for the pattern we want lock* methods to have:
 
-    They should return a callable.
-    Calling that callable should unlock the original object.
+    They should return an object with an unlock() method.
+    Calling that method should unlock the original object.
 
     :ivar lockable_thing: The object which can be locked that will be
         inspected.
@@ -48,11 +48,11 @@
         self.lockable_thing = lockable_thing
 
     def __str__(self):
-        return ('ReturnsCallableLeavingObjectUnlocked(lockable_thing=%s)' % 
+        return ('ReturnsUnlockable(lockable_thing=%s)' % 
             self.lockable_thing)
 
     def match(self, lock_method):
-        lock_method()()
+        lock_method().unlock()
         if self.lockable_thing.is_locked():
             return _IsLocked(self.lockable_thing)
         return None

=== modified file 'bzrlib/tests/test_matchers.py'
--- a/bzrlib/tests/test_matchers.py	2010-05-06 07:48:22 +0000
+++ b/bzrlib/tests/test_matchers.py	2010-05-06 11:08:10 +0000
@@ -35,23 +35,30 @@
         return self._is_locked
 
 
-class TestReturnsCallableLeavingObjectUnlocked(TestCase):
+class FakeUnlockable(object):
+    """Something that can be unlocked."""
+
+    def unlock(self):
+        pass
+
+
+class TestReturnsUnlockable(TestCase):
 
     def test___str__(self):
-        matcher = ReturnsCallableLeavingObjectUnlocked(StubTree(True))
+        matcher = ReturnsUnlockable(StubTree(True))
         self.assertEqual(
-            'ReturnsCallableLeavingObjectUnlocked(lockable_thing=I am da tree)',
+            'ReturnsUnlockable(lockable_thing=I am da tree)',
             str(matcher))
 
     def test_match(self):
         stub_tree = StubTree(False)
-        matcher = ReturnsCallableLeavingObjectUnlocked(stub_tree)
-        self.assertThat(matcher.match(lambda:lambda:None), Equals(None))
+        matcher = ReturnsUnlockable(stub_tree)
+        self.assertThat(matcher.match(lambda:FakeUnlockable()), Equals(None))
 
     def test_mismatch(self):
         stub_tree = StubTree(True)
-        matcher = ReturnsCallableLeavingObjectUnlocked(stub_tree)
-        mismatch = matcher.match(lambda:lambda:None)
+        matcher = ReturnsUnlockable(stub_tree)
+        mismatch = matcher.match(lambda:FakeUnlockable())
         self.assertNotEqual(None, mismatch)
         self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
 




More information about the bazaar-commits mailing list