~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Patch Queue Manager
  • Date: 2011-10-14 13:19:35 UTC
  • mfrom: (6182.2.30 ui.confirm)
  • Revision ID: pqm@pqm.ubuntu.com-20111014131935-bcj8kpy7tr9b7rsy
(jelmer) improvements to the interactive text ui framework,
 and make shelf and break-lock use it (Benoit PIERRE)

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