~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 08:02:52 UTC
  • mto: This revision was merged to the branch mainline in revision 4573.
  • Revision ID: andrew.bennetts@canonical.com-20090727080252-1r4s9oqwlkzgywx7
Fix trivial bug in _vfs_set_tags_bytes.

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
 
from bzrlib import (
24
 
    errors,
25
 
    shelf_ui,
26
 
    revision,
27
 
    tests,
28
 
)
29
 
from bzrlib.tests import script
30
 
from bzrlib.tests import (
31
 
    features,
32
 
    )
 
22
from bzrlib import errors, shelf_ui, tests
33
23
 
34
24
 
35
25
class ExpectShelver(shelf_ui.Shelver):
66
56
LINES_AY = 'a\nb\nc\nd\ne\nf\ng\nh\ni\ny\n'
67
57
 
68
58
 
69
 
class ShelfTestCase(tests.TestCaseWithTransport):
 
59
class TestShelver(tests.TestCaseWithTransport):
70
60
 
71
61
    def create_shelvable_tree(self):
72
62
        tree = self.make_branch_and_tree('tree')
76
66
        self.build_tree_contents([('tree/foo', LINES_ZY)])
77
67
        return tree
78
68
 
79
 
 
80
 
class TestShelver(ShelfTestCase):
81
 
 
82
69
    def test_unexpected_prompt_failure(self):
83
70
        tree = self.create_shelvable_tree()
84
 
        tree.lock_tree_write()
85
 
        self.addCleanup(tree.unlock)
86
71
        shelver = ExpectShelver(tree, tree.basis_tree())
87
 
        self.addCleanup(shelver.finalize)
88
72
        e = self.assertRaises(AssertionError, shelver.run)
89
73
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
90
74
 
91
75
    def test_wrong_prompt_failure(self):
92
76
        tree = self.create_shelvable_tree()
93
 
        tree.lock_tree_write()
94
 
        self.addCleanup(tree.unlock)
95
77
        shelver = ExpectShelver(tree, tree.basis_tree())
96
 
        self.addCleanup(shelver.finalize)
97
78
        shelver.expect('foo', 'y')
98
79
        e = self.assertRaises(AssertionError, shelver.run)
99
80
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
100
81
 
101
82
    def test_shelve_not_diff(self):
102
83
        tree = self.create_shelvable_tree()
103
 
        tree.lock_tree_write()
104
 
        self.addCleanup(tree.unlock)
105
84
        shelver = ExpectShelver(tree, tree.basis_tree())
106
 
        self.addCleanup(shelver.finalize)
107
85
        shelver.expect('Shelve? [yNfq?]', 'n')
108
86
        shelver.expect('Shelve? [yNfq?]', 'n')
109
87
        # No final shelving prompt because no changes were selected
112
90
 
113
91
    def test_shelve_diff_no(self):
114
92
        tree = self.create_shelvable_tree()
115
 
        tree.lock_tree_write()
116
 
        self.addCleanup(tree.unlock)
117
93
        shelver = ExpectShelver(tree, tree.basis_tree())
118
 
        self.addCleanup(shelver.finalize)
119
94
        shelver.expect('Shelve? [yNfq?]', 'y')
120
95
        shelver.expect('Shelve? [yNfq?]', 'y')
121
96
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n')
124
99
 
125
100
    def test_shelve_diff(self):
126
101
        tree = self.create_shelvable_tree()
127
 
        tree.lock_tree_write()
128
 
        self.addCleanup(tree.unlock)
129
102
        shelver = ExpectShelver(tree, tree.basis_tree())
130
 
        self.addCleanup(shelver.finalize)
131
103
        shelver.expect('Shelve? [yNfq?]', 'y')
132
104
        shelver.expect('Shelve? [yNfq?]', 'y')
133
105
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
136
108
 
137
109
    def test_shelve_one_diff(self):
138
110
        tree = self.create_shelvable_tree()
139
 
        tree.lock_tree_write()
140
 
        self.addCleanup(tree.unlock)
141
111
        shelver = ExpectShelver(tree, tree.basis_tree())
142
 
        self.addCleanup(shelver.finalize)
143
112
        shelver.expect('Shelve? [yNfq?]', 'y')
144
113
        shelver.expect('Shelve? [yNfq?]', 'n')
145
114
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
149
118
    def test_shelve_binary_change(self):
150
119
        tree = self.create_shelvable_tree()
151
120
        self.build_tree_contents([('tree/foo', '\x00')])
