/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 breezy/tests/per_workingtree/test_walkdirs.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# tests to write:
26
26
# type mismatches - file to link, dir, dir to file, link, link to file, dir
27
27
 
 
28
 
28
29
class DirBlock:
29
30
    """Object representation of the tuples returned by dirstate."""
30
31
 
34
35
        self.abspath = tree.abspath(file_path)
35
36
        self.relpath = tree.relpath(file_path)
36
37
        if file_name is None:
37
 
           file_name = os.path.split(file_path)[-1]
38
 
           if len(file_name) == 0:
39
 
               file_name = os.path.split(file_path)[-2]
 
38
            file_name = os.path.split(file_path)[-1]
 
39
            if len(file_name) == 0:
 
40
                file_name = os.path.split(file_path)[-2]
40
41
        self.file_name = file_name
41
42
        self.id = id
42
43
        self.inventory_kind = inventory_kind
44
45
        self.disk_kind = disk_kind
45
46
 
46
47
    def as_tuple(self):
47
 
         return (self.relpath, self.file_name, self.disk_kind,
48
 
                 self.stat, self.id, self.inventory_kind)
 
48
        return (self.relpath, self.file_name, self.disk_kind,
 
49
                self.stat, self.id, self.inventory_kind)
49
50
 
50
51
    def as_dir_tuple(self):
51
 
         return (self.relpath, self.id)
 
52
        return (self.relpath, self.id)
52
53
 
53
54
    def __str__(self):
54
55
        return """
60
61
inventory_kind = %r
61
62
stat           = %r
62
63
disk_kind      = %r""" % (self.file_path, self.abspath, self.relpath,
63
 
        self.file_name, self.id, self.inventory_kind, self.stat,
64
 
        self.disk_kind)
 
64
                          self.file_name, self.id, self.inventory_kind, self.stat,
 
65
                          self.disk_kind)
65
66
 
66
67
 
67
68
class TestWalkdirs(TestCaseWithWorkingTree):
68
69
 
69
 
    added='added'
70
 
    missing='missing'
71
 
    unknown='unknown'
 
70
    added = 'added'
 
71
    missing = 'missing'
 
72
    unknown = 'unknown'
72
73
 
73
74
    def get_tree(self, file_status, prefix=None):
74
75
        tree = self.make_branch_and_tree('.')
113
114
             ([dirblocks[3].as_tuple()]
114
115
                 if (tree.has_versioned_directories() or file_status == self.unknown) else []) +
115
116
             [dirblocks[0].as_tuple()]
116
 
            ),
 
117
             ),
117
118
            (dirblocks[1].as_dir_tuple(),
118
119
             [dirblocks[2].as_tuple()]
119
 
            ),
 
120
             ),
120
121
            ]
121
122
        if (tree.has_versioned_directories() or
122
 
            file_status != self.missing):
 
123
                file_status != self.missing):
123
124
            expected_dirblocks.append(
124
125
                (dirblocks[3].as_dir_tuple(),
125
126
                 []
126
 
                ))
 
127
                 ))
127
128
        if prefix:
128
129
            expected_dirblocks = [e for e in expected_dirblocks
129
 
                if len(e) > 0 and len(e[0]) > 0 and e[0][0] == prefix]
 
130
                                  if len(e) > 0 and len(e[0]) > 0 and e[0][0] == prefix]
130
131
        return tree, expected_dirblocks
131
132
 
132
133
    def _test_walkdir(self, file_status, prefix=""):
179
180
        tt = transform.TreeTransform(tree)
180
181
        root_transaction_id = tt.trans_id_tree_path('')
181
182
        tt.new_symlink('link1',
182
 
            root_transaction_id, 'link-target', b'link1')
 
183
                       root_transaction_id, 'link-target', b'link1')
183
184
        tt.new_symlink('link2',
184
 
            root_transaction_id, 'link-target', b'link2')
 
185
                       root_transaction_id, 'link-target', b'link2')
185
186
        tt.apply()
186
187
        tree.controldir.root_transport.delete_tree('dir1')
187
188
        tree.controldir.root_transport.delete_tree('dir2')
200
201
        link1_stat = os.lstat('link1')
201
202
        link2_stat = os.lstat('link2')
