~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    bzrdir,
27
27
    errors,
28
28
    osutils,
 
29
    symbol_versioning,
29
30
    tests,
30
31
    urlutils,
31
32
    )
41
42
    TreeDirectory,
42
43
    TreeFile,
43
44
    TreeLink,
 
45
    InventoryWorkingTree,
44
46
    WorkingTree,
45
47
    )
46
48
from bzrlib.conflicts import ConflictList, TextConflict, ContentsConflict
203
205
        os.unlink('hello.txt')
204
206
        tree.remove('hello.txt')
205
207
        tree.revert(['hello.txt'])
206
 
        self.failUnlessExists('hello.txt')
 
208
        self.assertPathExists('hello.txt')
207
209
 
208
210
    def test_versioned_files_not_unknown(self):
209
211
        tree = self.make_branch_and_tree('.')
244
246
        revid = b.revision_history()[0]
245
247
        self.log('first revision_id is {%s}' % revid)
246
248
 
247
 
        inv = b.repository.get_inventory(revid)
248
 
        self.log('contents of inventory: %r' % inv.entries())
 
249
        tree = b.repository.revision_tree(revid)
 
250
        self.log('contents of tree: %r' % list(tree.iter_entries_by_dir()))
249
251
 
250
 
        self.check_inventory_shape(inv,
251
 
                                   ['dir/', 'dir/sub/', 'dir/sub/file'])
 
252
        self.check_tree_shape(tree, ['dir/', 'dir/sub/', 'dir/sub/file'])
252
253
        wt.rename_one('dir', 'newdir')
253
254
 
254
255
        wt.lock_read()
255
 
        self.check_inventory_shape(wt.inventory,
 
256
        self.check_tree_shape(wt,
256
257
                                   ['newdir/', 'newdir/sub/', 'newdir/sub/file'])
257
258
        wt.unlock()
258
259
        wt.rename_one('newdir/sub', 'newdir/newsub')
259
260
        wt.lock_read()
260
 
        self.check_inventory_shape(wt.inventory,
261
 
                                   ['newdir/', 'newdir/newsub/',
 
261
        self.check_tree_shape(wt, ['newdir/', 'newdir/newsub/',
262
262
                                    'newdir/newsub/file'])
263
263
        wt.unlock()
264
264
 
327
327
        # because some formats mutate the branch to set it on the tree
328
328
        # we need to alter the branch to let this pass.
329
329
        try:
330
 
            wt.branch.set_revision_history(['A', 'B'])
 
330
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
331
                wt.branch.set_revision_history, ['A', 'B'])
331
332
        except errors.NoSuchRevision, e:
332
333
            self.assertEqual('B', e.revision)
333
334
            raise TestSkipped("Branch format does not permit arbitrary"
398
399
        wt.set_parent_ids(['B'])
399
400
        tree = wt.basis_tree()
400
401
        tree.lock_read()
401
 
        self.failUnless(tree.has_filename('bar'))
 
402
        self.assertTrue(tree.has_filename('bar'))
402
403
        tree.unlock()
403
404
        wt.set_parent_ids(['A'])
404
405
        tree = wt.basis_tree()
405
406
        tree.lock_read()
406
 
        self.failUnless(tree.has_filename('foo'))
 
407
        self.assertTrue(tree.has_filename('foo'))
407
408
        tree.unlock()
408
409
 
409
410
    def test_clone_tree_revision(self):
464
465
        wt.commit('A', rev_id='A')
465
466
        # and update old_tree
466
467
        self.assertEqual(0, old_tree.update())
467
 
        self.failUnlessExists('checkout/file')
 
468
        self.assertPathExists('checkout/file')
468
469
        self.assertEqual(['A'], old_tree.get_parent_ids())
469
470
 
470
471
    def test_update_sets_root_id(self):
485
486
        wt.commit('A', rev_id='A')
486
487
        # and update checkout
487
488
        self.assertEqual(0, checkout.update())
488
 
        self.failUnlessExists('checkout/file')
 
489
        self.assertPathExists('checkout/file')
489
490
        self.assertEqual(wt.get_root_id(), checkout.get_root_id())
490
491
        self.assertNotEqual(None, wt.get_root_id())
491
492
 
566
567
            a.close()
567
568
        this.revert()
568
569
        self.assertFileEqual('a test\n', 'b1/a')
569
 
        self.failUnlessExists('b1/b.~1~')
570
 
        self.failIfExists('b1/c')
571
 
        self.failIfExists('b1/a.~1~')
572
 
        self.failUnlessExists('b1/d')
 
570
        self.assertPathExists('b1/b.~1~')
 
571
        self.assertPathDoesNotExist('b1/c')
 
572
        self.assertPathDoesNotExist('b1/a.~1~')
 
573
        self.assertPathExists('b1/d')
573
574
 
574
575
    def test_update_updates_bound_branch_no_local_commits(self):
575
576
        # doing an update in a tree updates the branch its bound to too.
738
739
    def test_format_description(self):
739
740
        tree = self.make_branch_and_tree('tree')
740
741
        text = tree._format.get_format_description()
741
 
        self.failUnless(len(text))
 
742
        self.assertTrue(len(text))
742
743
 
743
744
    def test_branch_attribute_is_not_settable(self):
744
745
        # the branch attribute is an aspect of the working tree, not a
775
776
            tree.lock_read()
776
777
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
777
778
                    [(path, ie.kind) for path,ie in
778
 
                                tree.inventory.iter_entries()])
 
779
                                tree.iter_entries_by_dir()])
