~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: 2009-03-06 20:42:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4088.
  • Revision ID: john@arbash-meinel.com-20090306204240-mzjavv31z3gu1x7i
Fix a small bug in setup.py when an extension fails to build

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
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
 
22
from bzrlib import errors, shelf_ui, tests
30
23
 
31
24
 
32
25
class ExpectShelver(shelf_ui.Shelver):
33
26
    """A variant of Shelver that intercepts console activity, for testing."""
34
27
 
35
 
    def __init__(self, work_tree, target_tree, diff_writer=None,
36
 
                 auto=False, auto_apply=False, file_list=None, message=None,
37
 
                 destroy=False, reporter=None):
 
28
    def __init__(self, work_tree, target_tree, diff_writer=None, path=None,
 
29
                 auto=False, auto_apply=False, file_list=None, message=None):
38
30
        shelf_ui.Shelver.__init__(self, work_tree, target_tree, diff_writer,
39
 
                                  auto, auto_apply, file_list, message,
40
 
                                  destroy, reporter=reporter)
 
31
                                  auto, auto_apply, file_list, message)
41
32
        self.expected = []
42
33
        self.diff_writer = StringIO()
43
34
 
75
66
 
76
67
    def test_unexpected_prompt_failure(self):
77
68
        tree = self.create_shelvable_tree()
78
 
        tree.lock_tree_write()
79
 
        self.addCleanup(tree.unlock)
80
69
        shelver = ExpectShelver(tree, tree.basis_tree())
81
 
        self.addCleanup(shelver.finalize)
82
70
        e = self.assertRaises(AssertionError, shelver.run)
83
71
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
84
72
 
85
73
    def test_wrong_prompt_failure(self):
86
74
        tree = self.create_shelvable_tree()
87
 
        tree.lock_tree_write()
88
 
        self.addCleanup(tree.unlock)
89
75
        shelver = ExpectShelver(tree, tree.basis_tree())
90
 
        self.addCleanup(shelver.finalize)
91
76
        shelver.expect('foo', 'y')
92
77
        e = self.assertRaises(AssertionError, shelver.run)
93
78
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
94
79
 
95
80
    def test_shelve_not_diff(self):
96
81
        tree = self.create_shelvable_tree()
97
 
        tree.lock_tree_write()
98
 
        self.addCleanup(tree.unlock)
99
82
        shelver = ExpectShelver(tree, tree.basis_tree())
100
 
        self.addCleanup(shelver.finalize)
101
83
        shelver.expect('Shelve? [yNfq?]', 'n')
102
84
        shelver.expect('Shelve? [yNfq?]', 'n')
103
85
        # No final shelving prompt because no changes were selected
106
88
 
107
89
    def test_shelve_diff_no(self):
108
90
        tree = self.create_shelvable_tree()
109
 
        tree.lock_tree_write()
110
 
        self.addCleanup(tree.unlock)
111
91
        shelver = ExpectShelver(tree, tree.basis_tree())
112
 
        self.addCleanup(shelver.finalize)
113
92
        shelver.expect('Shelve? [yNfq?]', 'y')
114
93
        shelver.expect('Shelve? [yNfq?]', 'y')
115
94
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n')
118
97
 
119
98
    def test_shelve_diff(self):
120
99
        tree = self.create_shelvable_tree()
121
 
        tree.lock_tree_write()
122
 
        self.addCleanup(tree.unlock)
123
100
        shelver = ExpectShelver(tree, tree.basis_tree())
124
 
        self.addCleanup(shelver.finalize)
125
101
        shelver.expect('Shelve? [yNfq?]', 'y')
126
102
        shelver.expect('Shelve? [yNfq?]', 'y')
127
103
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
130
106
 
131
107
    def test_shelve_one_diff(self):
132
108
        tree = self.create_shelvable_tree()
133
 
        tree.lock_tree_write()
134
 
        self.addCleanup(tree.unlock)
135
109
        shelver = ExpectShelver(tree, tree.basis_tree())
136
 
        self.addCleanup(shelver.finalize)
137
110
        shelver.expect('Shelve? [yNfq?]', 'y')
138
111
        shelver.expect('Shelve? [yNfq?]', 'n')
139
112
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
143
116
    def test_shelve_binary_change(self):
144
117
        tree = self.create_shelvable_tree()
145
118
        self.build_tree_contents([('tree/foo', '\x00')])
146
 
        tree.lock_tree_write()
147
 
        self.addCleanup(tree.unlock)
148
119
        shelver = ExpectShelver(tree, tree.basis_tree())
149
 
        self.addCleanup(shelver.finalize)
