~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#           and others
4
4
#
19
19
from cStringIO import StringIO
20
20
import errno
21
21
import os
 
22
import sys
22
23
 
23
24
from bzrlib import (
24
25
    branch,
 
26
    branchbuilder,
25
27
    bzrdir,
26
 
    config,
27
 
    controldir,
28
28
    errors,
29
29
    osutils,
30
 
    revision as _mod_revision,
31
 
    symbol_versioning,
32
30
    tests,
33
 
    trace,
34
31
    urlutils,
35
 
    )
36
 
from bzrlib.errors import (
37
 
    UnsupportedOperation,
38
 
    PathsNotVersionedError,
39
 
    )
 
32
    workingtree,
 
33
    )
 
34
from bzrlib.errors import (NotBranchError, NotVersionedError,
 
35
                           UnsupportedOperation, PathsNotVersionedError)
40
36
from bzrlib.inventory import Inventory
41
 
from bzrlib.mutabletree import MutableTree
42
37
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
43
 
from bzrlib.tests import (
44
 
    features,
45
 
    TestSkipped,
46
 
    TestNotApplicable,
47
 
    )
 
38
from bzrlib.tests import TestSkipped, TestNotApplicable
48
39
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
49
 
from bzrlib.workingtree import (
50
 
    TreeDirectory,
51
 
    TreeFile,
52
 
    TreeLink,
53
 
    InventoryWorkingTree,
54
 
    WorkingTree,
55
 
    )
 
40
from bzrlib.trace import mutter
 
41
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
 
42
                                WorkingTree, WorkingTree2)
56
43
from bzrlib.conflicts import ConflictList, TextConflict, ContentsConflict
57
44
 
58
45
 
59
46
class TestWorkingTree(TestCaseWithWorkingTree):
60
47
 
61
 
    def requireBranchReference(self):
62
 
        test_branch = self.make_branch('test-branch')
63
 
        try:
64
 
            # if there is a working tree now, this is not supported.
65
 
            test_branch.bzrdir.open_workingtree()
66
 
            raise TestNotApplicable("only on trees that can be separate"
67
 
                " from their branch.")
68
 
        except (errors.NoWorkingTree, errors.NotLocalUrl):
69
 
            pass
70
 
 
71
 
    def test_branch_builder(self):
72
 
        # Just a smoke test that we get a branch at the specified relpath
73
 
        builder = self.make_branch_builder('foobar')
74
 
        br = branch.Branch.open(self.get_url('foobar'))
75
 
 
76
48
    def test_list_files(self):
77
49
        tree = self.make_branch_and_tree('.')
78
50
        self.build_tree(['dir/', 'file'])
132
104
        self.assertEqual(('filename', 'V', 'directory', 'file-id'),
133
105
                         result[0][:4])
134
106
 
135
 
    def test_get_config_stack(self):
136
 
        # Smoke test that all working trees succeed getting a config
137
 
        wt = self.make_branch_and_tree('.')
138
 
        conf = wt.get_config_stack()
139
 
        self.assertIsInstance(conf, config.Stack)
140
 
 
141
107
    def test_open_containing(self):
142
 
        local_wt = self.make_branch_and_tree('.')
143
 
        local_url = local_wt.bzrdir.root_transport.base
144
 
        local_base = urlutils.local_path_from_url(local_url)
145
 
        del local_wt
 
108
        branch = self.make_branch_and_tree('.').branch
 
109
        local_base = urlutils.local_path_from_url(branch.base)
146
110
 
147
111
        # Empty opens '.'
148
112
        wt, relpath = WorkingTree.open_containing()
180
144
 
181
145
    def test_lock_locks_branch(self):
182
146
        tree = self.make_branch_and_tree('.')
183
 
        self.assertEqual(None, tree.branch.peek_lock_mode())
184
147
        tree.lock_read()
185
148
        self.assertEqual('r', tree.branch.peek_lock_mode())
186
149
        tree.unlock()
195
158
        tree = self.make_branch_and_tree('.')
196
159
 
197
160
        self.build_tree(['hello.txt'])
198
 
        with file('hello.txt', 'w') as f: f.write('initial hello')
 
161
        file('hello.txt', 'w').write('initial hello')
199
162
 
200
163
        self.assertRaises(PathsNotVersionedError,
201
164
                          tree.revert, ['hello.txt'])
203
166
        tree.commit('create initial hello.txt')
204
167
 
205
168
        self.check_file_contents('hello.txt', 'initial hello')
