~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
23
22
 
24
23
from bzrlib import (
25
24
    branch,
27
26
    bzrdir,
28
27
    errors,
29
28
    osutils,
 
29
    symbol_versioning,
30
30
    tests,
31
31
    urlutils,
32
 
    workingtree,
33
 
    )
34
 
from bzrlib.errors import (NotBranchError, NotVersionedError,
35
 
                           UnsupportedOperation, PathsNotVersionedError)
 
32
    )
 
33
from bzrlib.errors import (
 
34
    UnsupportedOperation,
 
35
    PathsNotVersionedError,
 
36
    )
36
37
from bzrlib.inventory import Inventory
37
38
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
38
39
from bzrlib.tests import TestSkipped, TestNotApplicable
39
40
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
40
 
from bzrlib.trace import mutter
41
 
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
42
 
                                WorkingTree, WorkingTree2)
 
41
from bzrlib.workingtree import (
 
42
    TreeDirectory,
 
43
    TreeFile,
 
44
    TreeLink,
 
45
    InventoryWorkingTree,
 
46
    WorkingTree,
 
47
    )
43
48
from bzrlib.conflicts import ConflictList, TextConflict, ContentsConflict
44
49
 
45
50
 
46
51
class TestWorkingTree(TestCaseWithWorkingTree):
47
52
 
 
53
    def test_branch_builder(self):
 
54
        # Just a smoke test that we get a branch at the specified relpath
 
55
        builder = self.make_branch_builder('foobar')
 
56
        br = branch.Branch.open('foobar')
 
57
 
48
58
    def test_list_files(self):
49
59
        tree = self.make_branch_and_tree('.')
50
60
        self.build_tree(['dir/', 'file'])
195
205
        os.unlink('hello.txt')
196
206
        tree.remove('hello.txt')
197
207
        tree.revert(['hello.txt'])
198
 
        self.failUnlessExists('hello.txt')
 
208
        self.assertPathExists('hello.txt')
199
209
 
200
210
    def test_versioned_files_not_unknown(self):
201
211
        tree = self.make_branch_and_tree('.')
236
246
        revid = b.revision_history()[0]
237
247
        self.log('first revision_id is {%s}' % revid)
238
248
 
239
 
        inv = b.repository.get_inventory(revid)
240
 
        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()))
241
251
 
242
 
        self.check_inventory_shape(inv,
243
 
                                   ['dir/', 'dir/sub/', 'dir/sub/file'])
 
252
        self.check_tree_shape(tree, ['dir/', 'dir/sub/', 'dir/sub/file'])
244
253
        wt.rename_one('dir', 'newdir')
245
254
 
246
255
        wt.lock_read()