150
120
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
151
121
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
152
122
        shelver.run()
155
125
    def test_shelve_rename(self):
156
126
        tree = self.create_shelvable_tree()
157
127
        tree.rename_one('foo', 'bar')
158
 
        tree.lock_tree_write()
159
 
        self.addCleanup(tree.unlock)
160
128
        shelver = ExpectShelver(tree, tree.basis_tree())
161
 
        self.addCleanup(shelver.finalize)
162
129
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
163
130
        shelver.expect('Shelve? [yNfq?]', 'y')
164
131
        shelver.expect('Shelve? [yNfq?]', 'y')
169
136
    def test_shelve_deletion(self):
170
137
        tree = self.create_shelvable_tree()
171
138
        os.unlink('tree/foo')
172
 
        tree.lock_tree_write()
173
 
        self.addCleanup(tree.unlock)
174
139
        shelver = ExpectShelver(tree, tree.basis_tree())
175
 
        self.addCleanup(shelver.finalize)
176
140
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
177
141
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
178
142
        shelver.run()
183
147
        tree.commit('add tree root')
184
148
        self.build_tree(['tree/foo'])
185
149
        tree.add('foo')
186
 
        tree.lock_tree_write()
187
 
        self.addCleanup(tree.unlock)
188
150
        shelver = ExpectShelver(tree, tree.basis_tree())
189
 
        self.addCleanup(shelver.finalize)
190
151
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
191
152
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
192
153
        shelver.run()
196
157
        tree = self.create_shelvable_tree()
197
158
        os.unlink('tree/foo')
198
159
        os.mkdir('tree/foo')
199
 
        tree.lock_tree_write()
200
 
        self.addCleanup(tree.unlock)
201
160
        shelver = ExpectShelver(tree, tree.basis_tree())
202
 
        self.addCleanup(shelver.finalize)
203
161
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
204
162
                       'y')
205
163
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
206
164
 
207
 
    def test_shelve_modify_target(self):
208
 
        self.requireFeature(tests.SymlinkFeature)
209
 
        tree = self.create_shelvable_tree()
210
 
        os.symlink('bar', 'tree/baz')
211
 
        tree.add('baz', 'baz-id')
212
 
        tree.commit("Add symlink")
213
 
        os.unlink('tree/baz')
214
 
        os.symlink('vax', 'tree/baz')
215
 
        tree.lock_tree_write()
216
 
        self.addCleanup(tree.unlock)
217
 
        shelver = ExpectShelver(tree, tree.basis_tree())
218
 
        self.addCleanup(shelver.finalize)
219
 
        shelver.expect('Shelve changing target of "baz" from "bar" to '
220
 
                '"vax"? [yNfq?]', 'y')
221
 
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
222
 
        shelver.run()
223
 
        self.assertEqual('bar', os.readlink('tree/baz'))
224
 
 
225
165
    def test_shelve_finish(self):
226
166
        tree = self.create_shelvable_tree()
227
 
        tree.lock_tree_write()
228
 
        self.addCleanup(tree.unlock)
229
167
        shelver = ExpectShelver(tree, tree.basis_tree())
230
 
        self.addCleanup(shelver.finalize)
231
168
        shelver.expect('Shelve? [yNfq?]', 'f')
232
169
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
233
170
        shelver.run()
235
172
 
236
173
    def test_shelve_quit(self):
237
174
        tree = self.create_shelvable_tree()
238
 
        tree.lock_tree_write()
239
 
        self.addCleanup(tree.unlock)
240
175
        shelver = ExpectShelver(tree, tree.basis_tree())
241
 
        self.addCleanup(shelver.finalize)
242
176
        shelver.expect('Shelve? [yNfq?]', 'q')
243
177
        self.assertRaises(errors.UserAbort, shelver.run)
244
178
        self.assertFileEqual(LINES_ZY, 'tree/foo')
245
179
 
246
180
    def test_shelve_all(self):
247
181
        tree = self.create_shelvable_tree()
248
 
        shelver = ExpectShelver.from_args(sys.stdout, all=True,
249
 
            directory='tree')
250
 
        try:
251
 
            shelver.run()
252
 
        finally:
253
 
            shelver.finalize()
 
182
        ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
254
183
        self.assertFileEqual(LINES_AJ, 'tree/foo')
255
184
 
256
185
    def test_shelve_filename(self):
257
186
        tree = self.create_shelvable_tree()
258
187
        self.build_tree(['tree/bar'])
259
188
        tree.add('bar')
260
 
        tree.lock_tree_write()
261
 
        self.addCleanup(tree.unlock)
262
189
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
263
 
        self.addCleanup(shelver.finalize)
