~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf.py

  • Committer: Andrew Starr-Bochicchio
  • Date: 2015-07-31 01:04:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6606.
  • Revision ID: a.starr.b@gmail.com-20150731010441-3domwjjtnjijxlr2
Use hexlify() from binascii directly as paramiko removed hexify().

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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
    )
28
31
 
29
32
 
30
33
EMPTY_SHELF = ("Bazaar pack format 1 (introduced in 0.18)\n"
191
194
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
192
195
        self.assertEqual('foo-id',
193
196
                         creator.shelf_transform.final_file_id(s_trans_id))
194
 
        self.failIfExists('foo')
195
 
        self.failIfExists('bar')
 
197
        self.assertPathDoesNotExist('foo')
 
198
        self.assertPathDoesNotExist('bar')
196
199
        self.assertShelvedFileEqual('a\n', creator, 'foo-id')
197
200
        s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
198
201
        self.assertEqual('directory',
214
217
 
215
218
    def _test_shelve_symlink_creation(self, link_name, link_target,
216
219
                                      shelve_change=False):
217
 
        self.requireFeature(tests.SymlinkFeature)
 
220
        self.requireFeature(features.SymlinkFeature)
218
221
        tree = self.make_branch_and_tree('.')
219
222
        tree.lock_write()
220
223
        self.addCleanup(tree.unlock)
231
234
            creator.shelve_creation('foo-id')
232
235
        creator.transform()
233
236
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
234
 
        self.failIfExists(link_name)
 
237
        self.assertPathDoesNotExist(link_name)
235
238
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
236
239
        self.assertEqual(link_target, osutils.readlink(limbo_name))
237
240
        ptree = creator.shelf_transform.get_preview_tree()
241
244
        self._test_shelve_symlink_creation('foo', 'bar')
242
245
 
243
246
    def test_shelve_unicode_symlink_creation(self):
244
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
247
        self.requireFeature(features.UnicodeFilenameFeature)
245
248
        self._test_shelve_symlink_creation(u'fo\N{Euro Sign}o',
246
249
                                           u'b\N{Euro Sign}ar')
247
250
 
251
254
    def _test_shelve_symlink_target_change(self, link_name,
252
255
                                           old_target, new_target,
253
256
                                           shelve_change=False):
254
 
        self.requireFeature(tests.SymlinkFeature)
 
257
        self.requireFeature(features.SymlinkFeature)
255
258
        tree = self.make_branch_and_tree('.')
256
259
        tree.lock_write()
257
260
        self.addCleanup(tree.unlock)
282
285
        self._test_shelve_symlink_target_change('foo', 'bar', 'baz')
283
286
 
284
287
    def test_shelve_unicode_symlink_target_change(self):
285
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
288
        self.requireFeature(features.UnicodeFilenameFeature)
286
289
        self._test_shelve_symlink_target_change(
287
290
            u'fo\N{Euro Sign}o', u'b\N{Euro Sign}ar', u'b\N{Euro Sign}az')
288
291
 
310
313
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
311
314
        self.assertEqual('foo-id',
312
315
                         creator.shelf_transform.final_file_id(s_trans_id))
313
 
        self.failIfExists('foo')
 
316
        self.assertPathDoesNotExist('foo')
314
317
 
315
318
    def prepare_shelve_deletion(self):
316
319
        tree = self.make_branch_and_tree('tree')
330
333
        return creator, tree
331
334
 
332
335
    def check_shelve_deletion(self, tree):
333
 
        self.assertTrue('foo-id' in tree)
334
 
        self.assertTrue('bar-id' in tree)
 
336
        self.assertTrue(tree.has_id('foo-id'))
 
337
        self.assertTrue(tree.has_id('bar-id'))
335
338
        self.assertFileEqual('baz', 'tree/foo/bar')
336
339
 
337
340
    def test_shelve_deletion(self):
362
365
                         sorted(list(creator.iter_shelvable())))
363
366
        creator.shelve_deletion('foo-id')
364
367
        creator.transform()
365
 
        self.failUnlessExists('tree/foo')
 
368
        self.assertPathExists('tree/foo')
366
369
 
367
370
    def prepare_shelve_change_kind(self):
368
371
        tree = self.make_branch_and_tree('tree')
421
424
                         sorted(list(creator.iter_shelvable())))
422
425
        creator.shelve_deletion('foo-id')
423
426
        creator.transform()
424
 
        self.failUnlessExists('tree/foo')
 
427
        self.assertPathExists('tree/foo')
425
428
 
426
429
    def test_shelve_serialization(self):
427
430
        tree = self.make_branch_and_tree('.')
568
571
        list(creator.iter_shelvable())
569
572
        creator.shelve_deletion('foo-id')
570
573
        creator.shelve_deletion('bar-id')
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()
 
574
        with open('shelf', 'w+b') as shelf_file:
 
575
            creator.write_shelf(shelf_file)
 
576
            creator.transform()
 
577
            creator.finalize()
576
578
        # validate the test setup
577
 
        self.assertTrue('foo-id' in tree)
578
 
        self.assertTrue('bar-id' in tree)
 
579
        self.assertTrue(tree.has_id('foo-id'))
 
580
        self.assertTrue(tree.has_id('bar-id'))
579
581
        self.assertFileEqual('baz', 'tree/foo/bar')
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)
 
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'))
586
588
 
587
589
    def test_unshelve_base(self):
588
590
        tree = self.make_branch_and_tree('tree')
623
625
                              shelf_file)
624
626
        self.assertEqual('Shelf corrupt.', str(e))
625
627
 
 
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
 
626
651
 
627
652
class TestShelfManager(tests.TestCaseWithTransport):
628
653
 
723
748
        creator.shelve_creation('foo-id')
724
749
        shelf_manager = tree.get_shelf_manager()
725
750
        shelf_id = shelf_manager.shelve_changes(creator)
726
 
        self.failIfExists('tree/foo')
 
751
        self.assertPathDoesNotExist('tree/foo')
727
752
        unshelver = shelf_manager.get_unshelver(shelf_id)
728
753
        self.addCleanup(unshelver.finalize)
729
754
        unshelver.make_merger().do_merge()