165
165
# Test all entries
166
166
self.assertEqual([
168
('Makefile', 'makefile-id'),
171
('src/bye.c', 'bye-id'),
172
('src/hello.c', 'hello-id'),
173
('src/sub', 'sub-id'),
174
('src/sub/a', 'a-id'),
175
('src/zz.c', 'zzc-id'),
168
('Makefile', b'makefile-id'),
171
('src/bye.c', b'bye-id'),
172
('src/hello.c', b'hello-id'),
173
('src/sub', b'sub-id'),
174
('src/sub/a', b'a-id'),
175
('src/zz.c', b'zzc-id'),
177
177
], [(path, ie.file_id) for path, ie in inv.iter_entries()])
179
179
# Test a subdirectory
180
180
self.assertEqual([
182
('hello.c', 'hello-id'),
181
('bye.c', b'bye-id'),
182
('hello.c', b'hello-id'),
186
186
], [(path, ie.file_id) for path, ie in inv.iter_entries(
187
from_dir=b'src-id')])
189
189
# Test not recursing at the root level
190
190
self.assertEqual([
192
('Makefile', 'makefile-id'),
192
('Makefile', b'makefile-id'),
196
196
], [(path, ie.file_id) for path, ie in inv.iter_entries(
197
197
recursive=False)])
199
199
# Test not recursing at a subdirectory level
200
200
self.assertEqual([
202
('hello.c', 'hello-id'),
201
('bye.c', b'bye-id'),
202
('hello.c', b'hello-id'),
205
205
], [(path, ie.file_id) for path, ie in inv.iter_entries(
206
from_dir='src-id', recursive=False)])
206
from_dir=b'src-id', recursive=False)])
208
208
def test_iter_just_entries(self):
209
209
inv = self.prepare_inv_with_nested_dirs()
210
210
self.assertEqual([
221
221
], sorted([ie.file_id for ie in inv.iter_just_entries()]))
223
223
def test_iter_entries_by_dir(self):
224
224
inv = self. prepare_inv_with_nested_dirs()
225
225
self.assertEqual([
227
('Makefile', 'makefile-id'),
231
('src/bye.c', 'bye-id'),
232
('src/hello.c', 'hello-id'),
233
('src/sub', 'sub-id'),
234
('src/zz.c', 'zzc-id'),
235
('src/sub/a', 'a-id'),
227
('Makefile', b'makefile-id'),
231
('src/bye.c', b'bye-id'),
232
('src/hello.c', b'hello-id'),
233
('src/sub', b'sub-id'),
234
('src/zz.c', b'zzc-id'),
235
('src/sub/a', b'a-id'),
236
236
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
237
237
self.assertEqual([
239
('Makefile', 'makefile-id'),
243
('src/bye.c', 'bye-id'),
244
('src/hello.c', 'hello-id'),
245
('src/sub', 'sub-id'),
246
('src/zz.c', 'zzc-id'),
247
('src/sub/a', 'a-id'),
248
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
249
specific_file_ids=('a-id', 'zzc-id', 'doc-id', 'tree-root',
250
'hello-id', 'bye-id', 'zz-id', 'src-id', 'makefile-id',
254
('Makefile', 'makefile-id'),
257
('src/bye.c', 'bye-id'),
258
('src/hello.c', 'hello-id'),
259
('src/zz.c', 'zzc-id'),
260
('src/sub/a', 'a-id'),
261
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
262
specific_file_ids=('a-id', 'zzc-id', 'doc-id',
263
'hello-id', 'bye-id', 'zz-id', 'makefile-id'))])
266
('Makefile', 'makefile-id'),
267
('src/bye.c', 'bye-id'),
268
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
269
specific_file_ids=('bye-id', 'makefile-id'))])
272
('Makefile', 'makefile-id'),
273
('src/bye.c', 'bye-id'),
274
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
275
specific_file_ids=('bye-id', 'makefile-id'))])
278
('src/bye.c', 'bye-id'),
279
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
280
specific_file_ids=('bye-id',))])
285
('src/bye.c', 'bye-id'),
286
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
287
specific_file_ids=('bye-id',), yield_parents=True)])
239
('Makefile', b'makefile-id'),
243
('src/bye.c', b'bye-id'),
244
('src/hello.c', b'hello-id'),
245
('src/sub', b'sub-id'),
246
('src/zz.c', b'zzc-id'),
247
('src/sub/a', b'a-id'),
248
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
249
specific_file_ids=(b'a-id', b'zzc-id', b'doc-id', b'tree-root',
250
b'hello-id', b'bye-id', b'zz-id', b'src-id', b'makefile-id',
254
('Makefile', b'makefile-id'),
257
('src/bye.c', b'bye-id'),
258
('src/hello.c', b'hello-id'),
259
('src/zz.c', b'zzc-id'),
260
('src/sub/a', b'a-id'),
261
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
262
specific_file_ids=(b'a-id', b'zzc-id', b'doc-id',
263
b'hello-id', b'bye-id', b'zz-id', b'makefile-id'))])
266
('Makefile', b'makefile-id'),
267
('src/bye.c', b'bye-id'),
268
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
269
specific_file_ids=(b'bye-id', b'makefile-id'))])
272
('Makefile', b'makefile-id'),
273
('src/bye.c', b'bye-id'),
274
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
275
specific_file_ids=(b'bye-id', b'makefile-id'))])
278
('src/bye.c', b'bye-id'),
279
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
280
specific_file_ids=(b'bye-id',))])
285
('src/bye.c', b'bye-id'),
286
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
287
specific_file_ids=(b'bye-id',), yield_parents=True)])
290
290
class TestInventoryFiltering(TestInventory):
293
293
inv = self.prepare_inv_with_nested_dirs()
294
294
new_inv = inv.filter([])
295
295
self.assertEqual([
297
297
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
299
299
def test_inv_filter_files(self):
300
300
inv = self.prepare_inv_with_nested_dirs()
301
new_inv = inv.filter(['zz-id', 'hello-id', 'a-id'])
301
new_inv = inv.filter([b'zz-id', b'hello-id', b'a-id'])
302
302
self.assertEqual([
305
('src/hello.c', 'hello-id'),
306
('src/sub', 'sub-id'),
307
('src/sub/a', 'a-id'),
305
('src/hello.c', b'hello-id'),
306
('src/sub', b'sub-id'),
307
('src/sub/a', b'a-id'),
309
309
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
311
311
def test_inv_filter_dirs(self):
312
312
inv = self.prepare_inv_with_nested_dirs()
313
new_inv = inv.filter(['doc-id', 'sub-id'])
313
new_inv = inv.filter([b'doc-id', b'sub-id'])
314
314
self.assertEqual([
318
('src/sub', 'sub-id'),
319
('src/sub/a', 'a-id'),
318
('src/sub', b'sub-id'),
319
('src/sub/a', b'a-id'),
320
320
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
322
322
def test_inv_filter_files_and_dirs(self):
323
323
inv = self.prepare_inv_with_nested_dirs()
324
new_inv = inv.filter(['makefile-id', 'src-id'])
324
new_inv = inv.filter([b'makefile-id', b'src-id'])
325
325
self.assertEqual([
327
('Makefile', 'makefile-id'),
329
('src/bye.c', 'bye-id'),
330
('src/hello.c', 'hello-id'),
331
('src/sub', 'sub-id'),
332
('src/sub/a', 'a-id'),
333
('src/zz.c', 'zzc-id'),
327
('Makefile', b'makefile-id'),
329
('src/bye.c', b'bye-id'),
330
('src/hello.c', b'hello-id'),
331
('src/sub', b'sub-id'),
332
('src/sub/a', b'a-id'),
333
('src/zz.c', b'zzc-id'),
334
334
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
336
336
def test_inv_filter_entry_not_present(self):
337
337
inv = self.prepare_inv_with_nested_dirs()
338
new_inv = inv.filter(['not-present-id'])
338
new_inv = inv.filter([b'not-present-id'])
339
339
self.assertEqual([
341
341
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])