264
190
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
265
191
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
266
192
        shelver.run()
267
193
 
268
194
    def test_shelve_help(self):
269
195
        tree = self.create_shelvable_tree()
270
 
        tree.lock_tree_write()
271
 
        self.addCleanup(tree.unlock)
272
196
        shelver = ExpectShelver(tree, tree.basis_tree())
273
 
        self.addCleanup(shelver.finalize)
274
197
        shelver.expect('Shelve? [yNfq?]', '?')
275
198
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
276
199
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
277
200
        shelver.run()
278
201
 
279
 
    def test_shelve_destroy(self):
280
 
        tree = self.create_shelvable_tree()
281
 
        shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
282
 
                                             directory='tree', destroy=True)
283
 
        self.addCleanup(shelver.finalize)
284
 
        shelver.run()
285
 
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
286
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
287
 
 
288
 
    @staticmethod
289
 
    def shelve_all(tree, target_revision_id):
290
 
        tree.lock_write()
291
 
        try:
292
 
            target = tree.branch.repository.revision_tree(target_revision_id)
293
 
            shelver = shelf_ui.Shelver(tree, target, auto=True,
294
 
                                       auto_apply=True)
295
 
            try:
296
 
                shelver.run()
297
 
            finally:
298
 
                shelver.finalize()
299
 
        finally:
300
 
            tree.unlock()
301
 
 
302
 
    def test_shelve_old_root_deleted(self):
303
 
        tree1 = self.make_branch_and_tree('tree1')
304
 
        tree1.commit('add root')
305
 
        tree2 = self.make_branch_and_tree('tree2')
306
 
        rev2 = tree2.commit('add root')
307
 
        tree1.merge_from_branch(tree2.branch,
308
 
                                from_revision=revision.NULL_REVISION)
309
 
        tree1.commit('Replaced root entry')
310
 
        # This is essentially assertNotRaises(InconsistentDelta)
311
 
        self.expectFailure('Cannot shelve replacing a root entry',
312
 
                           self.assertRaises, AssertionError,
313
 
                           self.assertRaises, errors.InconsistentDelta,
314
 
                           self.shelve_all, tree1, rev2)
315
 
 
316
 
    def test_shelve_split(self):
317
 
        outer_tree = self.make_branch_and_tree('outer')
318
 
        outer_tree.commit('Add root')
319
 
        inner_tree = self.make_branch_and_tree('outer/inner')
320
 
        rev2 = inner_tree.commit('Add root')
321
 
        outer_tree.subsume(inner_tree)
322
 
        # This is essentially assertNotRaises(ValueError).
323
 
        # The ValueError is 'None is not a valid file id'.
324
 
        self.expectFailure('Cannot shelve a join back to the inner tree.',
325
 
                           self.assertRaises, AssertionError,
326
 
                           self.assertRaises, ValueError, self.shelve_all,
327
 
                           outer_tree, rev2)
328
 
 
329
 
 
330
 
class TestApplyReporter(TestShelver):
331
 
 
332
 
    def test_shelve_not_diff(self):
333
 
        tree = self.create_shelvable_tree()
334
 
        tree.lock_tree_write()
335
 
        self.addCleanup(tree.unlock)
336
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
337
 
                                reporter=shelf_ui.ApplyReporter())
338
 
        self.addCleanup(shelver.finalize)
339
 
        shelver.expect('Apply change? [yNfq?]', 'n')
340
 
        shelver.expect('Apply change? [yNfq?]', 'n')
341
 
        # No final shelving prompt because no changes were selected
342
 
        shelver.run()
343
 
        self.assertFileEqual(LINES_ZY, 'tree/foo')
344
 
 
345
 
    def test_shelve_diff_no(self):
346
 
        tree = self.create_shelvable_tree()
347
 
        tree.lock_tree_write()
348
 
        self.addCleanup(tree.unlock)
349
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
350
 
                                reporter=shelf_ui.ApplyReporter())
351
 
        self.addCleanup(shelver.finalize)
352
 
        shelver.expect('Apply change? [yNfq?]', 'y')
353
 
        shelver.expect('Apply change? [yNfq?]', 'y')
354
 
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
355
 
        shelver.run()
356
 
        self.assertFileEqual(LINES_ZY, 'tree/foo')
357
 
 
358
 
    def test_shelve_diff(self):
359
 
        tree = self.create_shelvable_tree()
360
 
        tree.lock_tree_write()
361
 
        self.addCleanup(tree.unlock)
362
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
363
 
                                reporter=shelf_ui.ApplyReporter())
364
 
        self.addCleanup(shelver.finalize)