779
780
            tree.unlock()
780
781
        finally:
781
782
            osutils.normalized_filename = orig
797
798
    def test__write_inventory(self):
798
799
        # The private interface _write_inventory is currently used by transform.
799
800
        tree = self.make_branch_and_tree('.')
 
801
        if not isinstance(tree, InventoryWorkingTree):
 
802
            raise TestNotApplicable("_write_inventory does not exist on "
 
803
                "non-inventory working trees")
800
804
        # if we write write an inventory then do a walkdirs we should get back
801
805
        # missing entries, and actual, and unknowns as appropriate.
802
806
        self.build_tree(['present', 'unknown'])
1070
1074
        self.assertEqual(0, wt.update(revision='1'))
1071
1075
        self.assertEqual('1', wt.last_revision())
1072
1076
        self.assertEqual(tip, wt.branch.last_revision())
1073
 
        self.failUnlessExists('checkout/file1')
1074
 
        self.failIfExists('checkout/file4')
1075
 
        self.failIfExists('checkout/file5')
 
1077
        self.assertPathExists('checkout/file1')
 
1078
        self.assertPathDoesNotExist('checkout/file4')
 
1079
        self.assertPathDoesNotExist('checkout/file5')
1076
1080
 
1077
1081
 
1078
1082
class TestIllegalPaths(TestCaseWithWorkingTree):
1120
1124
        # above the control dir but we might need to relax that?
1121
1125
        self.assertEqual(wt.control_url.find(wt.user_url), 0)
1122
1126
        self.assertEqual(wt.control_url, wt.control_transport.base)
 
1127
 
 
1128
 
 
1129
class TestWorthSavingLimit(TestCaseWithWorkingTree):
 
1130
 
 
1131
    def make_wt_with_worth_saving_limit(self):
 
1132
        wt = self.make_branch_and_tree('wt')
 
1133
        if getattr(wt, '_worth_saving_limit', None) is None:
 
1134
            raise tests.TestNotApplicable('no _worth_saving_limit for'
 
1135
                                          ' this tree type')
 
1136
        wt.lock_write()
 
1137
        self.addCleanup(wt.unlock)
 
1138
        return wt
 
1139
 
 
1140
    def test_not_set(self):
 
1141
        # Default should be 10
 
1142
        wt = self.make_wt_with_worth_saving_limit()
 
1143
        self.assertEqual(10, wt._worth_saving_limit())
 
1144
        ds = wt.current_dirstate()
 
1145
        self.assertEqual(10, ds._worth_saving_limit)
 
1146
 
 
1147
    def test_set_in_branch(self):
 
1148
        wt = self.make_wt_with_worth_saving_limit()
 
1149
        config = wt.branch.get_config()
 
1150
        config.set_user_option('bzr.workingtree.worth_saving_limit', '20')
 
1151
        self.assertEqual(20, wt._worth_saving_limit())
 
1152
        ds = wt.current_dirstate()
 
1153
        self.assertEqual(10, ds._worth_saving_limit)
 
1154
 
 
1155
    def test_invalid(self):
 
1156
        wt = self.make_wt_with_worth_saving_limit()
 
1157
        config = wt.branch.get_config()
 
1158
        config.set_user_option('bzr.workingtree.worth_saving_limit', 'a')
 
1159
        # If the config entry is invalid, default to 10
 
1160
        # TODO: This writes a warning to the user, trap it somehow
 
1161
        self.assertEqual(10, wt._worth_saving_limit())