~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-27 11:48:50 UTC
  • mto: This revision was merged to the branch mainline in revision 6173.
  • Revision ID: v.ladeuil+lp@free.fr-20110927114850-338r2mns0138klv0
Global options respect their hidden attribute

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        self.expected = []
45
45
        self.diff_writer = StringIO()
46
46
 
47
 
    def expect(self, message, response):
48
 
        self.expected.append((message, response))
 
47
    def expect(self, prompt, response):
 
48
        self.expected.append((prompt, response))
49
49
 
50
 
    def prompt(self, message, choices, default):
 
50
    def prompt(self, message):
51
51
        try:
52
 
            expected_message, response = self.expected.pop(0)
 
52
            prompt, response = self.expected.pop(0)
53
53
        except IndexError:
54
54
            raise AssertionError('Unexpected prompt: %s' % message)
55
 
        if message != expected_message:
 
55
        if prompt != message:
56
56
            raise AssertionError('Wrong prompt: %s' % message)
57
 
        if choices != '&yes\n&No\n&finish\n&quit':
58
 
            raise AssertionError('Wrong choices: %s' % choices)
59
57
        return response
60
58
 
61
59
 
88
86
        shelver = ExpectShelver(tree, tree.basis_tree())
89
87
        self.addCleanup(shelver.finalize)
90
88
        e = self.assertRaises(AssertionError, shelver.run)
91
 
        self.assertEqual('Unexpected prompt: Shelve?', str(e))
 
89
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
92
90
 
93
91
    def test_wrong_prompt_failure(self):
94
92
        tree = self.create_shelvable_tree()
96
94
        self.addCleanup(tree.unlock)
97
95
        shelver = ExpectShelver(tree, tree.basis_tree())
98
96
        self.addCleanup(shelver.finalize)
99
 
        shelver.expect('foo', 0)
 
97
        shelver.expect('foo', 'y')
100
98
        e = self.assertRaises(AssertionError, shelver.run)
101
 
        self.assertEqual('Wrong prompt: Shelve?', str(e))
 
99
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
102
100
 
103
101
    def test_shelve_not_diff(self):
104
102
        tree = self.create_shelvable_tree()
106
104
        self.addCleanup(tree.unlock)
107
105
        shelver = ExpectShelver(tree, tree.basis_tree())
108
106
        self.addCleanup(shelver.finalize)
109
 
        shelver.expect('Shelve?', 1)
110
 
        shelver.expect('Shelve?', 1)
 
107
        shelver.expect('Shelve? [yNfq?]', 'n')
 
108
        shelver.expect('Shelve? [yNfq?]', 'n')
111
109
        # No final shelving prompt because no changes were selected
112
110
        shelver.run()
113
111
        self.assertFileEqual(LINES_ZY, 'tree/foo')
118
116
        self.addCleanup(tree.unlock)
119
117
        shelver = ExpectShelver(tree, tree.basis_tree())
120
118
        self.addCleanup(shelver.finalize)
121
 
        shelver.expect('Shelve?', 0)
122
 
        shelver.expect('Shelve?', 0)
123
 
        shelver.expect('Shelve 2 change(s)?', 1)
 
119
        shelver.expect('Shelve? [yNfq?]', 'y')
 
120
        shelver.expect('Shelve? [yNfq?]', 'y')
 
121
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n')
124
122
        shelver.run()
125
123
        self.assertFileEqual(LINES_ZY, 'tree/foo')
126
124
 
130
128
        self.addCleanup(tree.unlock)
131
129
        shelver = ExpectShelver(tree, tree.basis_tree())
132
130
        self.addCleanup(shelver.finalize)
133
 
        shelver.expect('Shelve?', 0)
134
 
        shelver.expect('Shelve?', 0)
135
 
        shelver.expect('Shelve 2 change(s)?', 0)
 
131
        shelver.expect('Shelve? [yNfq?]', 'y')
 
132
        shelver.expect('Shelve? [yNfq?]', 'y')
 
133
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
136
134
        shelver.run()
137
135
        self.assertFileEqual(LINES_AJ, 'tree/foo')
138
136
 
142
140
        self.addCleanup(tree.unlock)
143
141
        shelver = ExpectShelver(tree, tree.basis_tree())
144
142
        self.addCleanup(shelver.finalize)
145
 
        shelver.expect('Shelve?', 0)
146
 
        shelver.expect('Shelve?', 1)
147
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
143
        shelver.expect('Shelve? [yNfq?]', 'y')
 
144
        shelver.expect('Shelve? [yNfq?]', 'n')
 
145
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
148
146
        shelver.run()
149
147
        self.assertFileEqual(LINES_AY, 'tree/foo')
150
148
 
155
153
        self.addCleanup(tree.unlock)
156
154
        shelver = ExpectShelver(tree, tree.basis_tree())
157
155
        self.addCleanup(shelver.finalize)
158
 
        shelver.expect('Shelve binary changes?', 0)