202
203
        expected_dirblocks = [
203
 
             (('', tree.path2id('')),
204
 
              [('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'),
205
 
                  'directory' if tree.has_versioned_directories() else None),
206
 
               ('dir2', 'dir2', 'symlink', dir2_stat, tree.path2id('dir2'),
207
 
                   'directory' if tree.has_versioned_directories() else None),
208
 
               ('file1', 'file1', 'directory', file1_stat, tree.path2id('file1'), 'file'),
209
 
               ('file2', 'file2', 'symlink', file2_stat, tree.path2id('file2'), 'file'),
210
 
               ('link1', 'link1', 'file', link1_stat, tree.path2id('link1'), 'symlink'),
211
 
               ('link2', 'link2', 'directory', link2_stat, tree.path2id('link2'), 'symlink'),
 
204
            (('', tree.path2id('')),
 
205
             [('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'),
 
206
               'directory' if tree.has_versioned_directories() else None),
 
207
              ('dir2', 'dir2', 'symlink', dir2_stat, tree.path2id('dir2'),
 
208
               'directory' if tree.has_versioned_directories() else None),
 
209
              ('file1', 'file1', 'directory', file1_stat,
 
210
               tree.path2id('file1'), 'file'),
 
211
              ('file2', 'file2', 'symlink', file2_stat,
 
212
               tree.path2id('file2'), 'file'),
 
213
              ('link1', 'link1', 'file', link1_stat,
 
214
               tree.path2id('link1'), 'symlink'),
 
215
              ('link2', 'link2', 'directory', link2_stat,
 
216
               tree.path2id('link2'), 'symlink'),
212
217
              ]
213
218
             )]
214
219
        if tree.has_versioned_directories():
215
220
            expected_dirblocks.extend([
216
 
             (('dir1', tree.path2id('dir1')),
217
 
              [
218
 
              ]
219
 
             ),
220
 
             (('dir2', tree.path2id('dir2')),
221
 
              [
222
 
              ]
223
 
             )])
 
221
                (('dir1', tree.path2id('dir1')),
 
222
                 [
 
223
                    ]
 
224
                 ),
 
225
                (('dir2', tree.path2id('dir2')),
 
226
                    [
 
227
                    ]
 
228
                 )])
224
229
        expected_dirblocks.extend([
225
 
             (('file1', None),
226
 
              [
227
 
              ]
 
230
            (('file1', None),
 
231
             [
 
232
                ]
228
233
             ),
229
 
             (('link2', None),
230
 
              [
231
 
              ]
 
234
            (('link2', None),
 
235
             [
 
236
                ]
232
237
             ),
233
238
            ])
234
239
        with tree.lock_read():
253
258
        file1_stat = os.lstat('file1')
254
259
        if tree.has_versioned_directories():
255
260
            expected_dirblocks = [
256
 
                 (('', tree.path2id('')),
257
 
                  [('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'), 'directory'),
258
 
                   ('file1', 'file1', 'directory', file1_stat, tree.path2id('file1'), 'file'),
259
 
                  ]
260
 
                 ),
261
 
                 (('dir1', tree.path2id('dir1')),
262
 
                  [
263
 
                  ]
264
 
                 ),
265
 
                 (('file1', None),
266
 
                  [
267
 
                  ]
 
261
                (('', tree.path2id('')),
 
262
                 [('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'), 'directory'),
 
263
                  ('file1', 'file1', 'directory', file1_stat,
 
264
                   tree.path2id('file1'), 'file'),
 
265
                  ]
 
266
                 ),
 
267
                (('dir1', tree.path2id('dir1')),
 
268
                 [
 
269
                    ]
 
270
                 ),
 
271
                (('file1', None),
 
272
                 [
 
273
                    ]
268
274
                 ),
269
275
                ]
270
276
        else:
271
277
            expected_dirblocks = [
272
 
                 (('', tree.path2id('')),
273
 
                  [('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'), None),
274
 
                   ('file1', 'file1', 'directory', file1_stat, tree.path2id('file1'), 'file'),
 
278
                (('', tree.path2id('')),
 
279
                 [('dir1', 'dir1', 'file', dir1_stat, tree.path2id('dir1'), None),
 
280
                  ('file1', 'file1', 'directory', file1_stat,
 
281
                   tree.path2id('file1'), 'file'),
275
282
                  ]
276
283
                 ),
277
 
                 (('file1', None),
278
 
                  [
279
 
                  ]
 
284
                (('file1', None),
 
285
                 [
 
286
                    ]
280
287
                 ),
281
288
                ]
282
289
        with tree.lock_read():