~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-05 07:22:59 UTC
  • mfrom: (4933 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4936.
  • Revision ID: john@arbash-meinel.com-20100105072259-77xsv5gcpl7nt7ku
Bring in the latest bzr.dev to resolve the criss-cross problem

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008 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
18
18
from cStringIO import StringIO
19
19
import os
20
20
import sys
21
 
from textwrap import dedent
22
21
 
23
22
from bzrlib import (
24
23
    errors,
27
26
    tests,
28
27
)
29
28
from bzrlib.tests import script
30
 
from bzrlib.tests import (
31
 
    features,
32
 
    )
33
29
 
34
30
 
35
31
class ExpectShelver(shelf_ui.Shelver):
66
62
LINES_AY = 'a\nb\nc\nd\ne\nf\ng\nh\ni\ny\n'
67
63
 
68
64
 
69
 
class ShelfTestCase(tests.TestCaseWithTransport):
 
65
class TestShelver(tests.TestCaseWithTransport):
70
66
 
71
67
    def create_shelvable_tree(self):
72
68
        tree = self.make_branch_and_tree('tree')
76
72
        self.build_tree_contents([('tree/foo', LINES_ZY)])
77
73
        return tree
78
74
 
79
 
 
80
 
class TestShelver(ShelfTestCase):
81
 
 
82
75
    def test_unexpected_prompt_failure(self):
83
76
        tree = self.create_shelvable_tree()
84
77
        tree.lock_tree_write()
196
189
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
197
190
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
198
191
        shelver.run()
199
 
        self.assertPathDoesNotExist('tree/foo')
 
192
        self.failIfExists('tree/foo')
200
193
 
201
194
    def test_shelve_kind_change(self):
202
195
        tree = self.create_shelvable_tree()
211
204
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
212
205
 
213
206
    def test_shelve_modify_target(self):
214
 
        self.requireFeature(features.SymlinkFeature)
 
207
        self.requireFeature(tests.SymlinkFeature)
215
208
        tree = self.create_shelvable_tree()
216
209
        os.symlink('bar', 'tree/baz')
217
210
        tree.add('baz', 'baz-id')
305
298
        finally:
306
299
            tree.unlock()
307
300
 
308
 
    def test_shelve_old_root_preserved(self):
 
301
    def test_shelve_old_root_deleted(self):
309
302
        tree1 = self.make_branch_and_tree('tree1')
310
303
        tree1.commit('add root')
311
 
        tree1_root_id = tree1.get_root_id()
312
304
        tree2 = self.make_branch_and_tree('tree2')
313
305
        rev2 = tree2.commit('add root')
314
 
        self.assertNotEquals(tree1_root_id, tree2.get_root_id())
315
306
        tree1.merge_from_branch(tree2.branch,
316
307
                                from_revision=revision.NULL_REVISION)
317
 
        tree1.commit('merging in tree2')
318
 
        self.assertEquals(tree1_root_id, tree1.get_root_id())
 
308
        tree1.commit('Replaced root entry')
319
309
        # This is essentially assertNotRaises(InconsistentDelta)
320
 
        # With testtools 0.9.9, it can be rewritten as:
321
 
        # with ExpectedException(AssertionError,
322
 
        #                        'InconsistentDelta not raised'):
323
 
        #     with ExpectedException(errors.InconsistentDelta, ''):
324
 
        #         self.shelve_all(tree1, rev2)
325
 
        e = self.assertRaises(AssertionError, self.assertRaises,
326
 
                              errors.InconsistentDelta, self.shelve_all, tree1,
327
 
                              rev2)
328
 
        self.assertContainsRe('InconsistentDelta not raised', str(e))
 
310
        self.expectFailure('Cannot shelve replacing a root entry',
 
311
                           self.assertRaises, AssertionError,
 
312
                           self.assertRaises, errors.InconsistentDelta,
 
313
                           self.shelve_all, tree1, rev2)
329
314
 
330
315
    def test_shelve_split(self):
331
316
        outer_tree = self.make_branch_and_tree('outer')
341
326
                           outer_tree, rev2)
342
327
 
343
328
 
344
 
class TestApplyReporter(ShelfTestCase):
 
329
class TestApplyReporter(TestShelver):
345
330
 
346
331
    def test_shelve_not_diff(self):
347
332
        tree = self.create_shelvable_tree()
436
421
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
437
422
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
438
423
        shelver.run()
439
 
        self.assertPathDoesNotExist('tree/foo')
 
424
        self.failIfExists('tree/foo')
440
425
 
441
426
    def test_shelve_kind_change(self):
442
427
        tree = self.create_shelvable_tree()
451
436
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
452
437
 
453
438
    def test_shelve_modify_target(self):
454
 
        self.requireFeature(features.SymlinkFeature)
 
439
        self.requireFeature(tests.SymlinkFeature)
455
440
        tree = self.create_shelvable_tree()
456
441
        os.symlink('bar', 'tree/baz')
457
442
        tree.add('baz', 'baz-id')
519
504
        self.assertFileEqual(LINES_AJ, 'tree/foo')
520
505
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
521
506
 
522
 
    def test_unshelve_args_preview(self):
523
 
        tree = self.create_tree_with_shelf()
524
 
        write_diff_to = StringIO()
525
 
        unshelver = shelf_ui.Unshelver.from_args(
526
 
            directory='tree', action='preview', write_diff_to=write_diff_to)
527
 
        try:
528
 
            unshelver.run()
529
 
        finally:
530
 
            unshelver.tree.unlock()
531
 
        # The changes were not unshelved.
532
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
533
 
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
534
 
 
535
 
        # But the diff was written to write_diff_to.
536
 
        diff = write_diff_to.getvalue()
537
 
        expected = dedent("""\
538
 
            @@ -1,4 +1,4 @@
539
 
            -a
540
 
            +z
541
 
             b
542
 
             c
543
 
             d
544
 
            @@ -7,4 +7,4 @@
545
 
             g
546
 
             h
547
 
             i
548
 
            -j
549
 
            +y
550
 
 
551
 
            """)
552
 
        self.assertEqualDiff(expected, diff[-len(expected):])
553
 
 
554
507
    def test_unshelve_args_delete_only(self):
555
508
        tree = self.make_branch_and_tree('tree')
556
509
        manager = tree.get_shelf_manager()