/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Andrew Bennetts
  • Date: 2011-05-26 08:04:46 UTC
  • mto: This revision was merged to the branch mainline in revision 5918.
  • Revision ID: andrew.bennetts@canonical.com-20110526080446-1wsdd1io98tmzavr
Removed bzrlib.branch._run_with_write_locked_target.  Use bzrlib.cleanup instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
711
711
        r.report(f)
712
712
        self.assertEqual("No revisions to pull.\n", f.getvalue())
713
713
 
714
 
 
715
 
class _StubLockable(object):
716
 
    """Helper for TestRunWithWriteLockedTarget."""
717
 
 
718
 
    def __init__(self, calls, unlock_exc=None):
719
 
        self.calls = calls
720
 
        self.unlock_exc = unlock_exc
721
 
 
722
 
    def lock_write(self):
723
 
        self.calls.append('lock_write')
724
 
 
725
 
    def unlock(self):
726
 
        self.calls.append('unlock')
727
 
        if self.unlock_exc is not None:
728
 
            raise self.unlock_exc
729
 
 
730
 
 
731
 
class _ErrorFromCallable(Exception):
732
 
    """Helper for TestRunWithWriteLockedTarget."""
733
 
 
734
 
 
735
 
class _ErrorFromUnlock(Exception):
736
 
    """Helper for TestRunWithWriteLockedTarget."""
737
 
 
738
 
 
739
 
class TestRunWithWriteLockedTarget(tests.TestCase):
740
 
    """Tests for _run_with_write_locked_target."""
741
 
 
742
 
    def setUp(self):
743
 
        tests.TestCase.setUp(self)
744
 
        self._calls = []
745
 
 
746
 
    def func_that_returns_ok(self):
747
 
        self._calls.append('func called')
748
 
        return 'ok'
749
 
 
750
 
    def func_that_raises(self):
751
 
        self._calls.append('func called')
752
 
        raise _ErrorFromCallable()
753
 
 
754
 
    def test_success_unlocks(self):
755
 
        lockable = _StubLockable(self._calls)
756
 
        result = _mod_branch._run_with_write_locked_target(
757
 
            lockable, self.func_that_returns_ok)
758
 
        self.assertEqual('ok', result)
759
 
        self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
760
 
 
761
 
    def test_exception_unlocks_and_propagates(self):
762
 
        lockable = _StubLockable(self._calls)
763
 
        self.assertRaises(_ErrorFromCallable,
764
 
                          _mod_branch._run_with_write_locked_target,
765
 
                          lockable, self.func_that_raises)
766
 
        self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
767
 
 
768
 
    def test_callable_succeeds_but_error_during_unlock(self):
769
 
        lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
770
 
        self.assertRaises(_ErrorFromUnlock,
771
 
                          _mod_branch._run_with_write_locked_target,
772
 
                          lockable, self.func_that_returns_ok)
773
 
        self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
774
 
 
775
 
    def test_error_during_unlock_does_not_mask_original_error(self):
776
 
        lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
777
 
        self.assertRaises(_ErrorFromCallable,
778
 
                          _mod_branch._run_with_write_locked_target,
779
 
                          lockable, self.func_that_raises)
780
 
        self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)