~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

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
191
191
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
192
192
        self.assertEqual('foo-id',
193
193
                         creator.shelf_transform.final_file_id(s_trans_id))
194
 
        self.assertPathDoesNotExist('foo')
195
 
        self.assertPathDoesNotExist('bar')
 
194
        self.failIfExists('foo')
 
195
        self.failIfExists('bar')
196
196
        self.assertShelvedFileEqual('a\n', creator, 'foo-id')
197
197
        s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
198
198
        self.assertEqual('directory',
231
231
            creator.shelve_creation('foo-id')
232
232
        creator.transform()
233
233
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
234
 
        self.assertPathDoesNotExist(link_name)
 
234
        self.failIfExists(link_name)
235
235
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
236
236
        self.assertEqual(link_target, osutils.readlink(limbo_name))
237
237
        ptree = creator.shelf_transform.get_preview_tree()
310
310
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
311
311
        self.assertEqual('foo-id',
312
312
                         creator.shelf_transform.final_file_id(s_trans_id))
313
 
        self.assertPathDoesNotExist('foo')
 
313
        self.failIfExists('foo')
314
314
 
315
315
    def prepare_shelve_deletion(self):
316
316
        tree = self.make_branch_and_tree('tree')
330
330
        return creator, tree
331
331
 
332
332
    def check_shelve_deletion(self, tree):
333
 
        self.assertTrue(tree.has_id('foo-id'))
334
 
        self.assertTrue(tree.has_id('bar-id'))
 
333
        self.assertTrue('foo-id' in tree)
 
334
        self.assertTrue('bar-id' in tree)
335
335
        self.assertFileEqual('baz', 'tree/foo/bar')
336
336
 
337
337
    def test_shelve_deletion(self):
362
362
                         sorted(list(creator.iter_shelvable())))
363
363
        creator.shelve_deletion('foo-id')
364
364
        creator.transform()
365
 
        self.assertPathExists('tree/foo')
 
365
        self.failUnlessExists('tree/foo')
366
366
 
367
367
    def prepare_shelve_change_kind(self):
368
368
        tree = self.make_branch_and_tree('tree')
421
421
                         sorted(list(creator.iter_shelvable())))
422
422
        creator.shelve_deletion('foo-id')
423
423
        creator.transform()
424
 
        self.assertPathExists('tree/foo')
 
424
        self.failUnlessExists('tree/foo')
425
425
 
426
426
    def test_shelve_serialization(self):
427
427
        tree = self.make_branch_and_tree('.')
568
568
        list(creator.iter_shelvable())
569
569
        creator.shelve_deletion('foo-id')
570
570
        creator.shelve_deletion('bar-id')
571
 
        with open('shelf', 'w+b') as shelf_file:
572
 
            creator.write_shelf(shelf_file)
573
 
            creator.transform()
574
 
            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()
575
576
        # validate the test setup
576
 
        self.assertTrue(tree.has_id('foo-id'))
577
 
        self.assertTrue(tree.has_id('bar-id'))
 
577
        self.assertTrue('foo-id' in tree)
 
578
        self.assertTrue('bar-id' in tree)
578
579
        self.assertFileEqual('baz', 'tree/foo/bar')
579
 
        with open('shelf', 'r+b') as shelf_file:
580
 
            unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
581
 
            self.addCleanup(unshelver.finalize)
582
 
            unshelver.make_merger().do_merge()
583
 
        self.assertFalse(tree.has_id('foo-id'))
584
 
        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)
585
586
 
586
587
    def test_unshelve_base(self):
587
588
        tree = self.make_branch_and_tree('tree')
622
623
                              shelf_file)
623
624
        self.assertEqual('Shelf corrupt.', str(e))
624
625
 
625
 
    def test_unshelve_subdir_in_now_removed_dir(self):
626
 
        tree = self.make_branch_and_tree('.')
627
 
        self.addCleanup(tree.lock_write().unlock)
628
 
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
629
 
        tree.add(['dir'], ['dir-id'])
630
 
        tree.commit('versioned dir')
631
 
        tree.add(['dir/subdir', 'dir/subdir/foo'], ['subdir-id', 'foo-id'])
632
 
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
633
 
        self.addCleanup(creator.finalize)
634
 
        for change in creator.iter_shelvable():
635
 
            creator.shelve_change(change)
636
 
        shelf_manager = tree.get_shelf_manager()
637
 
        shelf_id = shelf_manager.shelve_changes(creator)
638
 
        self.assertPathDoesNotExist('dir/subdir')
639
 
        tree.remove(['dir'])
640
 
        unshelver = shelf_manager.get_unshelver(shelf_id)
641
 
        self.addCleanup(unshelver.finalize)
642
 
        unshelver.make_merger().do_merge()
643
 
        self.assertPathExists('dir/subdir/foo')
644
 
        self.assertEqual('dir-id', tree.path2id('dir'))
645
 
        self.assertEqual('subdir-id', tree.path2id('dir/subdir'))
646
 
        self.assertEqual('foo-id', tree.path2id('dir/subdir/foo'))
647
 
 
648
626
 
649
627
class TestShelfManager(tests.TestCaseWithTransport):
650
628
 
745
723
        creator.shelve_creation('foo-id')
746
724
        shelf_manager = tree.get_shelf_manager()
747
725
        shelf_id = shelf_manager.shelve_changes(creator)
748
 
        self.assertPathDoesNotExist('tree/foo')
 
726
        self.failIfExists('tree/foo')
749
727
        unshelver = shelf_manager.get_unshelver(shelf_id)
750
728
        self.addCleanup(unshelver.finalize)
751
729
        unshelver.make_merger().do_merge()