~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
from bzrlib.branch import Branch
20
20
from bzrlib.errors import NotBranchError, NotVersionedError
21
 
from bzrlib.selftest import TestCaseInTempDir
 
21
from bzrlib.tests import TestCaseInTempDir
22
22
from bzrlib.trace import mutter
 
23
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
23
24
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
24
25
                                WorkingTree)
25
26
 
50
51
class TestWorkingTree(TestCaseInTempDir):
51
52
 
52
53
    def test_listfiles(self):
53
 
        branch = Branch.initialize('.')
 
54
        branch = Branch.initialize(u'.')
54
55
        os.mkdir('dir')
55
56
        print >> open('file', 'w'), "content"
56
 
        os.symlink('target', 'symlink')
 
57
        if has_symlinks():
 
58
            os.symlink('target', 'symlink')
57
59
        tree = branch.working_tree()
58
60
        files = list(tree.list_files())
59
61
        self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory()))
60
62
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
61
 
        self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
 
63
        if has_symlinks():
 
64
            self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
62
65
 
63
66
    def test_open_containing(self):
64
 
        branch = Branch.initialize('.')
 
67
        branch = Branch.initialize(u'.')
65
68
        wt, relpath = WorkingTree.open_containing()
66
69
        self.assertEqual('', relpath)
67
70
        self.assertEqual(wt.basedir, branch.base)
68
 
        wt, relpath = WorkingTree.open_containing('.')
 
71
        wt, relpath = WorkingTree.open_containing(u'.')
69
72
        self.assertEqual('', relpath)
70
73
        self.assertEqual(wt.basedir, branch.base)
71
74
        wt, relpath = WorkingTree.open_containing('./foo')
74
77
        # paths that are urls are just plain wrong for working trees.
75
78
        self.assertRaises(NotBranchError,
76
79
                          WorkingTree.open_containing, 
77
 
                          'file:///' + os.getcwdu())
 
80
                          'file:///' + getcwd())
78
81
 
79
82
    def test_construct_with_branch(self):
80
 
        branch = Branch.initialize('.')
 
83
        branch = Branch.initialize(u'.')
81
84
        tree = WorkingTree(branch.base, branch)
82
85
        self.assertEqual(branch, tree.branch)
83
86
        self.assertEqual(branch.base, tree.basedir)
84
87
    
85
88
    def test_construct_without_branch(self):
86
 
        branch = Branch.initialize('.')
 
89
        branch = Branch.initialize(u'.')
87
90
        tree = WorkingTree(branch.base)
88
91
        self.assertEqual(branch.base, tree.branch.base)
89
92
        self.assertEqual(branch.base, tree.basedir)
90
93
 
91
94
    def test_basic_relpath(self):
92
95
        # for comprehensive relpath tests, see whitebox.py.
93
 
        branch = Branch.initialize('.')
 
96
        branch = Branch.initialize(u'.')
94
97
        tree = WorkingTree(branch.base)
95
98
        self.assertEqual('child',
96
 
                         tree.relpath(os.path.join(os.getcwd(), 'child')))
 
99
                         tree.relpath(pathjoin(getcwd(), 'child')))
97
100
 
98
101
    def test_lock_locks_branch(self):
99
 
        branch = Branch.initialize('.')
 
102
        branch = Branch.initialize(u'.')
100
103
        tree = WorkingTree(branch.base)
101
104
        tree.lock_read()
102
105
        self.assertEqual(1, tree.branch._lock_count)
135
138
 
136
139
    def test_revert(self):
137
140
        """Test selected-file revert"""
138
 
        b = Branch.initialize('.')
 
141
        b = Branch.initialize(u'.')
139
142
 
140
143
        self.build_tree(['hello.txt'])
141
144
        file('hello.txt', 'w').write('initial hello')
161
164
        self.check_file_contents('hello.txt~', 'new hello')
162
165
 
163
166
    def test_unknowns(self):
164
 
        b = Branch.initialize('.')
165
 
        tree = WorkingTree('.', b)
 
167
        b = Branch.initialize(u'.')
 
168
        tree = WorkingTree(u'.', b)
166
169
        self.build_tree(['hello.txt',
167
170
                         'hello.txt~'])
168
171
        self.assertEquals(list(tree.unknowns()),
169
172
                          ['hello.txt'])
170
173
 
 
174
    def test_hashcache(self):
 
175
        from bzrlib.tests.test_hashcache import pause
 
176
        b = Branch.initialize(u'.')
 
177
        tree = WorkingTree(u'.', b)
 
178
        self.build_tree(['hello.txt',
 
179
                         'hello.txt~'])
 
180
        tree.add('hello.txt')
 
181
        pause()
 
182
        sha = tree.get_file_sha1(tree.path2id('hello.txt'))
 
183
        self.assertEqual(1, tree._hashcache.miss_count)
 
184
        tree2 = WorkingTree(u'.', b)
 
185
        sha2 = tree2.get_file_sha1(tree2.path2id('hello.txt'))
 
186
        self.assertEqual(0, tree2._hashcache.miss_count)
 
187
        self.assertEqual(1, tree2._hashcache.hit_count)