~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_matchers.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        return self._is_locked
36
36
 
37
37
 
38
 
class TestReturnsCallableLeavingObjectUnlocked(TestCase):
 
38
class FakeUnlockable(object):
 
39
    """Something that can be unlocked."""
 
40
 
 
41
    def unlock(self):
 
42
        pass
 
43
 
 
44
 
 
45
class TestReturnsUnlockable(TestCase):
39
46
 
40
47
    def test___str__(self):
41
 
        matcher = ReturnsCallableLeavingObjectUnlocked(StubTree(True))
 
48
        matcher = ReturnsUnlockable(StubTree(True))
42
49
        self.assertEqual(
43
 
            'ReturnsCallableLeavingObjectUnlocked(lockable_thing=I am da tree)',
 
50
            'ReturnsUnlockable(lockable_thing=I am da tree)',
44
51
            str(matcher))
45
52
 
46
53
    def test_match(self):
47
54
        stub_tree = StubTree(False)
48
 
        matcher = ReturnsCallableLeavingObjectUnlocked(stub_tree)
49
 
        self.assertThat(matcher.match(lambda:lambda:None), Equals(None))
 
55
        matcher = ReturnsUnlockable(stub_tree)
 
56
        self.assertThat(matcher.match(lambda:FakeUnlockable()), Equals(None))
50
57
 
51
58
    def test_mismatch(self):
52
59
        stub_tree = StubTree(True)
53
 
        matcher = ReturnsCallableLeavingObjectUnlocked(stub_tree)
54
 
        mismatch = matcher.match(lambda:lambda:None)
 
60
        matcher = ReturnsUnlockable(stub_tree)
 
61
        mismatch = matcher.match(lambda:FakeUnlockable())
55
62
        self.assertNotEqual(None, mismatch)
56
63
        self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
57
64