/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_inventory/basics.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 19:18:40 UTC
  • mto: This revision was merged to the branch mainline in revision 6928.
  • Revision ID: jelmer@jelmer.uk-20180218191840-2wezg20u9ffbfmed
Fix more bees, use with rather than try/finally for some files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
 
165
165
        # Test all entries
166
166
        self.assertEqual([
167
 
            ('', 'tree-root'),
168
 
            ('Makefile', 'makefile-id'),
169
 
            ('doc', 'doc-id'),
170
 
            ('src', 'src-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'),
176
 
            ('zz', 'zz-id'),
 
167
            ('', b'tree-root'),
 
168
            ('Makefile', b'makefile-id'),
 
169
            ('doc', b'doc-id'),
 
170
            ('src', b'src-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'),
 
176
            ('zz', b'zz-id'),
177
177
            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
178
178
 
179
179
        # Test a subdirectory
180
180
        self.assertEqual([
181
 
            ('bye.c', 'bye-id'),
182
 
            ('hello.c', 'hello-id'),
183
 
            ('sub', 'sub-id'),
184
 
            ('sub/a', 'a-id'),
185
 
            ('zz.c', 'zzc-id'),
 
181
            ('bye.c', b'bye-id'),
 
182
            ('hello.c', b'hello-id'),
 
183
            ('sub', b'sub-id'),
 
184
            ('sub/a', b'a-id'),
 
185
            ('zz.c', b'zzc-id'),
186
186
            ], [(path, ie.file_id) for path, ie in inv.iter_entries(
187
 
            from_dir='src-id')])
 
187
            from_dir=b'src-id')])
188
188
 
189
189
        # Test not recursing at the root level
190
190
        self.assertEqual([
191
 
            ('', 'tree-root'),
192
 
            ('Makefile', 'makefile-id'),
193
 
            ('doc', 'doc-id'),
194
 
            ('src', 'src-id'),
195
 
            ('zz', 'zz-id'),
 
191
            ('', b'tree-root'),
 
192
            ('Makefile', b'makefile-id'),
 
193
            ('doc', b'doc-id'),
 
194
            ('src', b'src-id'),
 
195
            ('zz', b'zz-id'),
196
196
            ], [(path, ie.file_id) for path, ie in inv.iter_entries(
197
197
            recursive=False)])
198
198
 
199
199
        # Test not recursing at a subdirectory level