152
 
        tree.lock_tree_write()
153
 
        self.addCleanup(tree.unlock)
154
121
        shelver = ExpectShelver(tree, tree.basis_tree())
155
 
        self.addCleanup(shelver.finalize)
156
122
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
157
123
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
158
124
        shelver.run()
161
127
    def test_shelve_rename(self):
162
128
        tree = self.create_shelvable_tree()
163
129
        tree.rename_one('foo', 'bar')
164
 
        tree.lock_tree_write()
165
 
        self.addCleanup(tree.unlock)
166
130
        shelver = ExpectShelver(tree, tree.basis_tree())
167
 
        self.addCleanup(shelver.finalize)
168
131
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
169
132
        shelver.expect('Shelve? [yNfq?]', 'y')
170
133
        shelver.expect('Shelve? [yNfq?]', 'y')
175
138
    def test_shelve_deletion(self):
176
139
        tree = self.create_shelvable_tree()
177
140
        os.unlink('tree/foo')
178
 
        tree.lock_tree_write()
179
 
        self.addCleanup(tree.unlock)
180
141
        shelver = ExpectShelver(tree, tree.basis_tree())
181
 
        self.addCleanup(shelver.finalize)
182
142
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
183
143
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
184
144
        shelver.run()
189
149
        tree.commit('add tree root')
190
150
        self.build_tree(['tree/foo'])
191
151
        tree.add('foo')
192
 
        tree.lock_tree_write()
193
 
        self.addCleanup(tree.unlock)
194
152
        shelver = ExpectShelver(tree, tree.basis_tree())
195
 
        self.addCleanup(shelver.finalize)
196
153
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
197
154
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
198
155
        shelver.run()
199
 
        self.assertPathDoesNotExist('tree/foo')
 
156
        self.failIfExists('tree/foo')
200
157
 
201
158
    def test_shelve_kind_change(self):
202
159
        tree = self.create_shelvable_tree()
203
160
        os.unlink('tree/foo')
204
161
        os.mkdir('tree/foo')
205
 
        tree.lock_tree_write()
206
 
        self.addCleanup(tree.unlock)
207
162
        shelver = ExpectShelver(tree, tree.basis_tree())
208
 
        self.addCleanup(shelver.finalize)
209
163
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
210
164
                       'y')
211
165
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
212
166
 
213
167
    def test_shelve_modify_target(self):
214
 
        self.requireFeature(features.SymlinkFeature)
 
168
        self.requireFeature(tests.SymlinkFeature)
215
169
        tree = self.create_shelvable_tree()
216
170
        os.symlink('bar', 'tree/baz')
217
171
        tree.add('baz', 'baz-id')
218
172
        tree.commit("Add symlink")
219
173
        os.unlink('tree/baz')
220
174
        os.symlink('vax', 'tree/baz')
221
 
        tree.lock_tree_write()
222
 
        self.addCleanup(tree.unlock)
223
175
        shelver = ExpectShelver(tree, tree.basis_tree())
224
 
        self.addCleanup(shelver.finalize)
225
176
        shelver.expect('Shelve changing target of "baz" from "bar" to '
226
177
                '"vax"? [yNfq?]', 'y')
227
178
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
230
181
 
231
182
    def test_shelve_finish(self):
232
183
        tree = self.create_shelvable_tree()
233
 
        tree.lock_tree_write()
234
 
        self.addCleanup(tree.unlock)
235
184
        shelver = ExpectShelver(tree, tree.basis_tree())
236
 
        self.addCleanup(shelver.finalize)
237
185
        shelver.expect('Shelve? [yNfq?]', 'f')
238
186
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
239
187
        shelver.run()
241
189
 
242
190
    def test_shelve_quit(self):
243
191
        tree = self.create_shelvable_tree()
244
 
        tree.lock_tree_write()
245
 
        self.addCleanup(tree.unlock)
246
192
        shelver = ExpectShelver(tree, tree.basis_tree())
247
 
        self.addCleanup(shelver.finalize)
248
193
        shelver.expect('Shelve? [yNfq?]', 'q')
249
194
        self.assertRaises(errors.UserAbort, shelver.run)
250
195
        self.assertFileEqual(LINES_ZY, 'tree/foo')
251
196
 
252
197
    def test_shelve_all(self):
253
198
        tree = self.create_shelvable_tree()
254
 
        shelver = ExpectShelver.from_args(sys.stdout, all=True,
255
 
            directory='tree')
256
 
        try:
257
 
            shelver.run()
258
 
        finally:
259
 
            shelver.finalize()
 
199
        ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
260
200
        self.assertFileEqual(LINES_AJ, 'tree/foo')
261
201
 
262
202
    def test_shelve_filename(self):
263
203
        tree = self.create_shelvable_tree()
264
204
        self.build_tree(['tree/bar'])
265
205
        tree.add('bar')
266
 
        tree.lock_tree_write()
267
 
        self.addCleanup(tree.unlock)
268
206
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
269
 
        self.addCleanup(shelver.finalize)
270
207
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
271
208
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
272
209
        shelver.run()
273
210
 
274
211
    def test_shelve_help(self):
275
212
        tree = self.create_shelvable_tree()
276
 
        tree.lock_tree_write()
277
 
        self.addCleanup(tree.unlock)
278
213
        shelver = ExpectShelver(tree, tree.basis_tree())
279
 
        self.addCleanup(shelver.finalize)
280
214
        shelver.expect('Shelve? [yNfq?]', '?')
281
215
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
282
216
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
283
217
        shelver.run()
284
218
 
285
 
    def test_shelve_destroy(self):
 
219
    def test_shelve_distroy(self):
286
220
        tree = self.create_shelvable_tree()
287
221
        shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
288
222
                                             directory='tree', destroy=True)
289
 
        self.addCleanup(shelver.finalize)
290
223
        shelver.run()
291
224
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
292
225
        self.assertFileEqual(LINES_AJ, 'tree/foo')
293
226
 
294
 
    @staticmethod
295
 
    def shelve_all(tree, target_revision_id):
296
 
        tree.lock_write()
297
 
        try:
298
 
            target = tree.branch.repository.revision_tree(target_revision_id)
299
 
            shelver = shelf_ui.Shelver(tree, target, auto=True,
300
 
                                       auto_apply=True)
301
 
            try:
302
 
                shelver.run()
303
 
            finally:
304
 
                shelver.finalize()
305
 
        finally:
306
 
            tree.unlock()
307
 
 
308
 
    def test_shelve_old_root_preserved(self):
309
 
        tree1 = self.make_branch_and_tree('tree1')
310
 
        tree1.commit('add root')
311
 
        tree1_root_id = tree1.get_root_id()
312
 
        tree2 = self.make_branch_and_tree('tree2')
313
 
        rev2 = tree2.commit('add root')
314
 
        self.assertNotEquals(tree1_root_id, tree2.get_root_id())
315
 
        tree1.merge_from_branch(tree2.branch,
316
 
                                from_revision=revision.NULL_REVISION)
317
 
        tree1.commit('merging in tree2')
318
 
        self.assertEquals(tree1_root_id, tree1.get_root_id())
319
 
        # 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))
329
 
 
330
 
    def test_shelve_split(self):
331
 
        outer_tree = self.make_branch_and_tree('outer')
332
 
        outer_tree.commit('Add root')
333
 
        inner_tree = self.make_branch_and_tree('outer/inner')
334
 
        rev2 = inner_tree.commit('Add root')
335
 
        outer_tree.subsume(inner_tree)
336
 
        # This is essentially assertNotRaises(ValueError).
337
 
        # The ValueError is 'None is not a valid file id'.
338
 
        self.expectFailure('Cannot shelve a join back to the inner tree.',
339
 
                           self.assertRaises, AssertionError,
340
 
                           self.assertRaises, ValueError, self.shelve_all,
341
 
                           outer_tree, rev2)
342
 
 
343
 
 
344
 
class TestApplyReporter(ShelfTestCase):
 
227
 
 
228
class TestApplyReporter(TestShelver):
345
229
 
346
230
    def test_shelve_not_diff(self):
347
231
        tree = self.create_shelvable_tree()
348
 
        tree.lock_tree_write()
349
 
        self.addCleanup(tree.unlock)
350
232
        shelver = ExpectShelver(tree, tree.basis_tree(),
351
233
                                reporter=shelf_ui.ApplyReporter())
352
 
        self.addCleanup(shelver.finalize)
353
234
        shelver.expect('Apply change? [yNfq?]', 'n')
354
235
        shelver.expect('Apply change? [yNfq?]', 'n')
355
236
        # No final shelving prompt because no changes were selected
358
239
 
359
240
    def test_shelve_diff_no(self):
360
241
        tree = self.create_shelvable_tree()
361
 
        tree.lock_tree_write()
