/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: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    bzrdir,
20
20
    conflicts,
21
21
    errors,
 
22
    symbol_versioning,
22
23
    transport,
23
24
    workingtree,
24
25
    workingtree_3,
25
26
    workingtree_4,
26
27
    )
27
 
from bzrlib.lock import write_locked
28
28
from bzrlib.lockdir import LockDir
29
29
from bzrlib.mutabletree import needs_tree_write_lock
30
30
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
218
218
                          workingtree.WorkingTreeFormatMetaDir.find_format,
219
219
                          dir)
220
220
 
 
221
    def test_register_unregister_format(self):
 
222
        format = SampleTreeFormat()
 
223
        # make a control dir
 
224
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
 
225
        dir.create_repository()
 
226
        dir.create_branch()
 
227
        # make a branch
 
228
        format.initialize(dir)
 
229
        # register a format for it.
 
230
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
231
            workingtree.WorkingTreeFormat.register_format, format)
 
232
        self.assertTrue(format in 
 
233
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
234
                workingtree.WorkingTreeFormat.get_formats))
 
235
        # which branch.Open will refuse (not supported)
 
236
        self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
 
237
        # but open_downlevel will work
 
238
        self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
 
239
        # unregister the format
 
240
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
241
            workingtree.WorkingTreeFormat.unregister_format, format)
 
242
        self.assertFalse(format in
 
243
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
244
                workingtree.WorkingTreeFormat.get_formats))
 
245
 
221
246
    def test_find_format_with_features(self):
222
247
        tree = self.make_branch_and_tree('.', format='2a')
223
248
        tree.update_feature_flags({"name": "necessity"})
495
520
        self.make_branch('qux')
496
521
        trees = workingtree.WorkingTree.find_trees('.')
497
522
        self.assertEqual(2, len(list(trees)))
498
 
 
499
 
 
500
 
class TestStoredUncommitted(TestCaseWithTransport):
501
 
 
502
 
    def store_uncommitted(self):
503
 
        tree = self.make_branch_and_tree('tree')
504
 
        tree.commit('get root in there')
505
 
        self.build_tree_contents([('tree/file', 'content')])
506
 
        tree.add('file', 'file-id')
507
 
        tree.store_uncommitted()
508
 
        return tree
509
 
 
510
 
    def test_store_uncommitted(self):
511
 
        self.store_uncommitted()
512
 
        self.assertPathDoesNotExist('tree/file')
513
 
 
514
 
    def test_store_uncommitted_no_change(self):
515
 
        tree = self.make_branch_and_tree('tree')
516
 
        tree.commit('get root in there')
517
 
        tree.store_uncommitted()
518
 
        self.assertIs(None, tree.branch.get_unshelver(tree))
519
 
 
520
 
    def test_restore_uncommitted(self):
521
 
        with write_locked(self.store_uncommitted()) as tree:
522
 
            tree.restore_uncommitted()
523
 
            self.assertPathExists('tree/file')
524
 
            self.assertIs(None, tree.branch.get_unshelver(tree))
525
 
 
526
 
    def test_restore_uncommitted_none(self):
527
 
        tree = self.make_branch_and_tree('tree')
528
 
        tree.restore_uncommitted()