206
 
        with file('hello.txt', 'w') as f: f.write('new hello')
 
169
        file('hello.txt', 'w').write('new hello')
207
170
        self.check_file_contents('hello.txt', 'new hello')
208
171
 
209
172
        # revert file modified since last revision
217
180
        self.check_file_contents('hello.txt.~1~', 'new hello')
218
181
 
219
182
        # backup files are numbered
220
 
        with file('hello.txt', 'w') as f: f.write('new hello2')
 
183
        file('hello.txt', 'w').write('new hello2')
221
184
        tree.revert(['hello.txt'])
222
185
        self.check_file_contents('hello.txt', 'initial hello')
223
186
        self.check_file_contents('hello.txt.~1~', 'new hello')
226
189
    def test_revert_missing(self):
227
190
        # Revert a file that has been deleted since last commit
228
191
        tree = self.make_branch_and_tree('.')
229
 
        with file('hello.txt', 'w') as f: f.write('initial hello')
 
192
        file('hello.txt', 'w').write('initial hello')
230
193
        tree.add('hello.txt')
231
194
        tree.commit('added hello.txt')
232
195
        os.unlink('hello.txt')
233
196
        tree.remove('hello.txt')
234
197
        tree.revert(['hello.txt'])
235
 
        self.assertPathExists('hello.txt')
 
198
        self.failUnlessExists('hello.txt')
236
199
 
237
200
    def test_versioned_files_not_unknown(self):
238
201
        tree = self.make_branch_and_tree('.')
270
233
 
271
234
        wt.commit('create initial state')
272
235
 
273
 
        revid = b.last_revision()
 
236
        revid = b.revision_history()[0]
274
237
        self.log('first revision_id is {%s}' % revid)
275
238
 
276
 
        tree = b.repository.revision_tree(revid)
277
 
        self.log('contents of tree: %r' % list(tree.iter_entries_by_dir()))
 
239
        inv = b.repository.get_inventory(revid)
 
240
        self.log('contents of inventory: %r' % inv.entries())
278
241
 
279
 
        self.check_tree_shape(tree, ['dir/', 'dir/sub/', 'dir/sub/file'])
 
242
        self.check_inventory_shape(inv,
 
243
                                   ['dir/', 'dir/sub/', 'dir/sub/file'])
280
244
        wt.rename_one('dir', 'newdir')
281
245
 
282
246
        wt.lock_read()