247
 
        self.check_inventory_shape(wt.inventory,
 
256
        self.check_tree_shape(wt,
248
257
                                   ['newdir/', 'newdir/sub/', 'newdir/sub/file'])
249
258
        wt.unlock()
250
259
        wt.rename_one('newdir/sub', 'newdir/newsub')
251
260
        wt.lock_read()
252
 
        self.check_inventory_shape(wt.inventory,
253
 
                                   ['newdir/', 'newdir/newsub/',
 
261
        self.check_tree_shape(wt, ['newdir/', 'newdir/newsub/',
254
262
                                    'newdir/newsub/file'])
255
263
        wt.unlock()
256
264
 
319
327
        # because some formats mutate the branch to set it on the tree
320
328
        # we need to alter the branch to let this pass.
321
329
        try:
322
 
            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'])
323
332
        except errors.NoSuchRevision, e:
324
333
            self.assertEqual('B', e.revision)
325
334
            raise TestSkipped("Branch format does not permit arbitrary"
390
399
        wt.set_parent_ids(['B'])
391
400
        tree = wt.basis_tree()
392
401
        tree.lock_read()
393
 
        self.failUnless(tree.has_filename('bar'))
 
402
        self.assertTrue(tree.has_filename('bar'))
394
403
        tree.unlock()
395
404
        wt.set_parent_ids(['A'])
396
405
        tree = wt.basis_tree()
397
406
        tree.lock_read()
398
 
        self.failUnless(tree.has_filename('foo'))
 
407
        self.assertTrue(tree.has_filename('foo'))
399
408
        tree.unlock()
400
409
 
401
410
    def test_clone_tree_revision(self):
456
465
        wt.commit('A', rev_id='A')
457
466
        # and update old_tree
458
467
        self.assertEqual(0, old_tree.update())
459
 
        self.failUnlessExists('checkout/file')
 
468
        self.assertPathExists('checkout/file')
460
469
        self.assertEqual(['A'], old_tree.get_parent_ids())
461
470
 
462
471
    def test_update_sets_root_id(self):
477
486
        wt.commit('A', rev_id='A')
478
487
        # and update checkout
479
488
        self.assertEqual(0, checkout.update())
480
 
        self.failUnlessExists('checkout/file')
 
489
        self.assertPathExists('checkout/file')
481
490
        self.assertEqual(wt.get_root_id(), checkout.get_root_id())
482
491
        self.assertNotEqual(None, wt.get_root_id())
483
492
 
558
567
            a.close()
559
568
        this.revert()
560
569
        self.assertFileEqual('a test\n', 'b1/a')
561
 
        self.failUnlessExists('b1/b.~1~')
562
 
        self.failIfExists('b1/c')
563
 
        self.failIfExists('b1/a.~1~')
564
 
        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')
565
574
 
566
575
    def test_update_updates_bound_branch_no_local_commits(self):
567
576
        # doing an update in a tree updates the branch its bound to too.
730
739
    def test_format_description(self):
731
740
        tree = self.make_branch_and_tree('tree')
732
741
        text = tree._format.get_format_description()
733
 
        self.failUnless(len(text))
 
742
        self.assertTrue(len(text))
734
743
 
735
744
    def test_branch_attribute_is_not_settable(self):
736
745
        # the branch attribute is an aspect of the working tree, not a
767
776
            tree.lock_read()
768
777
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
769
778
                    [(path, ie.kind) for path,ie in
770
 
                                tree.inventory.iter_entries()])
 
779
                                tree.iter_entries_by_dir()])
771
780
            tree.unlock()
772
781
        finally:
773
782
            osutils.normalized_filename = orig
789
798
    def test__write_inventory(self):
790
799
        # The private interface _write_inventory is currently used by transform.
791
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")
792
804
        # if we write write an inventory then do a walkdirs we should get back
793
805
        # missing entries, and actual, and unknowns as appropriate.
794
806
        self.build_tree(['present', 'unknown'])
915
927
        else:
916
928
            case_sensitive = True
917
929
        tree = self.make_branch_and_tree('test')
918
 
        if tree.__class__ == WorkingTree2:
919
 
            raise TestSkipped('WorkingTree2 is not supported')
920
930
        self.assertEqual(case_sensitive, tree.case_sensitive)
 
931
        # now we cheat, and make a file that matches the case-sensitive name
 
932
        t = tree.bzrdir.get_workingtree_transport(None)
 
933
        try:
 
934
            content = tree._format.get_format_string()
 
935
        except NotImplementedError:
 
936
            # All-in-one formats didn't have a separate format string.
 
937
            content = tree.bzrdir._format.get_format_string()
 
938
        t.put_bytes(tree._format.case_sensitive_filename, content)
 
939
        tree = tree.bzrdir.open_workingtree()
 
940
        self.assertFalse(tree.case_sensitive)
921
941
 
922
942
    def test_all_file_ids_with_missing(self):
923
943
        tree = self.make_branch_and_tree('tree')
1054
1074
        self.assertEqual(0, wt.update(revision='1'))
1055
1075
        self.assertEqual('1', wt.last_revision())
1056
1076
        self.assertEqual(tip, wt.branch.last_revision())
1057
 
        self.failUnlessExists('checkout/file1')
1058
 
        self.failIfExists('checkout/file4')
1059
 
        self.failIfExists('checkout/file5')
 
1077
        self.assertPathExists('checkout/file1')
 
1078
        self.assertPathDoesNotExist('checkout/file4')
 
1079
        self.assertPathDoesNotExist('checkout/file5')
1060
1080
 
1061
1081
 
1062
1082
class TestIllegalPaths(TestCaseWithWorkingTree):
1104
1124
        # above the control dir but we might need to relax that?
1105
1125
        self.assertEqual(wt.control_url.find(wt.user_url), 0)
1106
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())