/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 bzrlib/tests/test_shelf.py

  • Committer: Aaron Bentley
  • Date: 2009-09-29 04:40:55 UTC
  • mfrom: (4717 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4718.
  • Revision ID: aaron@aaronbentley.com-20090929044055-e9jtpmz6eyut711h
Merged bzr.dev into fix_get_mtime.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        tree.add(['foo'], ['foo-id'])
47
47
        tree.commit('foo')
48
48
        tree.rename_one('foo', 'bar')
 
49
        tree.lock_tree_write()
 
50
        self.addCleanup(tree.unlock)
49
51
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
50
52
        self.addCleanup(creator.finalize)
51
53
        self.assertEqual([('rename', 'foo-id', 'foo', 'bar')],
61
63
                         shelf_trans_id))
62
64
 
63
65
    def test_shelve_rename(self):
64
 
        self.thisFailsStrictLockCheck()
65
66
        creator = self.prepare_shelve_rename()
66
67
        creator.shelve_rename('foo-id')
67
68
        self.check_shelve_rename(creator)
68
69
 
69
70
    def test_shelve_change_handles_rename(self):
70
 
        self.thisFailsStrictLockCheck()
71
71
        creator = self.prepare_shelve_rename()
72
72
        creator.shelve_change(('rename', 'foo-id', 'foo', 'bar'))
73
73
        self.check_shelve_rename(creator)
78
78
        tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
79
79
        tree.commit('foo')
80
80
        tree.rename_one('foo/baz', 'bar/baz')
 
81
        tree.lock_tree_write()
 
82
        self.addCleanup(tree.unlock)
81
83
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
82
84
        self.addCleanup(creator.finalize)
83
85
        self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
97
99
        self.assertEqual('foo/baz', tree.id2path('baz-id'))
98
100
 
99
101
    def test_shelve_move(self):
100
 
        self.thisFailsStrictLockCheck()
101
102
        creator, tree = self.prepare_shelve_move()
102
103
        creator.shelve_rename('baz-id')
103
104
        self.check_shelve_move(creator, tree)
104
105
 
105
106
    def test_shelve_change_handles_move(self):
106
 
        self.thisFailsStrictLockCheck()
107
107
        creator, tree = self.prepare_shelve_move()
108
108
        creator.shelve_change(('rename', 'baz-id', 'foo/baz', 'bar/baz'))
109
109
        self.check_shelve_move(creator, tree)
114
114
        self.assertFileEqual(expected_content, shelf_file)
115
115
 
116
116
    def prepare_content_change(self):
117
 
        self.thisFailsStrictLockCheck()
118
117
        tree = self.make_branch_and_tree('.')
119
118
        tree.lock_write()
120
119
        self.addCleanup(tree.unlock)
177
176
            creator.shelf_transform.final_kind(s_bar_trans_id))
178
177
 
179
178
    def test_shelve_creation(self):
180
 
        self.thisFailsStrictLockCheck()
181
179
        creator, tree = self.prepare_shelve_creation()
182
180
        creator.shelve_creation('foo-id')
183
181
        creator.shelve_creation('bar-id')
185
183
        self.check_shelve_creation(creator, tree)
186
184
 
187
185
    def test_shelve_change_handles_creation(self):
188
 
        self.thisFailsStrictLockCheck()
189
186
        creator, tree = self.prepare_shelve_creation()
190
187
        creator.shelve_change(('add file', 'foo-id', 'file', 'foo'))
191
188
        creator.shelve_change(('add file', 'bar-id', 'directory', 'bar'))
218
215
        self.assertEqual(link_target, ptree.get_symlink_target('foo-id'))
219
216
 
220
217
    def test_shelve_symlink_creation(self):
221
 
        self.thisFailsStrictLockCheck()
222
218
        self._test_shelve_symlink_creation('foo', 'bar')
223
219
 
224
220
    def test_shelve_unicode_symlink_creation(self):
225
221
        self.requireFeature(tests.UnicodeFilenameFeature)
226
 
        self.thisFailsStrictLockCheck()
227
222
        self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