283
 
        self.check_tree_shape(wt,
 
247
        self.check_inventory_shape(wt.inventory,
284
248
                                   ['newdir/', 'newdir/sub/', 'newdir/sub/file'])
285
249
        wt.unlock()
286
250
        wt.rename_one('newdir/sub', 'newdir/newsub')
287
251
        wt.lock_read()
288
 
        self.check_tree_shape(wt, ['newdir/', 'newdir/newsub/',
 
252
        self.check_inventory_shape(wt.inventory,
 
253
                                   ['newdir/', 'newdir/newsub/',
289
254
                                    'newdir/newsub/file'])
290
255
        wt.unlock()
291
256
 
299
264
        wt = self.make_branch_and_tree('.')
300
265
        self.build_tree(['foo/',
301
266
                         'foo/hello'])
302
 
        if not wt._format.supports_versioned_directories:
303
 
            wt.add('foo/hello')
304
 
        else:
305
 
            self.assertRaises(NotVersionedError,
306
 
                              wt.add,
307
 
                              'foo/hello')
 
267
        self.assertRaises(NotVersionedError,
 
268
                          wt.add,
 
269
                          'foo/hello')
308
270
 
309
271
    def test_add_missing(self):
310
272
        # adding a msising file -> NoSuchFile
333
295
        cloned = cloned_dir.open_workingtree()
334
296
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
335
297
 
336
 
    def test_clone_empty(self):
337
 
        wt = self.make_branch_and_tree('source')
338
 
        cloned_dir = wt.bzrdir.clone('target', revision_id=_mod_revision.NULL_REVISION)
339
 
        cloned = cloned_dir.open_workingtree()
340
 
        self.assertEqual(cloned.get_parent_ids(), wt.get_parent_ids())
341
 
 
342
298
    def test_last_revision(self):
343
299
        wt = self.make_branch_and_tree('source')
344
300
        self.assertEqual([], wt.get_parent_ids())
356
312
        wt.set_last_revision('null:')
357
313
        wt.commit('A', allow_pointless=True, rev_id='A')
358
314
        self.assertEqual(['A'], wt.get_parent_ids())
359
 
        # null: is aways in the branch
 
315
        # None is aways in the branch
360
316
        wt.set_last_revision('null:')
361
317
        self.assertEqual([], wt.get_parent_ids())
362
318
        # and now we can set it to 'A'
363
319
        # because some formats mutate the branch to set it on the tree
364
320
        # we need to alter the branch to let this pass.
365
 
        if getattr(wt.branch, "_set_revision_history", None) is None:
 
321
        try:
 
322
            wt.branch.set_revision_history(['A', 'B'])
 
323
        except errors.NoSuchRevision, e:
 
324
            self.assertEqual('B', e.revision)
366
325
            raise TestSkipped("Branch format does not permit arbitrary"
367
326
                              " history")
368
 
        wt.branch._set_revision_history(['A', 'B'])
369
327
        wt.set_last_revision('A')
370
328
        self.assertEqual(['A'], wt.get_parent_ids())
371
329
        self.assertRaises(errors.ReservedId, wt.set_last_revision, 'A:')
379
337
        # that formats where initialising a branch does not initialise a
380
338
        # tree - and thus have separable entities - support skewing the
381
339
        # two things.
382
 
        self.requireBranchReference()
383
 
        wt = self.make_branch_and_tree('tree')
 
340
        branch = self.make_branch('tree')
 
341
        try:
 
342
            # if there is a working tree now, this is not supported.
 
343
            branch.bzrdir.open_workingtree()
 
344
            return
 
345
        except errors.NoWorkingTree:
 
346
            pass
 
347
        wt = branch.bzrdir.create_workingtree()
384
348
        wt.commit('A', allow_pointless=True, rev_id='A')
385
349
        wt.set_last_revision(None)
386
350
        self.assertEqual([], wt.get_parent_ids())
426
390
        wt.set_parent_ids(['B'])
427
391
        tree = wt.basis_tree()
428
392
        tree.lock_read()
429
 
        self.assertTrue(tree.has_filename('bar'))
 
393
        self.failUnless(tree.has_filename('bar'))
430
394
        tree.unlock()
431
395
        wt.set_parent_ids(['A'])
432
396
        tree = wt.basis_tree()
433
397
        tree.lock_read()
434
 
        self.assertTrue(tree.has_filename('foo'))
 
398
        self.failUnless(tree.has_filename('foo'))
435
399
        tree.unlock()
436
400
 
437
401
    def test_clone_tree_revision(self):
463
427
            revision_id='a')
464
428
        self.assertEqual(['a'], made_tree.get_parent_ids())
465
429
 
466
 
    def test_post_build_tree_hook(self):
467
 
        calls = []
468
 
        def track_post_build_tree(tree):
469
 
            calls.append(tree.last_revision())
470
 
        source = self.make_branch_and_tree('source')
471
 
        source.commit('a', rev_id='a', allow_pointless=True)
472
 
        source.commit('b', rev_id='b', allow_pointless=True)
473
 
        self.build_tree(['new/'])
474
 
        made_control = self.bzrdir_format.initialize('new')
475
 
        source.branch.repository.clone(made_control)
476
 
        source.branch.clone(made_control)
477
 
        MutableTree.hooks.install_named_hook("post_build_tree",
478
 
            track_post_build_tree, "Test")
479
 
        made_tree = self.workingtree_format.initialize(made_control,
480
 
            revision_id='a')
481
 
        self.assertEqual(['a'], calls)
482
 
 
483
430
    def test_update_sets_last_revision(self):
484
431
        # working tree formats from the meta-dir format and newer support
485
432
        # setting the last revision on a tree independently of that on the
489
436
        # that formats where initialising a branch does not initialise a
490
437
        # tree - and thus have separable entities - support skewing the
491
438
        # two things.
492
 
        self.requireBranchReference()
493
 
        wt = self.make_branch_and_tree('tree')
 
439
        main_branch = self.make_branch('tree')
 
440
        try:
 
441
            # if there is a working tree now, this is not supported.
 
442
            main_branch.bzrdir.open_workingtree()
 
443
            return
 
444
        except errors.NoWorkingTree:
 
445
            pass
 
446
        wt = main_branch.bzrdir.create_workingtree()
494
447
        # create an out of date working tree by making a checkout in this
495
448
        # current format
496
449
        self.build_tree(['checkout/', 'tree/file'])
497
450
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
498
 
        checkout.set_branch_reference(wt.branch)
 
451
        branch.BranchReferenceFormat().initialize(checkout,
 
452
            target_branch=main_branch)
499
453
        old_tree = self.workingtree_format.initialize(checkout)
500
454
        # now commit to 'tree'
501
455
        wt.add('file')
502
456
        wt.commit('A', rev_id='A')
503
457
        # and update old_tree
504
458
        self.assertEqual(0, old_tree.update())
505
 
        self.assertPathExists('checkout/file')
 
459
        self.failUnlessExists('checkout/file')
506
460
        self.assertEqual(['A'], old_tree.get_parent_ids())
507
461
 
508
462
    def test_update_sets_root_id(self):
523
477
        wt.commit('A', rev_id='A')
524
478
        # and update checkout
525
479
        self.assertEqual(0, checkout.update())
526
 
        self.assertPathExists('checkout/file')
 
480
        self.failUnlessExists('checkout/file')
527
481
        self.assertEqual(wt.get_root_id(), checkout.get_root_id())
528
482
        self.assertNotEqual(None, wt.get_root_id())
529
483
 
550
504
        # that formats where initialising a branch does not initialise a
551
505
        # tree - and thus have separable entities - support skewing the
552
506
        # two things.
553
 
        self.requireBranchReference()
554
 
        wt = self.make_branch_and_tree('tree')
 
507
        main_branch = self.make_branch('tree')
 
508
        try:
 
509
            # if there is a working tree now, this is not supported.
 
510
            main_branch.bzrdir.open_workingtree()
 
511
            return
 
512
        except errors.NoWorkingTree:
 
513
            pass
 
514
        wt = main_branch.bzrdir.create_workingtree()
555
515
        # create an out of date working tree by making a checkout in this
556
516
        # current format
557
517
        self.build_tree(['checkout/', 'tree/file'])
558
518
        checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
559
 
        checkout.set_branch_reference(wt.branch)
 
519
        branch.BranchReferenceFormat().initialize(checkout,
 
520
            target_branch=main_branch)
560
521
        old_tree = self.workingtree_format.initialize(checkout)
561
522
        # now commit to 'tree'
562
523
        wt.add('file')
597
558
            a.close()
598
559
        this.revert()
599
560
        self.assertFileEqual('a test\n', 'b1/a')
600
 
        self.assertPathExists('b1/b.~1~')
601
 
        self.assertPathDoesNotExist('b1/c')
602
 
        self.assertPathDoesNotExist('b1/a.~1~')
603
 
        self.assertPathExists('b1/d')
 
561
        self.failUnlessExists('b1/b.~1~')
 
562
        self.failIfExists('b1/c')
 
563
        self.failIfExists('b1/a.~1~')
 
564
        self.failUnlessExists('b1/d')
604
565
 
605
566
    def test_update_updates_bound_branch_no_local_commits(self):
606
567
        # doing an update in a tree updates the branch its bound to too.
644
605
        # which should have pivoted the local tip into a merge
645
606
        self.assertEqual([master_tip, 'bar'], tree.get_parent_ids())
646
607
        # and the local branch history should match the masters now.
647
 
        self.assertEqual(master_tree.branch.last_revision(),
648
 
            tree.branch.last_revision())
 
608
        self.assertEqual(master_tree.branch.revision_history(),
 
609
            tree.branch.revision_history())
649
610
 
650
611
    def test_update_takes_revision_parameter(self):
651
612
        wt = self.make_branch_and_tree('wt')
665
626
        # FIXME: This doesn't really test that it works; also this is not
666
627
        # implementation-independent. mbp 20070226
667
628
        tree = self.make_branch_and_tree('master')
668
 
        if not isinstance(tree, InventoryWorkingTree):
669
 
            raise TestNotApplicable("merge-hashes is specific to bzr "
670
 
                "working trees")
671
629
        tree._transport.put_bytes('merge-hashes', 'asdfasdf')
672
630
        self.assertRaises(errors.MergeModifiedFormatError, tree.merge_modified)
673
631
 
707
665
    def make_merge_conflicts(self):
708
666
        from bzrlib.merge import merge_inner
709
667
        tree = self.make_branch_and_tree('mine')
710
 
        with file('mine/bloo', 'wb') as f: f.write('one')
711
 
        with file('mine/blo', 'wb') as f: f.write('on')
 
668
        file('mine/bloo', 'wb').write('one')
 
669
        file('mine/blo', 'wb').write('on')
712
670
        tree.add(['bloo', 'blo'])
713
671
        tree.commit("blah", allow_pointless=False)
714
672
        base = tree.branch.repository.revision_tree(tree.last_revision())
715
 
        controldir.ControlDir.open("mine").sprout("other")
716
 
        with file('other/bloo', 'wb') as f: f.write('two')
 
673
        bzrdir.BzrDir.open("mine").sprout("other")
 
674
        file('other/bloo', 'wb').write('two')
717
675
        othertree = WorkingTree.open('other')
718
676
        othertree.commit('blah', allow_pointless=False)
719
 
        with file('mine/bloo', 'wb') as f: f.write('three')
 
677
        file('mine/bloo', 'wb').write('three')
720
678
        tree.commit("blah", allow_pointless=False)
721
679
        merge_inner(tree.branch, othertree, base, this_tree=tree)
722
680
        return tree
772
730
    def test_format_description(self):
773
731
        tree = self.make_branch_and_tree('tree')
774
732
        text = tree._format.get_format_description()
775
 
        self.assertTrue(len(text))
 
733
        self.failUnless(len(text))
776
734
 
777
735
    def test_branch_attribute_is_not_settable(self):
778
736
        # the branch attribute is an aspect of the working tree, not a
809
767
            tree.lock_read()
810
768
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
811
769
                    [(path, ie.kind) for path,ie in
812
 
                                tree.iter_entries_by_dir()])
 
770
                                tree.inventory.iter_entries()])