365
 
        shelver.expect('Apply change? [yNfq?]', 'y')
366
 
        shelver.expect('Apply change? [yNfq?]', 'y')
367
 
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
368
 
        shelver.run()
369
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
370
 
 
371
 
    def test_shelve_binary_change(self):
372
 
        tree = self.create_shelvable_tree()
373
 
        self.build_tree_contents([('tree/foo', '\x00')])
374
 
        tree.lock_tree_write()
375
 
        self.addCleanup(tree.unlock)
376
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
377
 
                                reporter=shelf_ui.ApplyReporter())
378
 
        self.addCleanup(shelver.finalize)
379
 
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
380
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
381
 
        shelver.run()
382
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
383
 
 
384
 
    def test_shelve_rename(self):
385
 
        tree = self.create_shelvable_tree()
386
 
        tree.rename_one('foo', 'bar')
387
 
        tree.lock_tree_write()
388
 
        self.addCleanup(tree.unlock)
389
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
390
 
                                reporter=shelf_ui.ApplyReporter())
391
 
        self.addCleanup(shelver.finalize)
392
 
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
393
 
        shelver.expect('Apply change? [yNfq?]', 'y')
394
 
        shelver.expect('Apply change? [yNfq?]', 'y')
395
 
        shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
396
 
        shelver.run()
397
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
398
 
 
399
 
    def test_shelve_deletion(self):
400
 
        tree = self.create_shelvable_tree()
401
 
        os.unlink('tree/foo')
402
 
        tree.lock_tree_write()
403
 
        self.addCleanup(tree.unlock)
404
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
405
 
                                reporter=shelf_ui.ApplyReporter())
406
 
        self.addCleanup(shelver.finalize)
407
 
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
408
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
409
 
        shelver.run()
410
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
411
 
 
412
 
    def test_shelve_creation(self):
413
 
        tree = self.make_branch_and_tree('tree')
414
 
        tree.commit('add tree root')
415
 
        self.build_tree(['tree/foo'])
416
 
        tree.add('foo')
417
 
        tree.lock_tree_write()
418
 
        self.addCleanup(tree.unlock)
419
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
420
 
                                reporter=shelf_ui.ApplyReporter())
421
 
        self.addCleanup(shelver.finalize)
422
 
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
423
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
424
 
        shelver.run()
425
 
        self.failIfExists('tree/foo')
426
 
 
427
 
    def test_shelve_kind_change(self):
428
 
        tree = self.create_shelvable_tree()
429
 
        os.unlink('tree/foo')
430
 
        os.mkdir('tree/foo')
431
 
        tree.lock_tree_write()
432
 
        self.addCleanup(tree.unlock)
433
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
434
 
                               reporter=shelf_ui.ApplyReporter())
435
 
        self.addCleanup(shelver.finalize)
436
 
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
437
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
438
 
 
439
 
    def test_shelve_modify_target(self):
440
 
        self.requireFeature(tests.SymlinkFeature)
441
 
        tree = self.create_shelvable_tree()
442
 
        os.symlink('bar', 'tree/baz')
443
 
        tree.add('baz', 'baz-id')
444
 
        tree.commit("Add symlink")
445
 
        os.unlink('tree/baz')
446
 
        os.symlink('vax', 'tree/baz')
447
 
        tree.lock_tree_write()
448
 
        self.addCleanup(tree.unlock)
449
 
        shelver = ExpectShelver(tree, tree.basis_tree(),
450
 
                                reporter=shelf_ui.ApplyReporter())
451
 
        self.addCleanup(shelver.finalize)
452
 
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
453
 
                       'y')
454
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
455
 
        shelver.run()
456
 
        self.assertEqual('bar', os.readlink('tree/baz'))
457
 
 
458
202
 
459
203
class TestUnshelver(tests.TestCaseWithTransport):
460
204
 
461
205
    def create_tree_with_shelf(self):
462
206
        tree = self.make_branch_and_tree('tree')
463
 
        tree.lock_write()
464
 
        try:
465
 
            self.build_tree_contents([('tree/foo', LINES_AJ)])
466
 
            tree.add('foo', 'foo-id')
467
 
            tree.commit('added foo')
468
 
            self.build_tree_contents([('tree/foo', LINES_ZY)])
469
 
            shelver = shelf_ui.Shelver(tree, tree.basis_tree(),
470
 
                                       auto_apply=True, auto=True)
471
 
            try:
472
 
                shelver.run()
473
 
            finally:
474
 
                shelver.finalize()
475
 
        finally:
476
 
            tree.unlock()
 
207
        self.build_tree_contents([('tree/foo', LINES_AJ)])
 