228
223
                                           u'b\N{Euro Sign}ar')
229
224
 
230
225
    def test_shelve_change_handles_symlink_creation(self):
231
 
        self.thisFailsStrictLockCheck()
232
226
        self._test_shelve_symlink_creation('foo', 'bar', shelve_change=True)
233
227
 
234
228
    def _test_shelve_symlink_target_change(self, link_name,
262
256
        self.assertEqual(new_target, ptree.get_symlink_target('foo-id'))
263
257
 
264
258
    def test_shelve_symlink_target_change(self):
265
 
        self.thisFailsStrictLockCheck()
266
259
        self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
267
260
 
268
261
    def test_shelve_unicode_symlink_target_change(self):
269
 
        self.thisFailsStrictLockCheck()
270
262
        self.requireFeature(tests.UnicodeFilenameFeature)
271
263
        self._test_shelve_symlink_target_change(
272
264
            u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
273
265
 
274
266
    def test_shelve_change_handles_symlink_target_change(self):
275
 
        self.thisFailsStrictLockCheck()
276
267
        self._test_shelve_symlink_target_change('foo', 'bar', 'baz',
277
268
                                                shelve_change=True)
278
269
 
279
270
    def test_shelve_creation_no_contents(self):
280
 
        self.thisFailsStrictLockCheck()
281
271
        tree = self.make_branch_and_tree('.')
282
272
        tree.lock_write()
283
273
        self.addCleanup(tree.unlock)
322
312
        self.assertFileEqual('baz', 'tree/foo/bar')
323
313
 
324
314
    def test_shelve_deletion(self):
325
 
        self.thisFailsStrictLockCheck()
326
315
        creator, tree = self.prepare_shelve_deletion()
327
316
        creator.shelve_deletion('foo-id')
328
317
        creator.shelve_deletion('bar-id')
330
319
        self.check_shelve_deletion(tree)
331
320
 
332
321
    def test_shelve_change_handles_deletion(self):
333
 
        self.thisFailsStrictLockCheck()
334
322
        creator, tree = self.prepare_shelve_deletion()
335
323
        creator.shelve_change(('delete file', 'foo-id', 'directory', 'foo'))
336
324
        creator.shelve_change(('delete file', 'bar-id', 'file', 'foo/bar'))
338
326
        self.check_shelve_deletion(tree)
339
327
 
340
328
    def test_shelve_delete_contents(self):
341
 
        self.thisFailsStrictLockCheck()
342
329
        tree = self.make_branch_and_tree('tree')
343
330
        self.build_tree(['tree/foo',])
344
331
        tree.add('foo', 'foo-id')
345
332
        tree.commit('Added file and directory')
346
333
        os.unlink('tree/foo')
 
334
        tree.lock_tree_write()
 
335
        self.addCleanup(tree.unlock)
347
336
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
348
337
        self.addCleanup(creator.finalize)
349
338
        self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
359
348
        tree.commit('Added file and directory')
360
349
        os.unlink('tree/foo')
361
350
        os.mkdir('tree/foo')
 
351
        tree.lock_tree_write()
 
352
        self.addCleanup(tree.unlock)
362
353
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
363
354
        self.addCleanup(creator.finalize)
364
355
        self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
372
363
                         creator.shelf_transform._new_contents[s_trans_id])
373
364
 
374
365
    def test_shelve_change_kind(self):
375
 
        self.thisFailsStrictLockCheck()
376
366
        creator = self.prepare_shelve_change_kind()
377
367
        creator.shelve_content_change('foo-id')
378
368
        creator.transform()
379
369
        self.check_shelve_change_kind(creator)
380
370
 
381
371
    def test_shelve_change_handles_change_kind(self):
382
 
        self.thisFailsStrictLockCheck()
383
372
        creator = self.prepare_shelve_change_kind()
384
373
        creator.shelve_change(('change kind', 'foo-id', 'file', 'directory',
385
374
                               'foo'))
387
376
        self.check_shelve_change_kind(creator)
388
377
 
389
378
    def test_shelve_change_unknown_change(self):
390
 
        self.thisFailsStrictLockCheck()
391
379
        tree = self.make_branch_and_tree('tree')
 
380
        tree.lock_tree_write()
 
381
        self.addCleanup(tree.unlock)
392
382
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
393
383
        self.addCleanup(creator.finalize)
394
384
        e = self.assertRaises(ValueError, creator.shelve_change, ('unknown',))
395
385
        self.assertEqual('Unknown change kind: "unknown"', str(e))
396
386
 
397
387
    def test_shelve_unversion(self):
398
 
        self.thisFailsStrictLockCheck()
399
388
        tree = self.make_branch_and_tree('tree')
400
389
        self.build_tree(['tree/foo',])
401
390
        tree.add('foo', 'foo-id')
402
391
        tree.commit('Added file and directory')
403
392
        tree.unversion(['foo-id'])
 
393
        tree.lock_tree_write()
 
394
        self.addCleanup(tree.unlock)
404
395
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
405
396
        self.addCleanup(creator.finalize)
406
397
        self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
410
401
        self.failUnlessExists('tree/foo')
411
402
 
412
403
    def test_shelve_serialization(self):
413
 
        self.thisFailsStrictLockCheck()
414
404
        tree = self.make_branch_and_tree('.')
 
405
        tree.lock_tree_write()
 
406
        self.addCleanup(tree.unlock)
415
407
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
416
408
        self.addCleanup(creator.finalize)
417
409
        shelf_file = open('shelf', 'wb')
423
415
        self.assertFileEqual(EMPTY_SHELF, 'shelf')
424
416
 
425
417
    def test_write_shelf(self):
426
 
        self.thisFailsStrictLockCheck()
427
418
        tree = self.make_branch_and_tree('tree')
428
419
        self.build_tree(['tree/foo'])
429
420
        tree.add('foo', 'foo-id')
 
421
        tree.lock_tree_write()
 
422
        self.addCleanup(tree.unlock)
430
423
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
431
424
        self.addCleanup(creator.finalize)
432
425
        list(creator.iter_shelvable())
450
443
        tt.deserialize(records)
451
444
 
452
445
    def test_shelve_unversioned(self):
453
 
        self.thisFailsStrictLockCheck()
454
446
        tree = self.make_branch_and_tree('tree')
455
 
        self.assertRaises(errors.PathsNotVersionedError,
456
 
                          shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
 
447
        tree.lock_tree_write()
 
448
        try:
 
449
            self.assertRaises(errors.PathsNotVersionedError,
 
450
                              shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
 
451
        finally:
 
452
            tree.unlock()
457
453
        # We should be able to lock/unlock the tree if ShelfCreator cleaned
458
454
        # after itself.
459
455
        wt = workingtree.WorkingTree.open('tree')
461
457
        wt.unlock()
462
458
        # And a second tentative should raise the same error (no
463
459
        # limbo/pending_deletion leftovers).
464
 
        self.assertRaises(errors.PathsNotVersionedError,
465
 
                          shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
 
460
        tree.lock_tree_write()
 
461
        try:
 
462
            self.assertRaises(errors.PathsNotVersionedError,
 
463
                              shelf.ShelfCreator, tree, tree.basis_tree(), ['foo'])
 
464
        finally:
 
465
            tree.unlock()
 
466
 
 
467
    def test_shelve_skips_added_root(self):
 
468
        """Skip adds of the root when iterating through shelvable changes."""
 
469
        tree = self.make_branch_and_tree('tree')
 
470
        tree.lock_tree_write()
 
471
        self.addCleanup(tree.unlock)
 
472
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
 
473
        self.addCleanup(creator.finalize)
 
474
        self.assertEqual([], list(creator.iter_shelvable()))
 
475
 
 
476
    def test_shelve_skips_added_root(self):
 
477
        """Skip adds of the root when iterating through shelvable changes."""
 
478
        tree = self.make_branch_and_tree('tree')
 
479
        tree.lock_tree_write()
 
480
        self.addCleanup(tree.unlock)
 
481
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
 
482
        self.addCleanup(creator.finalize)
 
483
        self.assertEqual([], list(creator.iter_shelvable()))
466
484
 
467
485
 
468
486
class TestUnshelver(tests.TestCaseWithTransport):
469
487
 
470
488
    def test_make_merger(self):
471
 
        self.thisFailsStrictLockCheck()
472
489
        tree = self.make_branch_and_tree('tree')
473
490
        tree.commit('first commit')
474
491
        self.build_tree_contents([('tree/foo', 'bar')])
486
503
            shelf_file.seek(0)
487
504
            unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
488
505
            unshelver.make_merger().do_merge()
 
506
            self.addCleanup(unshelver.finalize)
489
507
            self.assertFileEqual('bar', 'tree/foo')
490
508
        finally:
491
509
            shelf_file.close()
492
510
 
493
511
    def test_unshelve_changed(self):
494
 
        self.thisFailsStrictLockCheck()
495
512
        tree = self.make_branch_and_tree('tree')
496
513
        tree.lock_write()
497
514
        self.addCleanup(tree.unlock)
510
527
        self.build_tree_contents([('tree/foo', 'z\na\nb\nc\n')])
511
528
        shelf_file.seek(0)
512
529
        unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
 
530
        self.addCleanup(unshelver.finalize)
513
531
        unshelver.make_merger().do_merge()
514
532
        self.assertFileEqual('z\na\nb\nd\n', 'tree/foo')
515
533
 
516
534
    def test_unshelve_deleted(self):
517
 
        self.thisFailsStrictLockCheck()
518
535
        tree = self.make_branch_and_tree('tree')
519
536
        tree.lock_write()
520
537
        self.addCleanup(tree.unlock)
539
556
        self.assertFileEqual('baz', 'tree/foo/bar')
540
557
        shelf_file.seek(0)
541
558
        unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
 
559
        self.addCleanup(unshelver.finalize)
542
560
        unshelver.make_merger().do_merge()
543
561
        self.assertFalse('foo-id' in tree)
544
562
        self.assertFalse('bar-id' in tree)
545
563
 
546
564
    def test_unshelve_base(self):
547
 
        self.thisFailsStrictLockCheck()
548
565
        tree = self.make_branch_and_tree('tree')
549
566
        tree.lock_write()
550
567
        self.addCleanup(tree.unlock)
565
582
        self.assertEqual('rev1', unshelver.base_tree.get_revision_id())
566
583
 
567
584
    def test_unshelve_serialization(self):
568
 
        self.thisFailsStrictLockCheck()
569
585
        tree = self.make_branch_and_tree('.')
570
586
        self.build_tree_contents([('shelf', EMPTY_SHELF)])
571
587
        shelf_file = open('shelf', 'rb')
572
588
        self.addCleanup(shelf_file.close)
573
589
        unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
 
590
        unshelver.finalize()
574
591
 
575
592
    def test_corrupt_shelf(self):
576
 
        self.thisFailsStrictLockCheck()
577
593
        tree = self.make_branch_and_tree('.')
578
594
        self.build_tree_contents([('shelf', EMPTY_SHELF.replace('metadata',
579
595
                                                                'foo'))])
686
702
        shelf_id = shelf_manager.shelve_changes(creator)
687
703
        self.failIfExists('tree/foo')
688
704
        unshelver = shelf_manager.get_unshelver(shelf_id)
 
705
        self.addCleanup(unshelver.finalize)
689
706
        unshelver.make_merger().do_merge()
690
707
        self.assertFileEqual('bar', 'tree/foo')
691
708
 
692
709
    def test_get_metadata(self):
693
710
        tree = self.make_branch_and_tree('.')
 
711
        tree.lock_tree_write()
 
712
        self.addCleanup(tree.unlock)
694
713
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
 
714
        self.addCleanup(creator.finalize)
695
715
        shelf_manager = tree.get_shelf_manager()
696
716
        shelf_id = shelf_manager.shelve_changes(creator, 'foo')
697
717
        metadata = shelf_manager.get_metadata(shelf_id)