/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
1852.15.9 by Robert Collins
Add missing test script.
22
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
23
24
# tests to write:
25
# type mismatches - file to link, dir, dir to file, link, link to file, dir
26
27
class TestWalkdirs(TestCaseWithWorkingTree):
28
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
29
    def get_tree_with_unknowns(self):
1852.15.9 by Robert Collins
Add missing test script.
30
        tree = self.make_branch_and_tree('.')
31
        self.build_tree([
32
            'unknown file',
33
            'unknown dir/',
34
            'unknown dir/a file',
35
            ])
36
        u_f_stat = os.lstat('unknown file')
37
        u_d_stat = os.lstat('unknown dir')
38
        u_d_f_stat = os.lstat('unknown dir/a file')
39
        expected_dirblocks = [
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
40
            (('', tree.path2id('')),
1852.15.9 by Robert Collins
Add missing test script.
41
             [
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
42
              ('unknown dir', 'unknown dir', 'directory', u_d_stat, None, None),
43
              ('unknown file', 'unknown file', 'file', u_f_stat, None, None),
44
             ]
45
            ),
46
            (('unknown dir', None),
47
             [('unknown dir/a file', 'a file', 'file', u_d_f_stat, None, None),
48
             ]
49
            ),
50
            ]
51
        return tree, expected_dirblocks
52
    
53
    def test_walkdir_unknowns(self):
54
        """unknown files and directories should be reported by walkdirs."""
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
55
        # test that its iterable by iterating:
1852.15.9 by Robert Collins
Add missing test script.
56
        result = []
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
57
        tree, expected_dirblocks = self.get_tree_with_unknowns()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
58
        tree.lock_read()
1852.15.9 by Robert Collins
Add missing test script.
59
        for dirinfo, dirblock in tree.walkdirs():
60
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
61
        tree.unlock()
1852.15.9 by Robert Collins
Add missing test script.
62
        # check each return value for debugging ease.
63
        for pos, item in enumerate(expected_dirblocks):
64
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
65
        self.assertEqual(len(expected_dirblocks), len(result))
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
66
67
    def test_walkdir_from_unknown_dir(self):
68
        """Doing a walkdir when the requested prefix is unknown but on disk."""
69
        result = []
70
        tree, expected_dirblocks = self.get_tree_with_unknowns()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
71
        tree.lock_read()
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
72
        for dirinfo, dirblock in tree.walkdirs('unknown dir'):
73
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
74
        tree.unlock()
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
75
        # check each return value for debugging ease.
76
        for pos, item in enumerate(expected_dirblocks[1:]):
77
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
78
        self.assertEqual(len(expected_dirblocks) - 1, len(result))
79
80
    def get_tree_with_missings(self):
81
        tree = self.make_branch_and_tree('.')
82
        paths = [
83
            'missing file',
84
            'missing dir/',
85
            'missing dir/a file',
86
            ]
87
        ids = [
88
            'a file',
89
            'a dir',
90
            'a dir-a file',
91
            ]
92
        self.build_tree(paths)
93
        tree.add(paths, ids)
94
        # now make the files be missing
95
        tree.bzrdir.root_transport.delete_tree('missing dir')
96
        tree.bzrdir.root_transport.delete('missing file')
97
        expected_dirblocks = [
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
98
            (('', tree.path2id('')),
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
99
             [
100
              ('missing dir', 'missing dir', 'unknown', None, 'a dir', 'directory'),
101
              ('missing file', 'missing file', 'unknown', None, 'a file', 'file'),
102
             ]
103
            ),
104
            (('missing dir', 'a dir'),
105
             [('missing dir/a file', 'a file', 'unknown', None, 'a dir-a file', 'file'),
106
             ]
107
            ),
108
            ]
109
        return tree, expected_dirblocks
110
    
111
    def test_walkdir_missings(self):
112
        """missing files and directories should be reported by walkdirs."""
113
        # test that its iterable by iterating:
114
        result = []
115
        tree, expected_dirblocks = self.get_tree_with_missings()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
