~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Robert Collins
  • Date: 2009-08-25 23:47:08 UTC
  • mfrom: (4650 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4651.
  • Revision ID: robertc@robertcollins.net-20090825234708-utgl9u6v12sosp5c
NEWS Conflict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        return tree
73
73
 
74
74
    def test_unexpected_prompt_failure(self):
75
 
        self.thisFailsStrictLockCheck()
76
75
        tree = self.create_shelvable_tree()
 
76
        tree.lock_tree_write()
 
77
        self.addCleanup(tree.unlock)
77
78
        shelver = ExpectShelver(tree, tree.basis_tree())
78
79
        e = self.assertRaises(AssertionError, shelver.run)
79
80
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
80
81
 
81
82
    def test_wrong_prompt_failure(self):
82
 
        self.thisFailsStrictLockCheck()
83
83
        tree = self.create_shelvable_tree()
 
84
        tree.lock_tree_write()
 
85
        self.addCleanup(tree.unlock)
84
86
        shelver = ExpectShelver(tree, tree.basis_tree())
85
87
        shelver.expect('foo', 'y')
86
88
        e = self.assertRaises(AssertionError, shelver.run)
87
89
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
88
90
 
89
91
    def test_shelve_not_diff(self):
90
 
        self.thisFailsStrictLockCheck()
91
92
        tree = self.create_shelvable_tree()
 
93
        tree.lock_tree_write()
 
94
        self.addCleanup(tree.unlock)
92
95
        shelver = ExpectShelver(tree, tree.basis_tree())
93
96
        shelver.expect('Shelve? [yNfq?]', 'n')
94
97
        shelver.expect('Shelve? [yNfq?]', 'n')
97
100
        self.assertFileEqual(LINES_ZY, 'tree/foo')
98
101
 
99
102
    def test_shelve_diff_no(self):
100
 
        self.thisFailsStrictLockCheck()
101
103
        tree = self.create_shelvable_tree()
 
104
        tree.lock_tree_write()
 
105
        self.addCleanup(tree.unlock)
102
106
        shelver = ExpectShelver(tree, tree.basis_tree())
103
107
        shelver.expect('Shelve? [yNfq?]', 'y')
104
108
        shelver.expect('Shelve? [yNfq?]', 'y')
107
111
        self.assertFileEqual(LINES_ZY, 'tree/foo')
108
112
 
109
113
    def test_shelve_diff(self):
110
 
        self.thisFailsStrictLockCheck()
111
114
        tree = self.create_shelvable_tree()
 
115
        tree.lock_tree_write()
 
116
        self.addCleanup(tree.unlock)
112
117
        shelver = ExpectShelver(tree, tree.basis_tree())
113
118
        shelver.expect('Shelve? [yNfq?]', 'y')
114
119
        shelver.expect('Shelve? [yNfq?]', 'y')
117
122
        self.assertFileEqual(LINES_AJ, 'tree/foo')
118
123
 
119
124
    def test_shelve_one_diff(self):
120
 
        self.thisFailsStrictLockCheck()
121
125
        tree = self.create_shelvable_tree()
 
126
        tree.lock_tree_write()
 
127
        self.addCleanup(tree.unlock)
122
128
        shelver = ExpectShelver(tree, tree.basis_tree())
123
129
        shelver.expect('Shelve? [yNfq?]', 'y')
124
130
        shelver.expect('Shelve? [yNfq?]', 'n')
127
133
        self.assertFileEqual(LINES_AY, 'tree/foo')
128
134
 
129
135
    def test_shelve_binary_change(self):
130
 
        self.thisFailsStrictLockCheck()
131
136
        tree = self.create_shelvable_tree()
132
137
        self.build_tree_contents([('tree/foo', '\x00')])
 
138
        tree.lock_tree_write()
 
139
        self.addCleanup(tree.unlock)
133
140
        shelver = ExpectShelver(tree, tree.basis_tree())
134
141
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
135
142
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
137
144
        self.assertFileEqual(LINES_AJ, 'tree/foo')
138
145
 
139
146
    def test_shelve_rename(self):
140
 
        self.thisFailsStrictLockCheck()
141
147
        tree = self.create_shelvable_tree()
142
148
        tree.rename_one('foo', 'bar')
 
149
        tree.lock_tree_write()
 
150
        self.addCleanup(tree.unlock)
143
151
        shelver = ExpectShelver(tree, tree.basis_tree())
144
152
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
145
153
        shelver.expect('Shelve? [yNfq?]', 'y')
149
157
        self.assertFileEqual(LINES_AJ, 'tree/foo')
150
158
 
151
159
    def test_shelve_deletion(self):
152
 
        self.thisFailsStrictLockCheck()
153
160
        tree = self.create_shelvable_tree()
154
161
        os.unlink('tree/foo')
 
162
        tree.lock_tree_write()
 
163
        self.addCleanup(tree.unlock)
155
164
        shelver = ExpectShelver(tree, tree.basis_tree())
156
165
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
157
166
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
159
168
        self.assertFileEqual(LINES_AJ, 'tree/foo')
160
169
 
161
170
    def test_shelve_creation(self):
162
 
        self.thisFailsStrictLockCheck()
163
171
        tree = self.make_branch_and_tree('tree')
164
172
        tree.commit('add tree root')
165
173
        self.build_tree(['tree/foo'])
166
174
        tree.add('foo')
 
175
        tree.lock_tree_write()
 
176
        self.addCleanup(tree.unlock)
167
177
        shelver = ExpectShelver(tree, tree.basis_tree())
168
178
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
169
179
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
171
181
        self.failIfExists('tree/foo')
172
182
 
173
183
    def test_shelve_kind_change(self):
174
 
        self.thisFailsStrictLockCheck()
175
184
        tree = self.create_shelvable_tree()
176
185
        os.unlink('tree/foo')
177
186
        os.mkdir('tree/foo')
 
187
        tree.lock_tree_write()
 
188
        self.addCleanup(tree.unlock)
178
189
        shelver = ExpectShelver(tree, tree.basis_tree())
179
190
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
180
191
                       'y')
