25
25
from bzrlib.bzrdir import BzrDir
26
26
from bzrlib.errors import NotBranchError, NotVersionedError
27
27
from bzrlib.lockdir import LockDir
28
from bzrlib.mutabletree import needs_tree_write_lock
28
29
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
29
from bzrlib.tests import TestCaseWithTransport, TestSkipped
30
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
30
31
from bzrlib.trace import mutter
31
32
from bzrlib.transport import get_transport
32
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
33
from bzrlib.workingtree import (
35
41
class TestTreeDirectory(TestCaseWithTransport):
366
372
bzrlib.DEFAULT_IGNORE = orig_default
367
373
ignores._runtime_ignores = orig_runtime
376
class InstrumentedTree(object):
377
"""A instrumented tree to check the needs_tree_write_lock decorator."""
382
def lock_tree_write(self):
383
self._locks.append('t')
385
@needs_tree_write_lock
386
def method_with_tree_write_lock(self, *args, **kwargs):
387
"""A lock_tree_write decorated method that returns its arguments."""
390
@needs_tree_write_lock
391
def method_that_raises(self):
392
"""This method causes an exception when called with parameters.
394
This allows the decorator code to be checked - it should still call
399
self._locks.append('u')
402
class TestInstrumentedTree(TestCase):
404
def test_needs_tree_write_lock(self):
405
"""@needs_tree_write_lock should be semantically transparent."""
406
tree = InstrumentedTree()
408
'method_with_tree_write_lock',
409
tree.method_with_tree_write_lock.__name__)
411
"A lock_tree_write decorated method that returns its arguments.",
412
tree.method_with_tree_write_lock.__doc__)
415
result = tree.method_with_tree_write_lock(1,2,3, a='b')
416
self.assertEqual((args, kwargs), result)
417
self.assertEqual(['t', 'u'], tree._locks)
418
self.assertRaises(TypeError, tree.method_that_raises, 'foo')
419
self.assertEqual(['t', 'u', 't', 'u'], tree._locks)