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 (
375
374
self.assertEqual([], tree.get_parent_ids())
378
class InstrumentedTree(object):
379
"""A instrumented tree to check the needs_tree_write_lock decorator."""
384
def lock_tree_write(self):
385
self._locks.append('t')
386
return lock.LogicalLockResult(self.unlock)
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."""
393
@needs_tree_write_lock
394
def method_that_raises(self):
395
"""This method causes an exception when called with parameters.
397
This allows the decorator code to be checked - it should still call
402
self._locks.append('u')
405
class TestInstrumentedTree(TestCase):
407
def test_needs_tree_write_lock(self):
408
"""@needs_tree_write_lock should be semantically transparent."""
409
tree = InstrumentedTree()
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)
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)
425
377
class TestRevert(TestCaseWithTransport):
427
379
def test_revert_conflicts_recursive(self):