362
 
        self.addCleanup(tree.unlock)
363
242
        shelver = ExpectShelver(tree, tree.basis_tree(),
364
243
                                reporter=shelf_ui.ApplyReporter())
365
 
        self.addCleanup(shelver.finalize)
366
244
        shelver.expect('Apply change? [yNfq?]', 'y')
367
245
        shelver.expect('Apply change? [yNfq?]', 'y')
368
246
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
371
249
 
372
250
    def test_shelve_diff(self):
373
251
        tree = self.create_shelvable_tree()
374
 
        tree.lock_tree_write()
375
 
        self.addCleanup(tree.unlock)
376
252
        shelver = ExpectShelver(tree, tree.basis_tree(),
377
253
                                reporter=shelf_ui.ApplyReporter())
378
 
        self.addCleanup(shelver.finalize)
379
254
        shelver.expect('Apply change? [yNfq?]', 'y')
380
255
        shelver.expect('Apply change? [yNfq?]', 'y')
381
256
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
385
260
    def test_shelve_binary_change(self):
386
261
        tree = self.create_shelvable_tree()
387
262
        self.build_tree_contents([('tree/foo', '\x00')])
388
 
        tree.lock_tree_write()
389
 
        self.addCleanup(tree.unlock)
390
263
        shelver = ExpectShelver(tree, tree.basis_tree(),
391
264
                                reporter=shelf_ui.ApplyReporter())
392
 
        self.addCleanup(shelver.finalize)
393
265
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
394
266
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
395
267
        shelver.run()
398
270
    def test_shelve_rename(self):
399
271
        tree = self.create_shelvable_tree()
400
272
        tree.rename_one('foo', 'bar')
401
 
        tree.lock_tree_write()
402
 
        self.addCleanup(tree.unlock)
403
273
        shelver = ExpectShelver(tree, tree.basis_tree(),
404
274
                                reporter=shelf_ui.ApplyReporter())
405
 
        self.addCleanup(shelver.finalize)
406
275
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
407
276
        shelver.expect('Apply change? [yNfq?]', 'y')
408
277
        shelver.expect('Apply change? [yNfq?]', 'y')
413
282
    def test_shelve_deletion(self):
414
283
        tree = self.create_shelvable_tree()
415
284
        os.unlink('tree/foo')
416
 
        tree.lock_tree_write()
417
 
        self.addCleanup(tree.unlock)
418
285
        shelver = ExpectShelver(tree, tree.basis_tree(),
419
286
                                reporter=shelf_ui.ApplyReporter())
420
 
        self.addCleanup(shelver.finalize)
421
287
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
422
288
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
423
289
        shelver.run()
428
294
        tree.commit('add tree root')
429
295
        self.build_tree(['tree/foo'])
430
296
        tree.add('foo')
431
 
        tree.lock_tree_write()
432
 
        self.addCleanup(tree.unlock)
433
297
        shelver = ExpectShelver(tree, tree.basis_tree(),
434
298
                                reporter=shelf_ui.ApplyReporter())
435
 
        self.addCleanup(shelver.finalize)
436
299
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
437
300
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
438
301
        shelver.run()
439
 
        self.assertPathDoesNotExist('tree/foo')
 
302
        self.failIfExists('tree/foo')
440
303
 
441
304
    def test_shelve_kind_change(self):
442
305
        tree = self.create_shelvable_tree()
443
306
        os.unlink('tree/foo')
444
307
        os.mkdir('tree/foo')
445
 
        tree.lock_tree_write()
446
 
        self.addCleanup(tree.unlock)
447
308
        shelver = ExpectShelver(tree, tree.basis_tree(),
448
309
                               reporter=shelf_ui.ApplyReporter())
449
 
        self.addCleanup(shelver.finalize)
450
310
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
451
311
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
452
312
 
453
313
    def test_shelve_modify_target(self):
454
 
        self.requireFeature(features.SymlinkFeature)
 
314
        self.requireFeature(tests.SymlinkFeature)
455
315
        tree = self.create_shelvable_tree()
456
316
        os.symlink('bar', 'tree/baz')
457
317
        tree.add('baz', 'baz-id')
458
318
        tree.commit("Add symlink")
459
319
        os.unlink('tree/baz')
460
320
        os.symlink('vax', 'tree/baz')
461
 
        tree.lock_tree_write()
462
 
        self.addCleanup(tree.unlock)
463
321
        shelver = ExpectShelver(tree, tree.basis_tree(),
464
322
                                reporter=shelf_ui.ApplyReporter())
