/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Martin Pool
  • Date: 2006-10-19 02:59:24 UTC
  • mfrom: (2089 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2090.
  • Revision ID: mbp@sourcefrog.net-20061019025924-1af1ed4510b4e71f
merge up bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
                                WorkingTree)
 
33
from bzrlib.workingtree import (
 
34
    TreeEntry,
 
35
    TreeDirectory,
 
36
    TreeFile,
 
37
    TreeLink,
 
38
    WorkingTree,
 
39
    )
34
40
 
35
41
class TestTreeDirectory(TestCaseWithTransport):
36
42
 
90
96
    def initialize(self, a_bzrdir, revision_id=None):
91
97
        """Sample branches cannot be created."""
92
98
        t = a_bzrdir.get_workingtree_transport(self)
93
 
        t.put('format', StringIO(self.get_format_string()))
 
99
        t.put_bytes('format', self.get_format_string())
94
100
        return 'A tree'
95
101
 
96
102
    def is_supported(self):
167
173
        t = control.get_workingtree_transport(None)
168
174
        self.assertEqualDiff('Bazaar-NG Working Tree format 3',
169
175
                             t.get('format').read())
170
 
        self.assertEqualDiff('<inventory format="5">\n'
171
 
                             '</inventory>\n',
172
 
                             t.get('inventory').read())
 
176
        # self.assertContainsRe(t.get('inventory').read(), 
 
177
        #                       '<inventory file_id="[^"]*" format="5">\n'
 
178
        #                       '</inventory>\n',
 
179
        #                      )
 
180
        # WorkingTreeFormat3 doesn't default to creating a unique root id,
 
181
        # because it is incompatible with older bzr versions
 
182
        self.assertContainsRe(t.get('inventory').read(),
 
183
                              '<inventory format="5">\n'
 
184
                              '</inventory>\n',
 
185
                             )
173
186
        self.assertEqualDiff('### bzr hashcache v5\n',
174
187
                             t.get('stat-cache').read())
175
188
        self.assertFalse(t.has('inventory.basis'))
209
222
        control.create_branch()
210
223
        tree = workingtree.WorkingTreeFormat3().initialize(control)
211
224
        tree._control_files._transport.delete("pending-merges")
212
 
        self.assertEqual([], tree.pending_merges())
 
225
        self.assertEqual([], tree.get_parent_ids())
213
226
 
214
227
 
215
228
class TestFormat2WorkingTree(TestCaseWithTransport):
364
377
        finally:
365
378
            bzrlib.DEFAULT_IGNORE = orig_default
366
379
            ignores._runtime_ignores = orig_runtime
 
380
 
 
381
 
 
382
class InstrumentedTree(object):
 
383
    """A instrumented tree to check the needs_tree_write_lock decorator."""
 
384
 
 
385
    def __init__(self):
 
386
        self._locks = []
 
387
 
 
388
    def lock_tree_write(self):
 
389
        self._locks.append('t')
 
390
 
 
391
    @needs_tree_write_lock
 
392
    def method_with_tree_write_lock(self, *args, **kwargs):
 
393
        """A lock_tree_write decorated method that returns its arguments."""
 
394
        return args, kwargs
 
395
 
 
396
    @needs_tree_write_lock
 
397
    def method_that_raises(self):
 
398
        """This method causes an exception when called with parameters.
 
399
        
 
400
        This allows the decorator code to be checked - it should still call
 
401
        unlock.
 
402
        """
 
403
 
 
404
    def unlock(self):
 
405
        self._locks.append('u')
 
406
 
 
407
 
 
408
class TestInstrumentedTree(TestCase):
 
409
 
 
410
    def test_needs_tree_write_lock(self):
 
411
        """@needs_tree_write_lock should be semantically transparent."""
 
412
        tree = InstrumentedTree()
 
413
        self.assertEqual(
 
414
            'method_with_tree_write_lock',
 
415
            tree.method_with_tree_write_lock.__name__)
 
416
        self.assertEqual(
 
417
            "A lock_tree_write decorated method that returns its arguments.",
 
418
            tree.method_with_tree_write_lock.__doc__)
 
419
        args = (1, 2, 3)
 
420
        kwargs = {'a':'b'}
 
421
        result = tree.method_with_tree_write_lock(1,2,3, a='b')
 
422
        self.assertEqual((args, kwargs), result)
 
423
        self.assertEqual(['t', 'u'], tree._locks)
 
424
        self.assertRaises(TypeError, tree.method_that_raises, 'foo')
 
425
        self.assertEqual(['t', 'u', 't', 'u'], tree._locks)