181
192
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
182
193
 
183
194
    def test_shelve_modify_target(self):
184
 
        self.thisFailsStrictLockCheck()
185
195
        self.requireFeature(tests.SymlinkFeature)
186
196
        tree = self.create_shelvable_tree()
187
197
        os.symlink('bar', 'tree/baz')
189
199
        tree.commit("Add symlink")
190
200
        os.unlink('tree/baz')
191
201
        os.symlink('vax', 'tree/baz')
 
202
        tree.lock_tree_write()
 
203
        self.addCleanup(tree.unlock)
192
204
        shelver = ExpectShelver(tree, tree.basis_tree())
193
205
        shelver.expect('Shelve changing target of "baz" from "bar" to '
194
206
                '"vax"? [yNfq?]', 'y')
197
209
        self.assertEqual('bar', os.readlink('tree/baz'))
198
210
 
199
211
    def test_shelve_finish(self):
200
 
        self.thisFailsStrictLockCheck()
201
212
        tree = self.create_shelvable_tree()
 
213
        tree.lock_tree_write()
 
214
        self.addCleanup(tree.unlock)
202
215
        shelver = ExpectShelver(tree, tree.basis_tree())
203
216
        shelver.expect('Shelve? [yNfq?]', 'f')
204
217
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
206
219
        self.assertFileEqual(LINES_AJ, 'tree/foo')
207
220
 
208
221
    def test_shelve_quit(self):
209
 
        self.thisFailsStrictLockCheck()
210
222
        tree = self.create_shelvable_tree()
 
223
        tree.lock_tree_write()
 
224
        self.addCleanup(tree.unlock)
211
225
        shelver = ExpectShelver(tree, tree.basis_tree())
212
226
        shelver.expect('Shelve? [yNfq?]', 'q')
213
227
        self.assertRaises(errors.UserAbort, shelver.run)
214
228
        self.assertFileEqual(LINES_ZY, 'tree/foo')
215
229
 
216
230
    def test_shelve_all(self):
217
 
        self.thisFailsStrictLockCheck()
218
231
        tree = self.create_shelvable_tree()
219
 
        ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
 
232
        shelver = ExpectShelver.from_args(sys.stdout, all=True,
 
233
            directory='tree')
 
234
        try:
 
235
            shelver.run()
 
236
        finally:
 
237
            shelver.work_tree.unlock()
220
238
        self.assertFileEqual(LINES_AJ, 'tree/foo')
221
239
 
222
240
    def test_shelve_filename(self):
223
 
        self.thisFailsStrictLockCheck()
224
241
        tree = self.create_shelvable_tree()
225
242
        self.build_tree(['tree/bar'])
226
243
        tree.add('bar')
 
244
        tree.lock_tree_write()
 
245
        self.addCleanup(tree.unlock)
227
246
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
228
247
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
229
248
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
230
249
        shelver.run()
231
250
 
232
251
    def test_shelve_help(self):
233
 
        self.thisFailsStrictLockCheck()
234
252
        tree = self.create_shelvable_tree()
 
253
        tree.lock_tree_write()
 