159
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
156
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
 
157
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
160
158
        shelver.run()
161
159
        self.assertFileEqual(LINES_AJ, 'tree/foo')
162
160
 
167
165
        self.addCleanup(tree.unlock)
168
166
        shelver = ExpectShelver(tree, tree.basis_tree())
169
167
        self.addCleanup(shelver.finalize)
170
 
        shelver.expect('Shelve renaming "foo" => "bar"?', 0)
171
 
        shelver.expect('Shelve?', 0)
172
 
        shelver.expect('Shelve?', 0)
173
 
        shelver.expect('Shelve 3 change(s)?', 0)
 
168
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
 
169
        shelver.expect('Shelve? [yNfq?]', 'y')
 
170
        shelver.expect('Shelve? [yNfq?]', 'y')
 
171
        shelver.expect('Shelve 3 change(s)? [yNfq?]', 'y')
174
172
        shelver.run()
175
173
        self.assertFileEqual(LINES_AJ, 'tree/foo')
176
174
 
181
179
        self.addCleanup(tree.unlock)
182
180
        shelver = ExpectShelver(tree, tree.basis_tree())
183
181
        self.addCleanup(shelver.finalize)
184
 
        shelver.expect('Shelve removing file "foo"?', 0)
185
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
182
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
 
183
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
186
184
        shelver.run()
187
185
        self.assertFileEqual(LINES_AJ, 'tree/foo')
188
186
 
195
193
        self.addCleanup(tree.unlock)
196
194
        shelver = ExpectShelver(tree, tree.basis_tree())
197
195
        self.addCleanup(shelver.finalize)
198
 
        shelver.expect('Shelve adding file "foo"?', 0)
199
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
196
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
 
197
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
200
198
        shelver.run()
201
199
        self.assertPathDoesNotExist('tree/foo')
202
200
 
208
206
        self.addCleanup(tree.unlock)
209
207
        shelver = ExpectShelver(tree, tree.basis_tree())
210
208
        self.addCleanup(shelver.finalize)
211
 
        shelver.expect('Shelve changing "foo" from file to directory?',
212
 
                       0)
213
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
209
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
 
210
                       'y')
 
211
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
214
212
 
215
213
    def test_shelve_modify_target(self):
216
214
        self.requireFeature(features.SymlinkFeature)
225
223
        shelver = ExpectShelver(tree, tree.basis_tree())
226
224
        self.addCleanup(shelver.finalize)
227
225
        shelver.expect('Shelve changing target of "baz" from "bar" to '
228
 
                '"vax"?', 0)
229
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
226
                '"vax"? [yNfq?]', 'y')
 
227
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
230
228
        shelver.run()
231
229
        self.assertEqual('bar', os.readlink('tree/baz'))
232
230
 
236
234
        self.addCleanup(tree.unlock)
237
235
        shelver = ExpectShelver(tree, tree.basis_tree())
238
236
        self.addCleanup(shelver.finalize)
239
 
        shelver.expect('Shelve?', 2)
240
 
        shelver.expect('Shelve 2 change(s)?', 0)
 
237
        shelver.expect('Shelve? [yNfq?]', 'f')
 
238
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
241
239
        shelver.run()
242
240
        self.assertFileEqual(LINES_AJ, 'tree/foo')
243
241
 
247
245
        self.addCleanup(tree.unlock)
248
246
        shelver = ExpectShelver(tree, tree.basis_tree())
249
247
        self.addCleanup(shelver.finalize)
250
 
        shelver.expect('Shelve?', 3)
 
248
        shelver.expect('Shelve? [yNfq?]', 'q')
251
249
        self.assertRaises(errors.UserAbort, shelver.run)
252
250
        self.assertFileEqual(LINES_ZY, 'tree/foo')
253
251
 
269
267
        self.addCleanup(tree.unlock)
270
268
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
271
269
        self.addCleanup(shelver.finalize)
272
 
        shelver.expect('Shelve adding file "bar"?', 0)
273
 
        shelver.expect('Shelve 1 change(s)?', 0)
 
270
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
 
271
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
 
272
        shelver.run()
 
273
 
 
274
    def test_shelve_help(self):
 
275
        tree = self.create_shelvable_tree()
 
276
        tree.lock_tree_write()
 
277
        self.addCleanup(tree.unlock)
 
278
        shelver = ExpectShelver(tree, tree.basis_tree())
 
279
        self.addCleanup(shelver.finalize)
 
280
        shelver.expect('Shelve? [yNfq?]', '?')
 
281
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
 
282
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
274
283
        shelver.run()
275
284
 
276
285
    def test_shelve_destroy(self):
341
350
        shelver = ExpectShelver(tree, tree.basis_tree(),
342
351
                                reporter=shelf_ui.ApplyReporter())
343
352
        self.addCleanup(shelver.finalize)
344
 
        shelver.expect('Apply change?', 1)
345
 
        shelver.expect('Apply change?', 1)
 
