/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 = [
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
40
            (('', tree.inventory.root.file_id),
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()
1852.15.9 by Robert Collins
Add missing test script.
58
        for dirinfo, dirblock in tree.walkdirs():
59
            result.append((dirinfo, list(dirblock)))
60
        # check each return value for debugging ease.
61
        for pos, item in enumerate(expected_dirblocks):
62
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
63
        self.assertEqual(len(expected_dirblocks), len(result))
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
64
65
    def test_walkdir_from_unknown_dir(self):
66
        """Doing a walkdir when the requested prefix is unknown but on disk."""
67
        result = []
68
        tree, expected_dirblocks = self.get_tree_with_unknowns()
69
        for dirinfo, dirblock in tree.walkdirs('unknown dir'):
70
            result.append((dirinfo, list(dirblock)))
71
        # check each return value for debugging ease.
72
        for pos, item in enumerate(expected_dirblocks[1:]):
73
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
74
        self.assertEqual(len(expected_dirblocks) - 1, len(result))
75
76
    def get_tree_with_missings(self):
77
        tree = self.make_branch_and_tree('.')
78
        paths = [
79
            'missing file',
80
            'missing dir/',
81
            'missing dir/a file',
82
            ]
83
        ids = [
84
            'a file',
85
            'a dir',
86
            'a dir-a file',
87
            ]
88
        self.build_tree(paths)
89
        tree.add(paths, ids)
90
        # now make the files be missing
91
        tree.bzrdir.root_transport.delete_tree('missing dir')
92
        tree.bzrdir.root_transport.delete('missing file')
93
        expected_dirblocks = [
94
            (('', tree.inventory.root.file_id),
95
             [
96
              ('missing dir', 'missing dir', 'unknown', None, 'a dir', 'directory'),
97
              ('missing file', 'missing file', 'unknown', None, 'a file', 'file'),
98
             ]
99
            ),
100
            (('missing dir', 'a dir'),
101
             [('missing dir/a file', 'a file', 'unknown', None, 'a dir-a file', 'file'),
102
             ]
103
            ),
104
            ]
105
        return tree, expected_dirblocks
106
    
107
    def test_walkdir_missings(self):
108
        """missing files and directories should be reported by walkdirs."""
109
        # test that its iterable by iterating:
110
        result = []
111
        tree, expected_dirblocks = self.get_tree_with_missings()
112
        for dirinfo, dirblock in tree.walkdirs():
113
            result.append((dirinfo, list(dirblock)))
114
        # check each return value for debugging ease.
115
        for pos, item in enumerate(expected_dirblocks):
116
            self.assertEqual(item, result[pos])
117
        self.assertEqual(len(expected_dirblocks), len(result))
118
119
    def test_walkdir_from_missing_dir(self):
120
        """Doing a walkdir when the requested prefix is missing but on disk."""
121
        result = []
122
        tree, expected_dirblocks = self.get_tree_with_missings()
123
        for dirinfo, dirblock in tree.walkdirs('missing dir'):
124
            result.append((dirinfo, list(dirblock)))
125
        # check each return value for debugging ease.
126
        for pos, item in enumerate(expected_dirblocks[1:]):
127
            self.assertEqual(item, result[pos])
128
        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.
129
130
    def test_walkdirs_type_changes(self):
131
        """Walkdir shows the actual kinds on disk and the recorded kinds."""
132
        tree = self.make_branch_and_tree('.')
133
        paths = ['file1', 'file2', 'dir1/', 'dir2/']
134
        ids = ['file1', 'file2', 'dir1', 'dir2']
135
        self.build_tree(paths)
136
        tree.add(paths, ids)
137
        tt = transform.TreeTransform(tree)
138
        root_transaction_id = tt.trans_id_tree_path('')
139
        tt.new_symlink('link1',
140
            root_transaction_id, 'link-target', 'link1')
141
        tt.new_symlink('link2',
142
            root_transaction_id, 'link-target', 'link2')
143
        tt.apply()
144
        tree.bzrdir.root_transport.delete_tree('dir1')
145
        tree.bzrdir.root_transport.delete_tree('dir2')
146
        tree.bzrdir.root_transport.delete('file1')
147
        tree.bzrdir.root_transport.delete('file2')
148
        tree.bzrdir.root_transport.delete('link1')
149
        tree.bzrdir.root_transport.delete('link2')
150
        changed_paths = ['dir1', 'file1/', 'link1', 'link2/']
151
        self.build_tree(changed_paths)
152
        os.symlink('target', 'dir2')
153
        os.symlink('target', 'file2')
154
        dir1_stat = os.lstat('dir1')
155
        dir2_stat = os.lstat('dir2')
156
        file1_stat = os.lstat('file1')
157
        file2_stat = os.lstat('file2')
158
        link1_stat = os.lstat('link1')
159
        link2_stat = os.lstat('link2')
160
        expected_dirblocks = [
161
             (('', tree.inventory.root.file_id),
162
              [('dir1', 'dir1', 'file', dir1_stat, 'dir1', 'directory'),
163
               ('dir2', 'dir2', 'symlink', dir2_stat, 'dir2', 'directory'),
164
               ('file1', 'file1', 'directory', file1_stat, 'file1', 'file'),
165
               ('file2', 'file2', 'symlink', file2_stat, 'file2', 'file'),
166
               ('link1', 'link1', 'file', link1_stat, 'link1', 'symlink'),
167
               ('link2', 'link2', 'directory', link2_stat, 'link2', 'symlink'),
168
              ]
169
             ),
170
             (('dir1', 'dir1'),
171
              [
172
              ]
173
             ),
174
             (('dir2', 'dir2'),
175
              [
176
              ]
177
             ),
178
             (('file1', None),
179
              [
180
              ]
181
             ),
182
             (('link2', None),
183
              [
184
              ]
185
             ),
186
            ]
187
        result = list(tree.walkdirs())
188
        # check each return value for debugging ease.
189
        for pos, item in enumerate(expected_dirblocks):
190
            self.assertEqual(item, result[pos])
191
        self.assertEqual(len(expected_dirblocks), len(result))