~jelmer/brz/deprecation

« back to all changes in this revision

Viewing changes to breezy/tests/test_workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2017-09-06 04:15:55 UTC
  • mfrom: (6754.8.21 lock-context-2)
  • Revision ID: jelmer@jelmer.uk-20170906041555-jtr5qxli38167gc6
Merge lp:~jelmer/brz/lock-context-2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    )
31
31
from ..lock import write_locked
32
32
from ..lockdir import LockDir
33
 
from ..mutabletree import needs_tree_write_lock
34
33
from . import TestCase, TestCaseWithTransport, TestSkipped
35
34
from ..workingtree import (
36
35
    TreeEntry,
375
374
        self.assertEqual([], tree.get_parent_ids())
376
375
 
377
376
 
378
 
class InstrumentedTree(object):
379
 
    """A instrumented tree to check the needs_tree_write_lock decorator."""
380
 
 
381
 
    def __init__(self):
382
 
        self._locks = []
383
 
 
384
 
    def lock_tree_write(self):
385
 
        self._locks.append('t')
386
 
        return lock.LogicalLockResult(self.unlock)
387
 
 
388
 
    @needs_tree_write_lock
389
 
    def method_with_tree_write_lock(self, *args, **kwargs):
390
 
        """A lock_tree_write decorated method that returns its arguments."""
391
 
        return args, kwargs
392
 
 
393
 
    @needs_tree_write_lock
394
 
    def method_that_raises(self):
395
 
        """This method causes an exception when called with parameters.
396
 
 
397
 
        This allows the decorator code to be checked - it should still call
398
 
        unlock.
399
 
        """
400
 
 
401
 
    def unlock(self):
402
 
        self._locks.append('u')
403
 
 
404
 
 
405
 
class TestInstrumentedTree(TestCase):
406
 
 
407
 
    def test_needs_tree_write_lock(self):
408
 
        """@needs_tree_write_lock should be semantically transparent."""
409
 
        tree = InstrumentedTree()
410
 
        self.assertEqual(
411
 
            'method_with_tree_write_lock',
412
 
            tree.method_with_tree_write_lock.__name__)
413
 
        self.assertDocstring(
414
 
            "A lock_tree_write decorated method that returns its arguments.",
415
 
            tree.method_with_tree_write_lock)
416
 
        args = (1, 2, 3)
417
 
        kwargs = {'a':'b'}
418
 
        result = tree.method_with_tree_write_lock(1,2,3, a='b')
419
 
        self.assertEqual((args, kwargs), result)
420
 
        self.assertEqual(['t', 'u'], tree._locks)
421
 
        self.assertRaises(TypeError, tree.method_that_raises, 'foo')
422
 
        self.assertEqual(['t', 'u', 't', 'u'], tree._locks)
423
 
 
424
 
 
425
377
class TestRevert(TestCaseWithTransport):
426
378
 
427
379
    def test_revert_conflicts_recursive(self):