116
        tree.lock_read()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
117
        for dirinfo, dirblock in tree.walkdirs():
118
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
119
        tree.unlock()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
120
        # check each return value for debugging ease.
121
        for pos, item in enumerate(expected_dirblocks):
122
            self.assertEqual(item, result[pos])
123
        self.assertEqual(len(expected_dirblocks), len(result))
124
125
    def test_walkdir_from_missing_dir(self):
126
        """Doing a walkdir when the requested prefix is missing but on disk."""
127
        result = []
128
        tree, expected_dirblocks = self.get_tree_with_missings()
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
129
        tree.lock_read()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
130
        for dirinfo, dirblock in tree.walkdirs('missing dir'):
131
            result.append((dirinfo, list(dirblock)))
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
132
        tree.unlock()
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
133
        # check each return value for debugging ease.
134
        for pos, item in enumerate(expected_dirblocks[1:]):
135
            self.assertEqual(item, result[pos])
136
        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.
137
138
    def test_walkdirs_type_changes(self):
139
        """Walkdir shows the actual kinds on disk and the recorded kinds."""
140
        tree = self.make_branch_and_tree('.')
141
        paths = ['file1', 'file2', 'dir1/', 'dir2/']
142
        ids = ['file1', 'file2', 'dir1', 'dir2']
143
        self.build_tree(paths)
144
        tree.add(paths, ids)
145
        tt = transform.TreeTransform(tree)
146
        root_transaction_id = tt.trans_id_tree_path('')
147
        tt.new_symlink('link1',
148
            root_transaction_id, 'link-target', 'link1')
149
        tt.new_symlink('link2',
150
            root_transaction_id, 'link-target', 'link2')
151
        tt.apply()
152
        tree.bzrdir.root_transport.delete_tree('dir1')
153
        tree.bzrdir.root_transport.delete_tree('dir2')
154
        tree.bzrdir.root_transport.delete('file1')
155
        tree.bzrdir.root_transport.delete('file2')
156
        tree.bzrdir.root_transport.delete('link1')
157
        tree.bzrdir.root_transport.delete('link2')
158
        changed_paths = ['dir1', 'file1/', 'link1', 'link2/']
159
        self.build_tree(changed_paths)
160
        os.symlink('target', 'dir2')
161
        os.symlink('target', 'file2')
162
        dir1_stat = os.lstat('dir1')
163
        dir2_stat = os.lstat('dir2')
164
        file1_stat = os.lstat('file1')
165
        file2_stat = os.lstat('file2')
166
        link1_stat = os.lstat('link1')
167
        link2_stat = os.lstat('link2')
168
        expected_dirblocks = [
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
169
             (('', tree.path2id('')),
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
170
              [('dir1', 'dir1', 'file', dir1_stat, 'dir1', 'directory'),
171
               ('dir2', 'dir2', 'symlink', dir2_stat, 'dir2', 'directory'),
172
               ('file1', 'file1', 'directory', file1_stat, 'file1', 'file'),
173
               ('file2', 'file2', 'symlink', file2_stat, 'file2', 'file'),
174
               ('link1', 'link1', 'file', link1_stat, 'link1', 'symlink'),
175
               ('link2', 'link2', 'directory', link2_stat, 'link2', 'symlink'),
176
              ]
177
             ),
178
             (('dir1', 'dir1'),
179
              [
180
              ]
181
             ),
182
             (('dir2', 'dir2'),
183
              [
184
              ]
185
             ),
186
             (('file1', None),
187
              [
188
              ]
189
             ),
190
             (('link2', None),
191
              [
192
              ]
193
             ),
194
            ]
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
195
        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.
196
        result = list(tree.walkdirs())
2255.2.47 by Robert Collins
Adjust walkdirs tests to talk a lock around walk_dirs.
197
        tree.unlock()
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
198
        # check each return value for debugging ease.
199
        for pos, item in enumerate(expected_dirblocks):
200
            self.assertEqual(item, result[pos])
201
        self.assertEqual(len(expected_dirblocks), len(result))