208
        tree.add('foo', 'foo-id')
 
209
        tree.commit('added foo')
 
210
        self.build_tree_contents([('tree/foo', LINES_ZY)])
 
211
        shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
 
212
                         auto=True).run()
477
213
        return tree
478
214
 
479
215
    def test_unshelve(self):
486
222
 
487
223
    def test_unshelve_args(self):
488
224
        tree = self.create_tree_with_shelf()
489
 
        unshelver = shelf_ui.Unshelver.from_args(directory='tree')
490
 
        try:
491
 
            unshelver.run()
492
 
        finally:
493
 
            unshelver.tree.unlock()
 
225
        shelf_ui.Unshelver.from_args(directory='tree').run()
494
226
        self.assertFileEqual(LINES_ZY, 'tree/foo')
495
227
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
496
228
 
497
229
    def test_unshelve_args_dry_run(self):
498
230
        tree = self.create_tree_with_shelf()
499
 
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
500
 
            action='dry-run')
501
 
        try:
502
 
            unshelver.run()
503
 
        finally:
504
 
            unshelver.tree.unlock()
505
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
506
 
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
507
 
 
508
 
    def test_unshelve_args_preview(self):
509
 
        tree = self.create_tree_with_shelf()
510
 
        write_diff_to = StringIO()
511
 
        unshelver = shelf_ui.Unshelver.from_args(
512
 
            directory='tree', action='preview', write_diff_to=write_diff_to)
513
 
        try:
514
 
            unshelver.run()
515
 
        finally:
516
 
            unshelver.tree.unlock()
517
 
        # The changes were not unshelved.
518
 
        self.assertFileEqual(LINES_AJ, 'tree/foo')
519
 
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
520
 
 
521
 
        # But the diff was written to write_diff_to.
522
 
        diff = write_diff_to.getvalue()
523
 
        expected = dedent("""\
524
 
            @@ -1,4 +1,4 @@
525
 
            -a
526
 
            +z
527
 
             b
528
 
             c
529
 
             d
530
 
            @@ -7,4 +7,4 @@
531
 
             g
532
 
             h
533
 
             i
534
 
            -j
535
 
            +y
536
 
 
537
 
            """)
538
 
        self.assertEqualDiff(expected, diff[-len(expected):])
 
231
        shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
 
232
        self.assertFileEqual(LINES_AJ, 'tree/foo')
 
233
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
539
234
 
540
235
    def test_unshelve_args_delete_only(self):
541
236
        tree = self.make_branch_and_tree('tree')
547
242
            shelf_file.close()
548
243
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
549
244
                                                 action='delete-only')
550
 
        try:
551
 
            unshelver.run()
552
 
        finally:
553
 
            unshelver.tree.unlock()
 
245
        unshelver.run()
554
246
        self.assertIs(None, manager.last_shelf())
555
247
 
556
248
    def test_unshelve_args_invalid_shelf_id(self):
564
256
        self.assertRaises(errors.InvalidShelfId,
565
257
            shelf_ui.Unshelver.from_args, directory='tree',
566
258
            action='delete-only', shelf_id='foo')
567
 
 
568
 
 
569
 
class TestUnshelveScripts(TestUnshelver, 
570
 
                          script.TestCaseWithTransportAndScript): 
571
 
 
572
 
    def test_unshelve_messages_keep(self):
573
 
        self.create_tree_with_shelf()
574
 
        self.run_script("""
575
 
$ cd tree
576
 
$ bzr unshelve --keep
577
 
2>Using changes with id "1".
578
 
2> M  foo
579
 
2>All changes applied successfully.
580
 
""")
581
 
 
582
 
    def test_unshelve_messages_delete(self):
583
 
        self.create_tree_with_shelf()
584
 
        self.run_script("""
585
 
$ cd tree
586
 
$ bzr unshelve --delete-only
587
 
2>Deleted changes with id "1".
588
 
""")
589
 
 
590
 
    def test_unshelve_messages_apply(self):
591
 
        self.create_tree_with_shelf()
592
 
        self.run_script("""
593
 
$ cd tree
594
 
$ bzr unshelve --apply
595
 
2>Using changes with id "1".
596
 
2> M  foo
597
 
2>All changes applied successfully.
598
 
2>Deleted changes with id "1".
599
 
""")
600
 
 
601
 
    def test_unshelve_messages_dry_run(self):
602
 
        self.create_tree_with_shelf()
603
 
        self.run_script("""
604
 
$ cd tree
605
 
$ bzr unshelve --dry-run
606
 
2>Using changes with id "1".
607
 
2> M  foo
608
 
""")