~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: 2010-12-02 14:58:47 UTC
  • mfrom: (5554.1.3 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101202145847-fw822sd3nyhvrwmi
(vila) Merge 2.2 into trunk including fix for bug #583667 and bug
        #681885 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
25
25
    transform,
26
26
    workingtree,
27
27
    )
28
 
from bzrlib.tests import (
29
 
    features,
30
 
    )
31
28
 
32
29
 
33
30
EMPTY_SHELF = ("Bazaar pack format 1 (introduced in 0.18)\n"
194
191
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
195
192
        self.assertEqual('foo-id',
196
193
                         creator.shelf_transform.final_file_id(s_trans_id))
197
 
        self.assertPathDoesNotExist('foo')
198
 
        self.assertPathDoesNotExist('bar')
 
194
        self.failIfExists('foo')
 
195
        self.failIfExists('bar')
199
196
        self.assertShelvedFileEqual('a\n', creator, 'foo-id')
200
197
        s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
201
198
        self.assertEqual('directory',
217
214
 
218
215
    def _test_shelve_symlink_creation(self, link_name, link_target,
219
216
                                      shelve_change=False):
220
 
        self.requireFeature(features.SymlinkFeature)
 
217
        self.requireFeature(tests.SymlinkFeature)
221
218
        tree = self.make_branch_and_tree('.')
222
219
        tree.lock_write()
223
220
        self.addCleanup(tree.unlock)
234
231
            creator.shelve_creation('foo-id')
235
232
        creator.transform()
236
233
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
237
 
        self.assertPathDoesNotExist(link_name)
 
234
        self.failIfExists(link_name)
238
235
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
239
236
        self.assertEqual(link_target, osutils.readlink(limbo_name))
240
237
        ptree = creator.shelf_transform.get_preview_tree()
244
241
        self._test_shelve_symlink_creation('foo', 'bar')
245
242
 
246
243
    def test_shelve_unicode_symlink_creation(self):
247
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
244
        self.requireFeature(tests.UnicodeFilenameFeature)
248
245
        self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
249
246
                                           u'b\N{Euro Sign}ar')
250
247
 
254
251
    def _test_shelve_symlink_target_change(self, link_name,
255
252
                                           old_target, new_target,
256
253
                                           shelve_change=False):
257
 
        self.requireFeature(features.SymlinkFeature)
 
254
        self.requireFeature(tests.SymlinkFeature)
258
255
        tree = self.make_branch_and_tree('.')
259
256
        tree.lock_write()
260
257
        self.addCleanup(tree.unlock)
285
282
        self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
286
283
 
287
284
    def test_shelve_unicode_symlink_target_change(self):
288
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
285
        self.requireFeature(tests.UnicodeFilenameFeature)
289
286
        self._test_shelve_symlink_target_change(
290
287
            u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
291
288
 
313
310
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
314
311
        self.assertEqual('foo-id',
315
312
                         creator.shelf_transform.final_file_id(s_trans_id))
316
 
        self.assertPathDoesNotExist('foo')
 
313
        self.failIfExists('foo')
317
314
 
318
315
    def prepare_shelve_deletion(self):
319
316
        tree = self.make_branch_and_tree('tree')
333
330
        return creator, tree
334
331
 
335
332
    def check_shelve_deletion(self, tree):
336
 
        self.assertTrue(tree.has_id('foo-id'))
337
 
        self.assertTrue(tree.has_id('bar-id'))
 
333
        self.assertTrue('foo-id' in tree)
 
334
        self.assertTrue('bar-id' in tree)
338
335
        self.assertFileEqual('baz', 'tree/foo/bar')
339
336
 
340
337
    def test_shelve_deletion(self):
365
362
                         sorted(list(creator.iter_shelvable())))
366
363
        creator.shelve_deletion('foo-id')
367
364
        creator.transform()
368
 
        self.assertPathExists('tree/foo')
 
365
        self.failUnlessExists('tree/foo')
369
366
 
370
367
    def prepare_shelve_change_kind(self):
371
368
        tree = self.make_branch_and_tree('tree')
424
421
                         sorted(list(creator.iter_shelvable())))
