42
42
def make_inventory(self, root_id):
43
43
return self.inventory_class(root_id=root_id)
45
def prepare_inv_with_nested_dirs(self):
46
inv = self.make_inventory('tree-root')
47
for args in [('src', 'directory', 'src-id'),
48
('doc', 'directory', 'doc-id'),
49
('src/hello.c', 'file', 'hello-id'),
50
('src/bye.c', 'file', 'bye-id'),
51
('zz', 'file', 'zz-id'),
52
('src/sub/', 'directory', 'sub-id'),
53
('src/zz.c', 'file', 'zzc-id'),
54
('src/sub/a', 'file', 'a-id'),
55
('Makefile', 'file', 'makefile-id')]:
46
60
class TestInventoryUpdates(TestInventory):
226
240
], sorted([ie.file_id for ie in inv.iter_just_entries()]))
228
242
def test_iter_entries_by_dir(self):
229
inv = self.make_inventory('tree-root')
230
for args in [('src', 'directory', 'src-id'),
231
('doc', 'directory', 'doc-id'),
232
('src/hello.c', 'file', 'hello-id'),
233
('src/bye.c', 'file', 'bye-id'),
234
('zz', 'file', 'zz-id'),
235
('src/sub/', 'directory', 'sub-id'),
236
('src/zz.c', 'file', 'zzc-id'),
237
('src/sub/a', 'file', 'a-id'),
238
('Makefile', 'file', 'makefile-id')]:
243
inv = self. prepare_inv_with_nested_dirs()
240
244
self.assertEqual([
241
245
('', 'tree-root'),
242
246
('Makefile', 'makefile-id'),
300
304
('src/bye.c', 'bye-id'),
301
305
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
302
306
specific_file_ids=('bye-id',), yield_parents=True)])
309
class TestInventoryFiltering(TestInventory):
311
def test_inv_filter_empty(self):
312
inv = self.prepare_inv_with_nested_dirs()
313
new_inv = inv.filter([])
316
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
318
def test_inv_filter_files(self):
319
inv = self.prepare_inv_with_nested_dirs()
320
new_inv = inv.filter(['zz-id', 'hello-id', 'a-id'])
324
('src/hello.c', 'hello-id'),
325
('src/sub', 'sub-id'),
326
('src/sub/a', 'a-id'),
328
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
330
def test_inv_filter_dirs(self):
331
inv = self.prepare_inv_with_nested_dirs()
332
new_inv = inv.filter(['doc-id', 'sub-id'])
337
('src/sub', 'sub-id'),
338
('src/sub/a', 'a-id'),
339
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
341
def test_inv_filter_files_and_dirs(self):
342
inv = self.prepare_inv_with_nested_dirs()
343
new_inv = inv.filter(['makefile-id', 'src-id'])
346
('Makefile', 'makefile-id'),
348
('src/bye.c', 'bye-id'),
349
('src/hello.c', 'hello-id'),
350
('src/sub', 'sub-id'),
351
('src/sub/a', 'a-id'),
352
('src/zz.c', 'zzc-id'),
353
], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])