~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
33
 
                                WorkingTree)
 
32
from bzrlib.workingtree import (
 
33
    needs_tree_write_lock,
 
34
    TreeEntry,
 
35
    TreeDirectory,
 
36
    TreeFile,
 
37
    TreeLink,
 
38
    WorkingTree,
 
39
    )
34
40
 
35
41
class TestTreeDirectory(TestCaseWithTransport):
36
42
 
364
370
        finally:
365
371
            bzrlib.DEFAULT_IGNORE = orig_default
366
372
            ignores._runtime_ignores = orig_runtime
 
373
 
 
374
 
 
375
class InstrumentedTree(object):
 
376
    """A instrumented tree to check the needs_tree_write_lock decorator."""
 
377
 
 
378
    def __init__(self):
 
379
        self._locks = []
 
380
 
 
381
    def lock_tree_write(self):
 
382
        self._locks.append('t')
 
383
 
 
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."""
 
387
        return args, kwargs
 
388
 
 
389
    @needs_tree_write_lock
 
390
    def method_that_raises(self):
 
391
        """This method causes an exception when called with parameters.
 
392
        
 
393
        This allows the decorator code to be checked - it should still call
 
394
        unlock.
 
395
        """
 
396
 
 
397
    def unlock(self):
 
398
        self._locks.append('u')
 
399
 
 
400
 
 
401
class TestInstrumentedTree(TestCase):
 
402
 
 
403
    def test_needs_tree_write_lock(self):
 
404
        """@needs_tree_write_lock should be semantically transparent."""
 
405
        tree = InstrumentedTree()
 
406
        self.assertEqual(
 
407
            'method_with_tree_write_lock',
 
408
            tree.method_with_tree_write_lock.__name__)
 
409
        self.assertEqual(
 
410
            "A lock_tree_write decorated method that returns its arguments.",
 
411
            tree.method_with_tree_write_lock.__doc__)
 
412
        args = (1, 2, 3)
 
413
        kwargs = {'a':'b'}
 
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)