200
200
        self.assertEqual([
201
 
            ('bye.c', 'bye-id'),
202
 
            ('hello.c', 'hello-id'),
203
 
            ('sub', 'sub-id'),
204
 
            ('zz.c', 'zzc-id'),
 
201
            ('bye.c', b'bye-id'),
 
202
            ('hello.c', b'hello-id'),
 
203
            ('sub', b'sub-id'),
 
204
            ('zz.c', b'zzc-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)])
207
207
 
208
208
    def test_iter_just_entries(self):
209
209
        inv = self.prepare_inv_with_nested_dirs()
210
210
        self.assertEqual([
211
 
            'a-id',
212
 
            'bye-id',
213
 
            'doc-id',
214
 
            'hello-id',
215
 
            'makefile-id',
216
 
            'src-id',
217
 
            'sub-id',
218
 
            'tree-root',
219
 
            'zz-id',
220
 
            'zzc-id',
 
211
            b'a-id',
 
212
            b'bye-id',
 
213
            b'doc-id',
 
214
            b'hello-id',
 
215
            b'makefile-id',
 
216
            b'src-id',
 
217
            b'sub-id',
 
218
            b'tree-root',
 
219
            b'zz-id',
 
220
            b'zzc-id',
221
221
            ], sorted([ie.file_id for ie in inv.iter_just_entries()]))
222
222
 
223
223
    def test_iter_entries_by_dir(self):
224
224
        inv = self. prepare_inv_with_nested_dirs()
225
225
        self.assertEqual([
226
 
            ('', 'tree-root'),
227
 
            ('Makefile', 'makefile-id'),
228
 
            ('doc', 'doc-id'),
229
 
            ('src', 'src-id'),
230
 
            ('zz', 'zz-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'),
 
226
            ('', b'tree-root'),
 
227
            ('Makefile', b'makefile-id'),
 
228
            ('doc', b'doc-id'),
 
229
            ('src', b'src-id'),
 
230
            ('zz', b'zz-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([
238
 
            ('', 'tree-root'),
239
 
            ('Makefile', 'makefile-id'),
240
 
            ('doc', 'doc-id'),
241
 
            ('src', 'src-id'),
242
 
            ('zz', 'zz-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',
251
 
                'sub-id'))])
252
 
 
253
 
        self.assertEqual([
254
 
            ('Makefile', 'makefile-id'),
255
 
            ('doc', 'doc-id'),
256
 
            ('zz', 'zz-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'))])
264
 
 
265
 
        self.assertEqual([
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'))])
270
 
 
271
 
        self.assertEqual([
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'))])
276
 
 
277
 
        self.assertEqual([
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',))])
281
 
 
282
 
        self.assertEqual([
283
 
            ('', 'tree-root'),
284
 
            ('src', 'src-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)])
 
238
            ('', b'tree-root'),
 
239
            ('Makefile', b'makefile-id'),
 
240
            ('doc', b'doc-id'),
 
241
            ('src', b'src-id'),
 
242
            ('zz', b'zz-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',
 
251
                b'sub-id'))])
 
252
 
 
253
        self.assertEqual([
 
254
            ('Makefile', b'makefile-id'),
 
255
            ('doc', b'doc-id'),
 
256
            ('zz', b'zz-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'))])
 
264
 
 
265
        self.assertEqual([
 
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'))])
 
270
 
 
271
        self.assertEqual([
 
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'))])
 
276
 
 
277
        self.assertEqual([
 
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',))])
 
281
 
 
282
        self.assertEqual([
 
283
            ('', b'tree-root'),
 
284
            ('src', b'src-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)])
288
288
 
289
289
 
290
290
class TestInventoryFiltering(TestInventory):
293
293
        inv = self.prepare_inv_with_nested_dirs()
294
294
        new_inv = inv.filter([])
295
295
        self.assertEqual([
296
 
            ('', 'tree-root'),
 
296
            ('', b'tree-root'),
297
297
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
298
298
    
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([
303
 
            ('', 'tree-root'),
304
 
            ('src', 'src-id'),
305
 
            ('src/hello.c', 'hello-id'),
306
 
            ('src/sub', 'sub-id'),
307
 
            ('src/sub/a', 'a-id'),
308
 
            ('zz', 'zz-id'),
 
303
            ('', b'tree-root'),
 
304
            ('src', b'src-id'),
 
305
            ('src/hello.c', b'hello-id'),
 
306
            ('src/sub', b'sub-id'),
 
307
            ('src/sub/a', b'a-id'),
 
308
            ('zz', b'zz-id'),
309
309
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
310
310
    
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([
315
 
            ('', 'tree-root'),
316
 
            ('doc', 'doc-id'),
317
 
            ('src', 'src-id'),
318
 
            ('src/sub', 'sub-id'),
319
 
            ('src/sub/a', 'a-id'),
 
315
            ('', b'tree-root'),
 
316
            ('doc', b'doc-id'),
 
317
            ('src', b'src-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()])
321
321
 
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([
326
 
            ('', 'tree-root'),
327
 
            ('Makefile', 'makefile-id'),
328
 
            ('src', 'src-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'),
 
326
            ('', b'tree-root'),
 
327
            ('Makefile', b'makefile-id'),
 
328
            ('src', b'src-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()])
335
335
 
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([
340
 
            ('', 'tree-root'),
 
340
            ('', b'tree-root'),
341
341
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])