254
        self.addCleanup(tree.unlock)
235
255
        shelver = ExpectShelver(tree, tree.basis_tree())
236
256
        shelver.expect('Shelve? [yNfq?]', '?')
237
257
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
239
259
        shelver.run()
240
260
 
241
261
    def test_shelve_distroy(self):
242
 
        self.thisFailsStrictLockCheck()
243
262
        tree = self.create_shelvable_tree()
244
263
        shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
245
264
                                             directory='tree', destroy=True)
246
 
        shelver.run()
 
265
        try:
 
266
            shelver.run()
 
267
        finally:
 
268
            shelver.work_tree.unlock()
247
269
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
248
270
        self.assertFileEqual(LINES_AJ, 'tree/foo')
249
271
 
289
311
class TestApplyReporter(TestShelver):
290
312
 
291
313
    def test_shelve_not_diff(self):
292
 
        self.thisFailsStrictLockCheck()
293
314
        tree = self.create_shelvable_tree()
 
315
        tree.lock_tree_write()
 
316
        self.addCleanup(tree.unlock)
294
317
        shelver = ExpectShelver(tree, tree.basis_tree(),
295
318
                                reporter=shelf_ui.ApplyReporter())
296
319
        shelver.expect('Apply change? [yNfq?]', 'n')
300
323
        self.assertFileEqual(LINES_ZY, 'tree/foo')
301
324
 
302
325
    def test_shelve_diff_no(self):
303
 
        self.thisFailsStrictLockCheck()
304
326
        tree = self.create_shelvable_tree()
 
327
        tree.lock_tree_write()
 
328
        self.addCleanup(tree.unlock)
305
329
        shelver = ExpectShelver(tree, tree.basis_tree(),
306
330
                                reporter=shelf_ui.ApplyReporter())
307
331
        shelver.expect('Apply change? [yNfq?]', 'y')
311
335
        self.assertFileEqual(LINES_ZY, 'tree/foo')
312
336
 
313
337
    def test_shelve_diff(self):
314
 
        self.thisFailsStrictLockCheck()
315
338
        tree = self.create_shelvable_tree()
 
339
        tree.lock_tree_write()
 
340
        self.addCleanup(tree.unlock)
316
341
        shelver = ExpectShelver(tree, tree.basis_tree(),
317
342
                                reporter=shelf_ui.ApplyReporter())
318
343
        shelver.expect('Apply change? [yNfq?]', 'y')
322
347
        self.assertFileEqual(LINES_AJ, 'tree/foo')
323
348
 
324
349
    def test_shelve_binary_change(self):
325
 
        self.thisFailsStrictLockCheck()
326
350
        tree = self.create_shelvable_tree()
327
351
        self.build_tree_contents([('tree/foo', '\x00')])
 
352
        tree.lock_tree_write()
 
353
        self.addCleanup(tree.unlock)
328
354
        shelver = ExpectShelver(tree, tree.basis_tree(),
329
355
                                reporter=shelf_ui.ApplyReporter())
330
356
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
333
359
        self.assertFileEqual(LINES_AJ, 'tree/foo')
334
360
 
335
361
    def test_shelve_rename(self):
336
 
        self.thisFailsStrictLockCheck()
337
362
        tree = self.create_shelvable_tree()
338
363
        tree.rename_one('foo', 'bar')
 
364
        tree.lock_tree_write()
 
365
        self.addCleanup(tree.unlock)
339
366
        shelver = ExpectShelver(tree, tree.basis_tree(),
340
367
                                reporter=shelf_ui.ApplyReporter())
341
368
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
346
373
        self.assertFileEqual(LINES_AJ, 'tree/foo')
347
374
 
348
375
    def test_shelve_deletion(self):
349
 
        self.thisFailsStrictLockCheck()
350
376
        tree = self.create_shelvable_tree()
351
377
        os.unlink('tree/foo')
 
378
        tree.lock_tree_write()
 
379
        self.addCleanup(tree.unlock)
352
380
        shelver = ExpectShelver(tree, tree.basis_tree(),
353
381
                                reporter=shelf_ui.ApplyReporter())
354
382
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
357
385
        self.assertFileEqual(LINES_AJ, 'tree/foo')
358
386
 
359
387
    def test_shelve_creation(self):
360
 
        self.thisFailsStrictLockCheck()
361
388
        tree = self.make_branch_and_tree('tree')
362
389
        tree.commit('add tree root')
363
390
        self.build_tree(['tree/foo'])
364
391
        tree.add('foo')
 
392
        tree.lock_tree_write()
 
393
        self.addCleanup(tree.unlock)