813
771
            tree.unlock()
814
772
        finally:
815
773
            osutils.normalized_filename = orig
831
789
    def test__write_inventory(self):
832
790
        # The private interface _write_inventory is currently used by transform.
833
791
        tree = self.make_branch_and_tree('.')
834
 
        if not isinstance(tree, InventoryWorkingTree):
835
 
            raise TestNotApplicable("_write_inventory does not exist on "
836
 
                "non-inventory working trees")
837
792
        # if we write write an inventory then do a walkdirs we should get back
838
793
        # missing entries, and actual, and unknowns as appropriate.
839
794
        self.build_tree(['present', 'unknown'])
960
915
        else:
961
916
            case_sensitive = True
962
917
        tree = self.make_branch_and_tree('test')
 
918
        if tree.__class__ == WorkingTree2:
 
919
            raise TestSkipped('WorkingTree2 is not supported')
963
920
        self.assertEqual(case_sensitive, tree.case_sensitive)
964
 
        if not isinstance(tree, InventoryWorkingTree):
965
 
            raise TestNotApplicable("get_format_string is only available "
966
 
                                    "on bzr working trees")
967
 
        # now we cheat, and make a file that matches the case-sensitive name
968
 
        t = tree.bzrdir.get_workingtree_transport(None)
969
 
        try:
970
 
            content = tree._format.get_format_string()
971
 
        except NotImplementedError:
972
 
            # All-in-one formats didn't have a separate format string.
973
 
            content = tree.bzrdir._format.get_format_string()
974
 
        t.put_bytes(tree._format.case_sensitive_filename, content)
975
 
        tree = tree.bzrdir.open_workingtree()
976
 
        self.assertFalse(tree.case_sensitive)
977
 
 
978
 
    def test_supports_executable(self):
979
 
        self.build_tree(['filename'])
980
 
        tree = self.make_branch_and_tree('.')
981
 
        tree.add('filename')
982
 
        self.assertIsInstance(tree._supports_executable(), bool)
983
 
        if tree._supports_executable():
984
 
            tree.lock_read()
985
 
            try:
986
 
                self.assertFalse(tree.is_executable(tree.path2id('filename')))
987
 
            finally:
988
 
                tree.unlock()
989
 
            os.chmod('filename', 0755)
990
 
            self.addCleanup(tree.lock_read().unlock)
991
 
            self.assertTrue(tree.is_executable(tree.path2id('filename')))
992
 
        else:
993
 
            self.addCleanup(tree.lock_read().unlock)
994
 
            self.assertFalse(tree.is_executable(tree.path2id('filename')))
995
921
 
996
922
    def test_all_file_ids_with_missing(self):
997
923
        tree = self.make_branch_and_tree('tree')
1043
969
            4 5-M
1044
970
            |
1045
971
            W
1046
 
        """
1047
 
        format = self.workingtree_format.get_controldir_for_branch()
1048
 
        builder = self.make_branch_builder(".", format=format)
 
972
         """
 
973
        builder = branchbuilder.BranchBuilder(
 
974
            self.get_transport(),
 
975
            format=self.workingtree_format._matchingbzrdir)
1049
976
        builder.start_series()
1050
977
        # mainline
