~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-25 23:37:34 UTC
  • mfrom: (4648.1.2 shelve-locks)
  • Revision ID: pqm@pqm.ubuntu.com-20090825233734-ozgeetbq9aagneer
Fix shelve on windows. (Robert Collins, #305006)

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
466
 
467
467
    def test_shelve_skips_added_root(self):
468
468
        """Skip adds of the root when iterating through shelvable changes."""
469
469
        tree = self.make_branch_and_tree('tree')
 
470
        tree.lock_tree_write()
 
471
        self.addCleanup(tree.unlock)
470
472
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
471
473
        self.addCleanup(creator.finalize)
472
474
        self.assertEqual([], list(creator.iter_shelvable()))
475
477
class TestUnshelver(tests.TestCaseWithTransport):
476
478
 
477
479
    def test_make_merger(self):
478
 
        self.thisFailsStrictLockCheck()
479
480
        tree = self.make_branch_and_tree('tree')
480
481
        tree.commit('first commit')
481
482
        self.build_tree_contents([('tree/foo', 'bar')])
498
499
            shelf_file.close()
499
500
 
500
501
    def test_unshelve_changed(self):
501
 
        self.thisFailsStrictLockCheck()
502
502
        tree = self.make_branch_and_tree('tree')
503
503
        tree.lock_write()
504
504
        self.addCleanup(tree.unlock)
521
521
        self.assertFileEqual('z\na\nb\nd\n', 'tree/foo')
522
522
 
523
523
    def test_unshelve_deleted(self):
524
 
        self.thisFailsStrictLockCheck()
525
524
        tree = self.make_branch_and_tree('tree')
526
525
        tree.lock_write()
527
526
        self.addCleanup(tree.unlock)
551
550
        self.assertFalse('bar-id' in tree)
552
551
 
553
552
    def test_unshelve_base(self):
554
 
        self.thisFailsStrictLockCheck()
555
553
        tree = self.make_branch_and_tree('tree')
556
554
        tree.lock_write()
557
555
        self.addCleanup(tree.unlock)
572
570
        self.assertEqual('rev1', unshelver.base_tree.get_revision_id())
573
571
 
574
572
    def test_unshelve_serialization(self):
575
 
        self.thisFailsStrictLockCheck()
576
573
        tree = self.make_branch_and_tree('.')
577
574
        self.build_tree_contents([('shelf', EMPTY_SHELF)])
578
575
        shelf_file = open('shelf', 'rb')
579
576
        self.addCleanup(shelf_file.close)
580
577
        unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
 
578
        unshelver.finalize()
581
579
 
582
580
    def test_corrupt_shelf(self):
583
 
        self.thisFailsStrictLockCheck()
584
581
        tree = self.make_branch_and_tree('.')
585
582
        self.build_tree_contents([('shelf', EMPTY_SHELF.replace('metadata',
586
583
                                                                'foo'))])
698
695
 
699
696
    def test_get_metadata(self):
700
697
        tree = self.make_branch_and_tree('.')
 
698
        tree.lock_tree_write()
 
699
        self.addCleanup(tree.unlock)
701
700
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
 
701
        self.addCleanup(creator.finalize)
702
702
        shelf_manager = tree.get_shelf_manager()
703
703
        shelf_id = shelf_manager.shelve_changes(creator, 'foo')
704
704
        metadata = shelf_manager.get_metadata(shelf_id)