365
394
        shelver = ExpectShelver(tree, tree.basis_tree(),
366
395
                                reporter=shelf_ui.ApplyReporter())
367
396
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
370
399
        self.failIfExists('tree/foo')
371
400
 
372
401
    def test_shelve_kind_change(self):
373
 
        self.thisFailsStrictLockCheck()
374
402
        tree = self.create_shelvable_tree()
375
403
        os.unlink('tree/foo')
376
404
        os.mkdir('tree/foo')
 
405
        tree.lock_tree_write()
 
406
        self.addCleanup(tree.unlock)
377
407
        shelver = ExpectShelver(tree, tree.basis_tree(),
378
408
                               reporter=shelf_ui.ApplyReporter())
379
409
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
380
410
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
381
411
 
382
412
    def test_shelve_modify_target(self):
383
 
        self.thisFailsStrictLockCheck()
384
413
        self.requireFeature(tests.SymlinkFeature)
385
414
        tree = self.create_shelvable_tree()
386
415
        os.symlink('bar', 'tree/baz')
388
417
        tree.commit("Add symlink")
389
418
        os.unlink('tree/baz')
390
419
        os.symlink('vax', 'tree/baz')
 
420
        tree.lock_tree_write()
 
421
        self.addCleanup(tree.unlock)
391
422
        shelver = ExpectShelver(tree, tree.basis_tree(),
392
423
                                reporter=shelf_ui.ApplyReporter())
393
424
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
401
432
 
402
433
    def create_tree_with_shelf(self):
403
434
        tree = self.make_branch_and_tree('tree')
404
 
        self.build_tree_contents([('tree/foo', LINES_AJ)])
405
 
        tree.add('foo', 'foo-id')
406
 
        tree.commit('added foo')
407
 
        self.build_tree_contents([('tree/foo', LINES_ZY)])
408
 
        shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
409
 
                         auto=True).run()
 
435
        tree.lock_write()
 
436
        try:
 
437
            self.build_tree_contents([('tree/foo', LINES_AJ)])
 
438
            tree.add('foo', 'foo-id')
 
439
            tree.commit('added foo')
 
440
            self.build_tree_contents([('tree/foo', LINES_ZY)])
 
441
            shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
 
442
                             auto=True).run()
 
443
        finally:
 
444
            tree.unlock()
410
445
        return tree
411
446
 
412
447
    def test_unshelve(self):
413
 
        self.thisFailsStrictLockCheck()
414
448
        tree = self.create_tree_with_shelf()
415
449
        tree.lock_write()
416
450
        self.addCleanup(tree.unlock)
419
453
        self.assertFileEqual(LINES_ZY, 'tree/foo')
420
454
 
421
455
    def test_unshelve_args(self):
422
 
        self.thisFailsStrictLockCheck()
423
456
        tree = self.create_tree_with_shelf()
424
 
        shelf_ui.Unshelver.from_args(directory='tree').run()
 
457
        unshelver = shelf_ui.Unshelver.from_args(directory='tree')
 
458
        try:
 
459
            unshelver.run()
 
460
        finally:
 
461
            unshelver.tree.unlock()
425
462
        self.assertFileEqual(LINES_ZY, 'tree/foo')
426
463
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
427
464
 
428
465
    def test_unshelve_args_dry_run(self):
429
 
        self.thisFailsStrictLockCheck()
430
466
        tree = self.create_tree_with_shelf()
431
 
        shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
 
467
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
 
468
            action='dry-run')
 
469
        try:
 
470
            unshelver.run()
 
471
        finally:
 
472
            unshelver.tree.unlock()
432
473
        self.assertFileEqual(LINES_AJ, 'tree/foo')
433
474
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
434
475
 
435
476
    def test_unshelve_args_delete_only(self):
436
 
        self.thisFailsStrictLockCheck()
437
477
        tree = self.make_branch_and_tree('tree')
438
478
        manager = tree.get_shelf_manager()
439
479
        shelf_file = manager.new_shelf()[1]
443
483
            shelf_file.close()
444
484
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
445
485
                                                 action='delete-only')
446
 
        unshelver.run()
 
486
        try:
 
487
            unshelver.run()
 
488
        finally:
 
489
            unshelver.tree.unlock()
447
490
        self.assertIs(None, manager.last_shelf())
448
491
 
449
492
    def test_unshelve_args_invalid_shelf_id(self):
450
 
        self.thisFailsStrictLockCheck()
451
493
        tree = self.make_branch_and_tree('tree')
452
494
        manager = tree.get_shelf_manager()
453
495
        shelf_file = manager.new_shelf()[1]