353
        shelver.expect('Apply change? [yNfq?]', 'n')
 
354
        shelver.expect('Apply change? [yNfq?]', 'n')
346
355
        # No final shelving prompt because no changes were selected
347
356
        shelver.run()
348
357
        self.assertFileEqual(LINES_ZY, 'tree/foo')
354
363
        shelver = ExpectShelver(tree, tree.basis_tree(),
355
364
                                reporter=shelf_ui.ApplyReporter())
356
365
        self.addCleanup(shelver.finalize)
357
 
        shelver.expect('Apply change?', 0)
358
 
        shelver.expect('Apply change?', 0)
359
 
        shelver.expect('Apply 2 change(s)?', 1)
 
366
        shelver.expect('Apply change? [yNfq?]', 'y')
 
367
        shelver.expect('Apply change? [yNfq?]', 'y')
 
368
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
360
369
        shelver.run()
361
370
        self.assertFileEqual(LINES_ZY, 'tree/foo')
362
371
 
367
376
        shelver = ExpectShelver(tree, tree.basis_tree(),
368
377
                                reporter=shelf_ui.ApplyReporter())
369
378
        self.addCleanup(shelver.finalize)
370
 
        shelver.expect('Apply change?', 0)
371
 
        shelver.expect('Apply change?', 0)
372
 
        shelver.expect('Apply 2 change(s)?', 0)
 
379
        shelver.expect('Apply change? [yNfq?]', 'y')
 
380
        shelver.expect('Apply change? [yNfq?]', 'y')
 
381
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
373
382
        shelver.run()
374
383
        self.assertFileEqual(LINES_AJ, 'tree/foo')
375
384
 
381
390
        shelver = ExpectShelver(tree, tree.basis_tree(),
382
391
                                reporter=shelf_ui.ApplyReporter())
383
392
        self.addCleanup(shelver.finalize)
384
 
        shelver.expect('Apply binary changes?', 0)
385
 
        shelver.expect('Apply 1 change(s)?', 0)
 
393
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
 
394
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
386
395
        shelver.run()
387
396
        self.assertFileEqual(LINES_AJ, 'tree/foo')
388
397
 
394
403
        shelver = ExpectShelver(tree, tree.basis_tree(),
395
404
                                reporter=shelf_ui.ApplyReporter())
396
405
        self.addCleanup(shelver.finalize)
397
 
        shelver.expect('Rename "bar" => "foo"?', 0)
398
 
        shelver.expect('Apply change?', 0)
399
 
        shelver.expect('Apply change?', 0)
400
 
        shelver.expect('Apply 3 change(s)?', 0)
 
406
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
 
407
        shelver.expect('Apply change? [yNfq?]', 'y')
 
408
        shelver.expect('Apply change? [yNfq?]', 'y')
 
409
        shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
401
410
        shelver.run()
402
411
        self.assertFileEqual(LINES_AJ, 'tree/foo')
403
412
 
409
418
        shelver = ExpectShelver(tree, tree.basis_tree(),
410
419
                                reporter=shelf_ui.ApplyReporter())
411
420
        self.addCleanup(shelver.finalize)
412
 
        shelver.expect('Add file "foo"?', 0)
413
 
        shelver.expect('Apply 1 change(s)?', 0)
 
421
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
 
422
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
414
423
        shelver.run()
415
424
        self.assertFileEqual(LINES_AJ, 'tree/foo')
416
425
 
424
433
        shelver = ExpectShelver(tree, tree.basis_tree(),
425
434
                                reporter=shelf_ui.ApplyReporter())
426
435
        self.addCleanup(shelver.finalize)
427
 
        shelver.expect('Delete file "foo"?', 0)
428
 
        shelver.expect('Apply 1 change(s)?', 0)
 
436
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
 
437
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
429
438
        shelver.run()
430
439
        self.assertPathDoesNotExist('tree/foo')
431
440
 
438
447
        shelver = ExpectShelver(tree, tree.basis_tree(),
439
448
                               reporter=shelf_ui.ApplyReporter())
440
449
        self.addCleanup(shelver.finalize)
441
 
        shelver.expect('Change "foo" from directory to a file?', 0)
442
 
        shelver.expect('Apply 1 change(s)?', 0)
 
450
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
 
451
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
443
452
 
444
453
    def test_shelve_modify_target(self):
445
454
        self.requireFeature(features.SymlinkFeature)
454
463
        shelver = ExpectShelver(tree, tree.basis_tree(),
455
464
                                reporter=shelf_ui.ApplyReporter())
456
465
        self.addCleanup(shelver.finalize)
457
 
        shelver.expect('Change target of "baz" from "vax" to "bar"?',
458
 
                       0)
459
 
        shelver.expect('Apply 1 change(s)?', 0)
 
466
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
 
467
                       'y')
 
468
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
460
469
        shelver.run()
461
470
        self.assertEqual('bar', os.readlink('tree/baz'))
462
471