/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
from bzrlib.branch import Branch
20
 
from bzrlib.errors import NotVersionedError
21
 
from bzrlib.selftest import TestCaseInTempDir
 
20
from bzrlib.errors import NotBranchError, NotVersionedError
 
21
from bzrlib.tests import TestCaseInTempDir
22
22
from bzrlib.trace import mutter
23
23
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
24
24
                                WorkingTree)
50
50
class TestWorkingTree(TestCaseInTempDir):
51
51
 
52
52
    def test_listfiles(self):
53
 
        branch = Branch.initialize('.')
 
53
        branch = Branch.initialize(u'.')
54
54
        os.mkdir('dir')
55
55
        print >> open('file', 'w'), "content"
56
56
        os.symlink('target', 'symlink')
60
60
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
61
61
        self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
62
62
 
 
63
    def test_open_containing(self):
 
64
        branch = Branch.initialize(u'.')
 
65
        wt, relpath = WorkingTree.open_containing()
 
66
        self.assertEqual('', relpath)
 
67
        self.assertEqual(wt.basedir, branch.base)
 
68
        wt, relpath = WorkingTree.open_containing(u'.')
 
69
        self.assertEqual('', relpath)
 
70
        self.assertEqual(wt.basedir, branch.base)
 
71
        wt, relpath = WorkingTree.open_containing('./foo')
 
72
        self.assertEqual('foo', relpath)
 
73
        self.assertEqual(wt.basedir, branch.base)
 
74
        # paths that are urls are just plain wrong for working trees.
 
75
        self.assertRaises(NotBranchError,
 
76
                          WorkingTree.open_containing, 
 
77
                          'file:///' + os.getcwdu())
 
78
 
63
79
    def test_construct_with_branch(self):
64
 
        branch = Branch.initialize('.')
 
80
        branch = Branch.initialize(u'.')
65
81
        tree = WorkingTree(branch.base, branch)
66
82
        self.assertEqual(branch, tree.branch)
67
83
        self.assertEqual(branch.base, tree.basedir)
68
84
    
69
85
    def test_construct_without_branch(self):
70
 
        branch = Branch.initialize('.')
 
86
        branch = Branch.initialize(u'.')
71
87
        tree = WorkingTree(branch.base)
72
88
        self.assertEqual(branch.base, tree.branch.base)
73
89
        self.assertEqual(branch.base, tree.basedir)
74
90
 
75
91
    def test_basic_relpath(self):
76
92
        # for comprehensive relpath tests, see whitebox.py.
77
 
        branch = Branch.initialize('.')
 
93
        branch = Branch.initialize(u'.')
78
94
        tree = WorkingTree(branch.base)
79
95
        self.assertEqual('child',
80
96
                         tree.relpath(os.path.join(os.getcwd(), 'child')))
81
97
 
82
98
    def test_lock_locks_branch(self):
83
 
        branch = Branch.initialize('.')
 
99
        branch = Branch.initialize(u'.')
84
100
        tree = WorkingTree(branch.base)
85
101
        tree.lock_read()
86
102
        self.assertEqual(1, tree.branch._lock_count)
96
112
    def get_pullable_branches(self):
97
113
        self.build_tree(['from/', 'from/file', 'to/'])
98
114
        br_a = Branch.initialize('from')
99
 
        br_a.add('file')
100
 
        br_a.working_tree().commit('foo', rev_id='A')
 
115
        tree = br_a.working_tree()
 
116
        tree.add('file')
 
117
        tree.commit('foo', rev_id='A')
101
118
        br_b = Branch.initialize('to')
102
119
        return br_a, br_b
103
120
 
118
135
 
119
136
    def test_revert(self):
120
137
        """Test selected-file revert"""
121
 
        b = Branch.initialize('.')
 
138
        b = Branch.initialize(u'.')
122
139
 
123
140
        self.build_tree(['hello.txt'])
124
141
        file('hello.txt', 'w').write('initial hello')
125
142
 
126
143
        self.assertRaises(NotVersionedError,
127
144
                          b.working_tree().revert, ['hello.txt'])
128
 
        
129
 
        b.add(['hello.txt'])
130
 
        b.working_tree().commit('create initial hello.txt')
 
145
        tree = WorkingTree(b.base, b)
 
146
        tree.add(['hello.txt'])
 
147
        tree.commit('create initial hello.txt')
131
148
 
132
149
        self.check_file_contents('hello.txt', 'initial hello')
133
150
        file('hello.txt', 'w').write('new hello')
134
151
        self.check_file_contents('hello.txt', 'new hello')
135
152
 
136
 
        wt = b.working_tree()
137
 
 
138
153
        # revert file modified since last revision
139
 
        wt.revert(['hello.txt'])
 
154
        tree.revert(['hello.txt'])
140
155
        self.check_file_contents('hello.txt', 'initial hello')
141
156
        self.check_file_contents('hello.txt~', 'new hello')
142
157
 
143
158
        # reverting again does not clobber the backup
144
 
        wt.revert(['hello.txt'])
 
159
        tree.revert(['hello.txt'])
145
160
        self.check_file_contents('hello.txt', 'initial hello')
146
161
        self.check_file_contents('hello.txt~', 'new hello')
 
162
 
 
163
    def test_unknowns(self):
 
164
        b = Branch.initialize(u'.')
 
165
        tree = WorkingTree(u'.', b)
 
166
        self.build_tree(['hello.txt',
 
167
                         'hello.txt~'])
 
168
        self.assertEquals(list(tree.unknowns()),
 
169
                          ['hello.txt'])
 
170