~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

MergeĀ fromĀ jam-integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.errors import NotBranchError, NotVersionedError
21
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
 
53
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
67
        branch = Branch.initialize(u'.')
65
68
        wt, relpath = WorkingTree.open_containing()
66
69
        self.assertEqual('', relpath)
67
 
        self.assertEqual(wt.basedir, branch.base)
 
70
        self.assertEqual(wt.basedir + '/', branch.base)
68
71
        wt, relpath = WorkingTree.open_containing(u'.')
69
72
        self.assertEqual('', relpath)
70
 
        self.assertEqual(wt.basedir, branch.base)
 
73
        self.assertEqual(wt.basedir + '/', branch.base)
71
74
        wt, relpath = WorkingTree.open_containing('./foo')
72
75
        self.assertEqual('foo', relpath)
73
 
        self.assertEqual(wt.basedir, branch.base)
 
76
        self.assertEqual(wt.basedir + '/', branch.base)
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
83
        branch = Branch.initialize(u'.')
81
84
        tree = WorkingTree(branch.base, branch)
82
85
        self.assertEqual(branch, tree.branch)
83
 
        self.assertEqual(branch.base, tree.basedir)
 
86
        self.assertEqual(branch.base, tree.basedir + '/')
84
87
    
85
88
    def test_construct_without_branch(self):
86
89
        branch = Branch.initialize(u'.')
87
90
        tree = WorkingTree(branch.base)
88
91
        self.assertEqual(branch.base, tree.branch.base)
89
 
        self.assertEqual(branch.base, tree.basedir)
 
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
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
102
        branch = Branch.initialize(u'.')
100
103
        tree = WorkingTree(branch.base)
101
104
        tree.lock_read()
102
 
        self.assertEqual(1, tree.branch._lock_count)
103
 
        self.assertEqual('r', tree.branch._lock_mode)
 
105
        self.assertEqual('r', tree.branch.peek_lock_mode())
104
106
        tree.unlock()
105
 
        self.assertEqual(None, tree.branch._lock_count)
 
107
        self.assertEqual(None, tree.branch.peek_lock_mode())
106
108
        tree.lock_write()
107
 
        self.assertEqual(1, tree.branch._lock_count)
108
 
        self.assertEqual('w', tree.branch._lock_mode)
 
109
        self.assertEqual('w', tree.branch.peek_lock_mode())
109
110
        tree.unlock()
110
 
        self.assertEqual(None, tree.branch._lock_count)
 
111
        self.assertEqual(None, tree.branch.peek_lock_mode())
111
112
 
112
113
    def get_pullable_branches(self):
113
114
        self.build_tree(['from/', 'from/file', 'to/'])
121
122
    def test_pull(self):
122
123
        br_a, br_b = self.get_pullable_branches()
123
124
        br_b.working_tree().pull(br_a)
124
 
        self.failUnless(br_b.has_revision('A'))
 
125
        self.failUnless(br_b.repository.has_revision('A'))
125
126
        self.assertEqual(['A'], br_b.revision_history())
126
127
 
127
128
    def test_pull_overwrites(self):
129
130
        br_b.working_tree().commit('foo', rev_id='B')
130
131
        self.assertEqual(['B'], br_b.revision_history())
131
132
        br_b.working_tree().pull(br_a, overwrite=True)
132
 
        self.failUnless(br_b.has_revision('A'))
133
 
        self.failUnless(br_b.has_revision('B'))
 
133
        self.failUnless(br_b.repository.has_revision('A'))
 
134
        self.failUnless(br_b.repository.has_revision('B'))
134
135
        self.assertEqual(['A'], br_b.revision_history())
135
136
 
136
137
    def test_revert(self):
168
169
        self.assertEquals(list(tree.unknowns()),
169
170
                          ['hello.txt'])
170
171
 
 
172
    def test_hashcache(self):
 
173
        from bzrlib.tests.test_hashcache import pause
 
174
        b = Branch.initialize(u'.')
 
175
        tree = WorkingTree(u'.', b)
 
176
        self.build_tree(['hello.txt',
 
177
                         'hello.txt~'])
 
178
        tree.add('hello.txt')
 
179
        pause()
 
180
        sha = tree.get_file_sha1(tree.path2id('hello.txt'))
 
181
        self.assertEqual(1, tree._hashcache.miss_count)
 
182
        tree2 = WorkingTree(u'.', b)
 
183
        sha2 = tree2.get_file_sha1(tree2.path2id('hello.txt'))
 
184
        self.assertEqual(0, tree2._hashcache.miss_count)
 
185
        self.assertEqual(1, tree2._hashcache.hit_count)