425
422
        creator.shelve_deletion('foo-id')
426
423
        creator.transform()
427
 
        self.assertPathExists('tree/foo')
 
424
        self.failUnlessExists('tree/foo')
428
425
 
429
426
    def test_shelve_serialization(self):
430
427
        tree = self.make_branch_and_tree('.')
571
568
        list(creator.iter_shelvable())
572
569
        creator.shelve_deletion('foo-id')
573
570
        creator.shelve_deletion('bar-id')
574
 
        with open('shelf', 'w+b') as shelf_file:
575
 
            creator.write_shelf(shelf_file)
576
 
            creator.transform()
577
 
            creator.finalize()
 
571
        shelf_file = open('shelf', 'w+b')
 
572
        self.addCleanup(shelf_file.close)
 
573
        creator.write_shelf(shelf_file)
 
574
        creator.transform()
 
575
        creator.finalize()
578
576
        # validate the test setup
579
 
        self.assertTrue(tree.has_id('foo-id'))
580
 
        self.assertTrue(tree.has_id('bar-id'))
 
577
        self.assertTrue('foo-id' in tree)
 
578
        self.assertTrue('bar-id' in tree)
581
579
        self.assertFileEqual('baz', 'tree/foo/bar')
582
 
        with open('shelf', 'r+b') as shelf_file:
583
 
            unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
584
 
            self.addCleanup(unshelver.finalize)
585
 
            unshelver.make_merger().do_merge()
586
 
        self.assertFalse(tree.has_id('foo-id'))
587
 
        self.assertFalse(tree.has_id('bar-id'))
 
580
        shelf_file.seek(0)
 
581
        unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
 
582
        self.addCleanup(unshelver.finalize)
 
583
        unshelver.make_merger().do_merge()
 
584
        self.assertFalse('foo-id' in tree)
 
585
        self.assertFalse('bar-id' in tree)
588
586
 
589
587
    def test_unshelve_base(self):
590
588
        tree = self.make_branch_and_tree('tree')
625
623
                              shelf_file)
626
624
        self.assertEqual('Shelf corrupt.', str(e))
627
625
 
628
 
    def test_unshelve_subdir_in_now_removed_dir(self):
629
 
        tree = self.make_branch_and_tree('.')
630
 
        self.addCleanup(tree.lock_write().unlock)
631
 
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
632
 
        tree.add(['dir'], ['dir-id'])
633
 
        tree.commit('versioned dir')
634
 
        tree.add(['dir/subdir', 'dir/subdir/foo'], ['subdir-id', 'foo-id'])
635
 
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
636
 
        self.addCleanup(creator.finalize)
637
 
        for change in creator.iter_shelvable():
638
 
            creator.shelve_change(change)
639
 
        shelf_manager = tree.get_shelf_manager()
640
 
        shelf_id = shelf_manager.shelve_changes(creator)
641
 
        self.assertPathDoesNotExist('dir/subdir')
642
 
        tree.remove(['dir'])
643
 
        unshelver = shelf_manager.get_unshelver(shelf_id)
644
 
        self.addCleanup(unshelver.finalize)
645
 
        unshelver.make_merger().do_merge()
646
 
        self.assertPathExists('dir/subdir/foo')
647
 
        self.assertEqual('dir-id', tree.path2id('dir'))
648
 
        self.assertEqual('subdir-id', tree.path2id('dir/subdir'))
649
 
        self.assertEqual('foo-id', tree.path2id('dir/subdir/foo'))
650
 
 
651
626
 
652
627
class TestShelfManager(tests.TestCaseWithTransport):
653
628
 
748
723
        creator.shelve_creation('foo-id')
749
724
        shelf_manager = tree.get_shelf_manager()
750
725
        shelf_id = shelf_manager.shelve_changes(creator)
751
 
        self.assertPathDoesNotExist('tree/foo')
 
726
        self.failIfExists('tree/foo')
752
727
        unshelver = shelf_manager.get_unshelver(shelf_id)
753
728
        self.addCleanup(unshelver.finalize)
754
729
        unshelver.make_merger().do_merge()