465
 
        self.addCleanup(shelver.finalize)
466
323
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
467
324
                       'y')
468
325
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
474
331
 
475
332
    def create_tree_with_shelf(self):
476
333
        tree = self.make_branch_and_tree('tree')
477
 
        tree.lock_write()
478
 
        try:
479
 
            self.build_tree_contents([('tree/foo', LINES_AJ)])
480
 
            tree.add('foo', 'foo-id')
481
 
            tree.commit('added foo')
482
 
            self.build_tree_contents([('tree/foo', LINES_ZY)])
483
 
            shelver = shelf_ui.Shelver(tree, tree.basis_tree(),
484
 
                                       auto_apply=True, auto=True)
485
 
            try:
486
 
                shelver.run()
487
 
            finally:
488
 
                shelver.finalize()
489
 
        finally:
490
 
            tree.unlock()
 
334
        self.build_tree_contents([('tree/foo', LINES_AJ)])
 
335
        tree.add('foo', 'foo-id')
 
336
        tree.commit('added foo')
 
337
        self.build_tree_contents([('tree/foo', LINES_ZY)])
 
338
        shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
 
339
                         auto=True).run()
491
340
        return tree
492
341
 
493
342
    def test_unshelve(self):
500
349
 
501
350
    def test_unshelve_args(self):
502
351
        tree = self.create_tree_with_shelf()
503
 
        unshelver = shelf_ui.Unshelver.from_args(directory='tree')
504
 
        try:
505
 
            unshelver.run()
506
 
        finally:
507
 
            unshelver.tree.unlock()
 
352
        shelf_ui.Unshelver.from_args(directory='tree').run()
508
353
        self.assertFileEqual(LINES_ZY, 'tree/foo')
509
354
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
510
355
 
511
356
    def test_unshelve_args_dry_run(self):
512
357
        tree = self.create_tree_with_shelf()
513
 
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
514
 
            action='dry-run')
515
 
        try:
516
 
            unshelver.run()
517
 
        finally:
518
 
            unshelver.tree.unlock()
519
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
520
 
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
521
 
 
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):])
 
358
        shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
 
359
        self.assertFileEqual(LINES_AJ, 'tree/foo')
 
360
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
553
361
 
554
362
    def test_unshelve_args_delete_only(self):
555
363
        tree = self.make_branch_and_tree('tree')
561
369
            shelf_file.close()
562
370
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
563
371
                                                 action='delete-only')
564
 
        try:
565
 
            unshelver.run()
566
 
        finally:
567
 
            unshelver.tree.unlock()
 
372
        unshelver.run()
568
373
        self.assertIs(None, manager.last_shelf())
569
374
 
570
375
    def test_unshelve_args_invalid_shelf_id(self):
578
383
        self.assertRaises(errors.InvalidShelfId,
579
384
            shelf_ui.Unshelver.from_args, directory='tree',
580
385
            action='delete-only', shelf_id='foo')
581
 
 
582
 
 
583
 
class TestUnshelveScripts(TestUnshelver, 
584
 
                          script.TestCaseWithTransportAndScript): 
585
 
 
586
 
    def test_unshelve_messages_keep(self):
587
 
        self.create_tree_with_shelf()
588
 
        self.run_script("""
589
 
$ cd tree
590
 
$ bzr unshelve --keep
591
 
2>Using changes with id "1".
592
 
2> M  foo
593
 
2>All changes applied successfully.
594
 
""")
595
 
 
596
 
    def test_unshelve_messages_delete(self):
597
 
        self.create_tree_with_shelf()
598
 
        self.run_script("""
599
 
$ cd tree
600
 
$ bzr unshelve --delete-only
601
 
2>Deleted changes with id "1".
602
 
""")
603
 
 
604
 
    def test_unshelve_messages_apply(self):
605
 
        self.create_tree_with_shelf()
606
 
        self.run_script("""
607
 
$ cd tree
608
 
$ bzr unshelve --apply
609
 
2>Using changes with id "1".
610
 
2> M  foo
611
 
2>All changes applied successfully.
612
 
2>Deleted changes with id "1".
613
 
""")
614
 
 
615
 
    def test_unshelve_messages_dry_run(self):
616
 
        self.create_tree_with_shelf()
617
 
        self.run_script("""
618
 
$ cd tree
619
 
$ bzr unshelve --dry-run
620
 
2>Using changes with id "1".
621
 
2> M  foo
622
 
""")