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