/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1852.16.5 by John Arbash Meinel
[merge] bzr.dev 2255, resolve conflicts, update copyrights
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.15.9 by Robert Collins
Add missing test script.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for the extra cases that WorkingTree.walkdirs can encounter."""
18
19
import os
20
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
21
from bzrlib import transform
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
22
from bzrlib.tests import SymlinkFeature
1852.15.9 by Robert Collins
Add missing test script.
23
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
24
25
# tests to write:
26
# type mismatches - file to link, dir, dir to file, link, link to file, dir
27
28
class TestWalkdirs(TestCaseWithWorkingTree):
29
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
30
    def get_tree_with_unknowns(self):
1852.15.9 by Robert Collins
Add missing test script.
31
        tree = self.make_branch_and_tree('.')
32
        self.build_tree([
33
            'unknown file',
34
            'unknown dir/',
35
            'unknown dir/a file',
36
            ])
37
        u_f_stat = os.lstat('unknown file')
38
        u_d_stat = os.lstat('unknown dir')
39
        u_d_f_stat = os.lstat('unknown dir/a file')
40
        expected_dirblocks = [
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
41
            (('', tree.path2id('')),
1852.15.9 by Robert Collins
Add missing test script.
42
             [
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
43
              ('unknown dir', 'unknown dir', 'directory', u_d_stat, None, None),
44
              ('unknown file', 'unknown file', 'file', u_f_stat, None, None),
45
             ]
46
            ),
47
            (('unknown dir', None),
48
             [('unknown dir/a file', 'a file', 'file', u_d_f_stat, None, None),
49
             ]
50
            ),
51
            ]
52
        return tree, expected_dirblocks
53
    
54
    def test_walkdir_unknowns(self):
55
        """unknown files and directories should be reported by walkdirs."""
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
56
        # test that its iterable by iterating:
1852.15.9 by Robert Collins
Add missing test script.
57
        result = []
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
58
        tree, expected_dirblocks = self.get_tree_with_unknowns()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
59
        tree.lock_read()
1852.15.9 by Robert Collins
Add missing test script.
60
        for dirinfo, dirblock in tree.walkdirs():
61
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
62
        tree.unlock()
1852.15.9 by Robert Collins
Add missing test script.
63
        # check each return value for debugging ease.
64
        for pos, item in enumerate(expected_dirblocks):
65
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
66
        self.assertEqual(len(expected_dirblocks), len(result))
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
67
68
    def test_walkdir_from_unknown_dir(self):
69
        """Doing a walkdir when the requested prefix is unknown but on disk."""
70
        result = []
71
        tree, expected_dirblocks = self.get_tree_with_unknowns()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
72
        tree.lock_read()
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
73
        for dirinfo, dirblock in tree.walkdirs('unknown dir'):
74
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
75
        tree.unlock()
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
76
        # check each return value for debugging ease.
77
        for pos, item in enumerate(expected_dirblocks[1:]):
78
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
79
        self.assertEqual(len(expected_dirblocks) - 1, len(result))
80
81
    def get_tree_with_missings(self):
82
        tree = self.make_branch_and_tree('.')
83
        paths = [
84
            'missing file',
85
            'missing dir/',
86
            'missing dir/a file',
87
            ]
88
        ids = [
89
            'a file',
90
            'a dir',
91
            'a dir-a file',
92
            ]
93
        self.build_tree(paths)
94
        tree.add(paths, ids)
95
        # now make the files be missing
96
        tree.bzrdir.root_transport.delete_tree('missing dir')
97
        tree.bzrdir.root_transport.delete('missing file')
98
        expected_dirblocks = [
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
99
            (('', tree.path2id('')),
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
100
             [
101
              ('missing dir', 'missing dir', 'unknown', None, 'a dir', 'directory'),
102
              ('missing file', 'missing file', 'unknown', None, 'a file', 'file'),
103
             ]
104
            ),
105
            (('missing dir', 'a dir'),
106
             [('missing dir/a file', 'a file', 'unknown', None, 'a dir-a file', 'file'),
107
             ]
108
            ),
109
            ]
110
        return tree, expected_dirblocks
111
    
112
    def test_walkdir_missings(self):
113
        """missing files and directories should be reported by walkdirs."""
114
        # test that its iterable by iterating:
115
        result = []
116
        tree, expected_dirblocks = self.get_tree_with_missings()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
117
        tree.lock_read()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
118
        for dirinfo, dirblock in tree.walkdirs():
119
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
120
        tree.unlock()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
121
        # check each return value for debugging ease.
122
        for pos, item in enumerate(expected_dirblocks):
123
            self.assertEqual(item, result[pos])
124
        self.assertEqual(len(expected_dirblocks), len(result))
125
126
    def test_walkdir_from_missing_dir(self):
127
        """Doing a walkdir when the requested prefix is missing but on disk."""
128
        result = []
129
        tree, expected_dirblocks = self.get_tree_with_missings()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
130
        tree.lock_read()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
131
        for dirinfo, dirblock in tree.walkdirs('missing dir'):
132
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
133
        tree.unlock()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
134
        # check each return value for debugging ease.
135
        for pos, item in enumerate(expected_dirblocks[1:]):
136
            self.assertEqual(item, result[pos])
137
        self.assertEqual(len(expected_dirblocks[1:]), len(result))
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
138
139
    def test_walkdirs_type_changes(self):
140
        """Walkdir shows the actual kinds on disk and the recorded kinds."""
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
141
        self.requireFeature(SymlinkFeature)
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
142
        tree = self.make_branch_and_tree('.')
143
        paths = ['file1', 'file2', 'dir1/', 'dir2/']
144
        ids = ['file1', 'file2', 'dir1', 'dir2']
145
        self.build_tree(paths)
146
        tree.add(paths, ids)
147
        tt = transform.TreeTransform(tree)
148
        root_transaction_id = tt.trans_id_tree_path('')
149
        tt.new_symlink('link1',
150
            root_transaction_id, 'link-target', 'link1')
151
        tt.new_symlink('link2',
152
            root_transaction_id, 'link-target', 'link2')
153
        tt.apply()
154
        tree.bzrdir.root_transport.delete_tree('dir1')
155
        tree.bzrdir.root_transport.delete_tree('dir2')
156
        tree.bzrdir.root_transport.delete('file1')
157
        tree.bzrdir.root_transport.delete('file2')
158
        tree.bzrdir.root_transport.delete('link1')
159
        tree.bzrdir.root_transport.delete('link2')
160
        changed_paths = ['dir1', 'file1/', 'link1', 'link2/']
161
        self.build_tree(changed_paths)
162
        os.symlink('target', 'dir2')
163
        os.symlink('target', 'file2')
164
        dir1_stat = os.lstat('dir1')
165
        dir2_stat = os.lstat('dir2')
166
        file1_stat = os.lstat('file1')
167
        file2_stat = os.lstat('file2')
168
        link1_stat = os.lstat('link1')
169
        link2_stat = os.lstat('link2')
170
        expected_dirblocks = [
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
171
             (('', tree.path2id('')),
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
172
              [('dir1', 'dir1', 'file', dir1_stat, 'dir1', 'directory'),
173
               ('dir2', 'dir2', 'symlink', dir2_stat, 'dir2', 'directory'),
174
               ('file1', 'file1', 'directory', file1_stat, 'file1', 'file'),
175
               ('file2', 'file2', 'symlink', file2_stat, 'file2', 'file'),
176
               ('link1', 'link1', 'file', link1_stat, 'link1', 'symlink'),
177
               ('link2', 'link2', 'directory', link2_stat, 'link2', 'symlink'),
178
              ]
179
             ),
180
             (('dir1', 'dir1'),
181
              [
182
              ]
183
             ),
184
             (('dir2', 'dir2'),
185
              [
186
              ]
187
             ),
188
             (('file1', None),
189
              [
190
              ]
191
             ),
192
             (('link2', None),
193
              [
194
              ]
195
             ),
196
            ]
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
197
        tree.lock_read()
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
198
        result = list(tree.walkdirs())
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
199
        tree.unlock()
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
200
        # check each return value for debugging ease.
201
        for pos, item in enumerate(expected_dirblocks):
202
            self.assertEqual(item, result[pos])
203
        self.assertEqual(len(expected_dirblocks), len(result))
2408.1.4 by Alexander Belchenko
workingtree_implementations: make usage of symlinks optional
204
205
    def test_walkdirs_type_changes_wo_symlinks(self):
206
        # similar to test_walkdirs_type_changes
207
        # but don't use symlinks for safe testing on win32
208
        tree = self.make_branch_and_tree('.')
209
        paths = ['file1', 'dir1/']
210
        ids = ['file1', 'dir1']
211
        self.build_tree(paths)
212
        tree.add(paths, ids)
213
        tree.bzrdir.root_transport.delete_tree('dir1')
214
        tree.bzrdir.root_transport.delete('file1')
215
        changed_paths = ['dir1', 'file1/']
216
        self.build_tree(changed_paths)
217
        dir1_stat = os.lstat('dir1')
218
        file1_stat = os.lstat('file1')
219
        expected_dirblocks = [
220
             (('', tree.path2id('')),
221
              [('dir1', 'dir1', 'file', dir1_stat, 'dir1', 'directory'),
222
               ('file1', 'file1', 'directory', file1_stat, 'file1', 'file'),
223
              ]
224
             ),
225
             (('dir1', 'dir1'),
226
              [
227
              ]
228
             ),
229
             (('file1', None),
230
              [
231
              ]
232
             ),
233
            ]
234
        tree.lock_read()
235
        result = list(tree.walkdirs())
236
        tree.unlock()
237
        # check each return value for debugging ease.
238
        for pos, item in enumerate(expected_dirblocks):
239
            self.assertEqual(item, result[pos])
240
        self.assertEqual(len(expected_dirblocks), len(result))