1051
978
        builder.build_snapshot(
1127
1054
        self.assertEqual(0, wt.update(revision='1'))
1128
1055
        self.assertEqual('1', wt.last_revision())
1129
1056
        self.assertEqual(tip, wt.branch.last_revision())
1130
 
        self.assertPathExists('checkout/file1')
1131
 
        self.assertPathDoesNotExist('checkout/file4')
1132
 
        self.assertPathDoesNotExist('checkout/file5')
 
1057
        self.failUnlessExists('checkout/file1')
 
1058
        self.failIfExists('checkout/file4')
 
1059
        self.failIfExists('checkout/file5')
1133
1060
 
1134
1061
 
1135
1062
class TestIllegalPaths(TestCaseWithWorkingTree):
1138
1065
        if osutils.normalizes_filenames():
1139
1066
            # You *can't* create an illegal filename on OSX.
1140
1067
            raise tests.TestNotApplicable('OSX normalizes filenames')
1141
 
        self.requireFeature(features.UTF8Filesystem)
 
1068
        self.requireFeature(tests.UTF8Filesystem)
1142
1069
        # We require a UTF8 filesystem, because otherwise we would need to get
1143
1070
        # tricky to figure out how to create an illegal filename.
1144
1071
        # \xb5 is an illegal path because it should be \xc2\xb5 for UTF-8
1168
1095
 
1169
1096
class TestControlComponent(TestCaseWithWorkingTree):
1170
1097
    """WorkingTree implementations adequately implement ControlComponent."""
1171
 
 
 
1098
    
1172
1099
    def test_urls(self):
1173
1100
        wt = self.make_branch_and_tree('wt')
1174
1101
        self.assertIsInstance(wt.user_url, str)
1177
1104
        # above the control dir but we might need to relax that?
1178
1105
        self.assertEqual(wt.control_url.find(wt.user_url), 0)
1179
1106
        self.assertEqual(wt.control_url, wt.control_transport.base)
1180
 
 
1181
 
 
1182
 
class TestWorthSavingLimit(TestCaseWithWorkingTree):
1183
 
 
1184
 
    def make_wt_with_worth_saving_limit(self):
1185
 
        wt = self.make_branch_and_tree('wt')
1186
 
        if getattr(wt, '_worth_saving_limit', None) is None:
1187
 
            raise tests.TestNotApplicable('no _worth_saving_limit for'
1188
 
                                          ' this tree type')
1189
 
        wt.lock_write()
1190
 
        self.addCleanup(wt.unlock)
1191
 
        return wt
1192
 
 
1193
 
    def test_not_set(self):
1194
 
        # Default should be 10
1195
 
        wt = self.make_wt_with_worth_saving_limit()
1196
 
        self.assertEqual(10, wt._worth_saving_limit())
1197
 
        ds = wt.current_dirstate()
1198
 
        self.assertEqual(10, ds._worth_saving_limit)
1199
 
 
1200
 
    def test_set_in_branch(self):
1201
 
        wt = self.make_wt_with_worth_saving_limit()
1202
 
        conf = wt.get_config_stack()
1203
 
        conf.set('bzr.workingtree.worth_saving_limit', '20')
1204
 
        self.assertEqual(20, wt._worth_saving_limit())
1205
 
        ds = wt.current_dirstate()
1206
 
        self.assertEqual(10, ds._worth_saving_limit)
1207
 
 
1208
 
    def test_invalid(self):
1209
 
        wt = self.make_wt_with_worth_saving_limit()
1210
 
        conf = wt.get_config_stack()
1211
 
        conf.set('bzr.workingtree.worth_saving_limit', 'a')
1212
 
        # If the config entry is invalid, default to 10
1213
 
        warnings = []
1214
 
        def warning(*args):
1215
 
            warnings.append(args[0] % args[1:])
1216
 
        self.overrideAttr(trace, 'warning', warning)
1217
 
        self.assertEqual(10, wt._worth_saving_limit())
1218
 
        self.assertLength(1, warnings)
1219
 
        self.assertEquals('Value "a" is not valid for'
1220
 
                          ' "bzr.workingtree.worth_saving_limit"',
1221
 
                          warnings[0])
1222
 
 
1223
 
 
1224
 
class TestFormatAttributes(TestCaseWithWorkingTree):
1225
 
 
1226
 
    def test_versioned_directories(self):
1227
 
        self.assertSubset(
1228
 
            [self.workingtree_format.supports_versioned_directories],
1229
 
            (True, False))