~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Benoît Pierre
  • Date: 2011-10-10 20:55:52 UTC
  • mto: This revision was merged to the branch mainline in revision 6215.
  • Revision ID: benoit.pierre@gmail.com-20111010205552-7o6qoaiihy31hhxb
Avoid prompt duplication for shelf_ui tests.

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, choices, response):
48
 
        self.expected.append((message, choices, response))
 
47
    def expect(self, message, response):
 
48
        self.expected.append((message, response))
49
49
 
50
50
    def prompt(self, message, choices, default):
51
51
        try:
52
 
            expected_message, expected_choices, 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
55
        if message != expected_message:
56
56
            raise AssertionError('Wrong prompt: %s' % message)
57
 
        if choices != expected_choices:
 
57
        if choices != '&yes\n&No\n&finish\n&quit':
58
58
            raise AssertionError('Wrong choices: %s' % choices)
59
59
        return response
60
60
 
96
96
        self.addCleanup(tree.unlock)
97
97
        shelver = ExpectShelver(tree, tree.basis_tree())
98
98
        self.addCleanup(shelver.finalize)
99
 
        shelver.expect('foo', 'bar', 0)
 
99
        shelver.expect('foo', 0)
100
100
        e = self.assertRaises(AssertionError, shelver.run)
101
101
        self.assertEqual('Wrong prompt: Shelve?', str(e))
102
102
 
106
106
        self.addCleanup(tree.unlock)
107
107
        shelver = ExpectShelver(tree, tree.basis_tree())
108
108
        self.addCleanup(shelver.finalize)
109
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 1)
110
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 1)
 
109
        shelver.expect('Shelve?', 1)
 
110
        shelver.expect('Shelve?', 1)
111
111
        # No final shelving prompt because no changes were selected
112
112
        shelver.run()
113
113
        self.assertFileEqual(LINES_ZY, 'tree/foo')
118
118
        self.addCleanup(tree.unlock)
119
119
        shelver = ExpectShelver(tree, tree.basis_tree())
120
120
        self.addCleanup(shelver.finalize)
121
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
122
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
123
 
        shelver.expect('Shelve 2 change(s)?', '&yes\n&No\n&finish\n&quit', 1)
 
121
        shelver.expect('Shelve?', 0)
 
122
        shelver.expect('Shelve?', 0)
 
123
        shelver.expect('Shelve 2 change(s)?', 1)
124
124
        shelver.run()
125
125
        self.assertFileEqual(LINES_ZY, 'tree/foo')
126
126
 
130
130
        self.addCleanup(tree.unlock)
131
131
        shelver = ExpectShelver(tree, tree.basis_tree())
132
132
        self.addCleanup(shelver.finalize)
133
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
134
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
135
 
        shelver.expect('Shelve 2 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
133
        shelver.expect('Shelve?', 0)
 
134
        shelver.expect('Shelve?', 0)
 
135
        shelver.expect('Shelve 2 change(s)?', 0)
136
136
        shelver.run()
137
137
        self.assertFileEqual(LINES_AJ, 'tree/foo')
138
138
 
142
142
        self.addCleanup(tree.unlock)
143
143
        shelver = ExpectShelver(tree, tree.basis_tree())
144
144
        self.addCleanup(shelver.finalize)
145
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
146
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 1)
147
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
145
        shelver.expect('Shelve?', 0)
 
146
        shelver.expect('Shelve?', 1)
 
147
        shelver.expect('Shelve 1 change(s)?', 0)
148
148
        shelver.run()
149
149
        self.assertFileEqual(LINES_AY, 'tree/foo')
150
150
 
155
155
        self.addCleanup(tree.unlock)
156
156
        shelver = ExpectShelver(tree, tree.basis_tree())
157
157
        self.addCleanup(shelver.finalize)
158
 
        shelver.expect('Shelve binary changes?', '&yes\n&No\n&finish\n&quit', 0)
159
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
158
        shelver.expect('Shelve binary changes?', 0)
 
159
        shelver.expect('Shelve 1 change(s)?', 0)
160
160
        shelver.run()
161
161
        self.assertFileEqual(LINES_AJ, 'tree/foo')
162
162
 
167
167
        self.addCleanup(tree.unlock)
168
168
        shelver = ExpectShelver(tree, tree.basis_tree())
169
169
        self.addCleanup(shelver.finalize)
170
 
        shelver.expect('Shelve renaming "foo" => "bar"?', '&yes\n&No\n&finish\n&quit', 0)
171
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
172
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 0)
173
 
        shelver.expect('Shelve 3 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
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)
174
174
        shelver.run()
175
175
        self.assertFileEqual(LINES_AJ, 'tree/foo')
176
176
 
181
181
        self.addCleanup(tree.unlock)
182
182
        shelver = ExpectShelver(tree, tree.basis_tree())
183
183
        self.addCleanup(shelver.finalize)
184
 
        shelver.expect('Shelve removing file "foo"?', '&yes\n&No\n&finish\n&quit', 0)
185
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
184
        shelver.expect('Shelve removing file "foo"?', 0)
 
185
        shelver.expect('Shelve 1 change(s)?', 0)
186
186
        shelver.run()
187
187
        self.assertFileEqual(LINES_AJ, 'tree/foo')
188
188
 
195
195
        self.addCleanup(tree.unlock)
196
196
        shelver = ExpectShelver(tree, tree.basis_tree())
197
197
        self.addCleanup(shelver.finalize)
198
 
        shelver.expect('Shelve adding file "foo"?', '&yes\n&No\n&finish\n&quit', 0)
199
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
198
        shelver.expect('Shelve adding file "foo"?', 0)
 
199
        shelver.expect('Shelve 1 change(s)?', 0)
200
200
        shelver.run()
201
201
        self.assertPathDoesNotExist('tree/foo')
202
202
 
208
208
        self.addCleanup(tree.unlock)
209
209
        shelver = ExpectShelver(tree, tree.basis_tree())
210
210
        self.addCleanup(shelver.finalize)
211
 
        shelver.expect('Shelve changing "foo" from file to directory?', '&yes\n&No\n&finish\n&quit',
 
211
        shelver.expect('Shelve changing "foo" from file to directory?',
212
212
                       0)
213
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
213
        shelver.expect('Shelve 1 change(s)?', 0)
214
214
 
215
215
    def test_shelve_modify_target(self):
216
216
        self.requireFeature(features.SymlinkFeature)
225
225
        shelver = ExpectShelver(tree, tree.basis_tree())
226
226
        self.addCleanup(shelver.finalize)
227
227
        shelver.expect('Shelve changing target of "baz" from "bar" to '
228
 
                '"vax"?', '&yes\n&No\n&finish\n&quit', 0)
229
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
228
                '"vax"?', 0)
 
229
        shelver.expect('Shelve 1 change(s)?', 0)
230
230
        shelver.run()
231
231
        self.assertEqual('bar', os.readlink('tree/baz'))
232
232
 
236
236
        self.addCleanup(tree.unlock)
237
237
        shelver = ExpectShelver(tree, tree.basis_tree())
238
238
        self.addCleanup(shelver.finalize)
239
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 2)
240
 
        shelver.expect('Shelve 2 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
239
        shelver.expect('Shelve?', 2)
 
240
        shelver.expect('Shelve 2 change(s)?', 0)
241
241
        shelver.run()
242
242
        self.assertFileEqual(LINES_AJ, 'tree/foo')
243
243
 
247
247
        self.addCleanup(tree.unlock)
248
248
        shelver = ExpectShelver(tree, tree.basis_tree())
249
249
        self.addCleanup(shelver.finalize)
250
 
        shelver.expect('Shelve?', '&yes\n&No\n&finish\n&quit', 3)
 
250
        shelver.expect('Shelve?', 3)
251
251
        self.assertRaises(errors.UserAbort, shelver.run)
252
252
        self.assertFileEqual(LINES_ZY, 'tree/foo')
253
253
 
269
269
        self.addCleanup(tree.unlock)
270
270
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
271
271
        self.addCleanup(shelver.finalize)
272
 
        shelver.expect('Shelve adding file "bar"?', '&yes\n&No\n&finish\n&quit', 0)
273
 
        shelver.expect('Shelve 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
272
        shelver.expect('Shelve adding file "bar"?', 0)
 
273
        shelver.expect('Shelve 1 change(s)?', 0)
274
274
        shelver.run()
275
275
 
276
276
    def test_shelve_destroy(self):
341
341
        shelver = ExpectShelver(tree, tree.basis_tree(),
342
342
                                reporter=shelf_ui.ApplyReporter())
343
343
        self.addCleanup(shelver.finalize)
344
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 1)
345
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 1)
 
344
        shelver.expect('Apply change?', 1)
 
345
        shelver.expect('Apply change?', 1)
346
346
        # No final shelving prompt because no changes were selected
347
347
        shelver.run()
348
348
        self.assertFileEqual(LINES_ZY, 'tree/foo')
354
354
        shelver = ExpectShelver(tree, tree.basis_tree(),
355
355
                                reporter=shelf_ui.ApplyReporter())
356
356
        self.addCleanup(shelver.finalize)
357
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 0)
358
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 0)
359
 
        shelver.expect('Apply 2 change(s)?', '&yes\n&No\n&finish\n&quit', 1)
 
357
        shelver.expect('Apply change?', 0)
 
358
        shelver.expect('Apply change?', 0)
 
359
        shelver.expect('Apply 2 change(s)?', 1)
360
360
        shelver.run()
361
361
        self.assertFileEqual(LINES_ZY, 'tree/foo')
362
362
 
367
367
        shelver = ExpectShelver(tree, tree.basis_tree(),
368
368
                                reporter=shelf_ui.ApplyReporter())
369
369
        self.addCleanup(shelver.finalize)
370
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 0)
371
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 0)
372
 
        shelver.expect('Apply 2 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
370
        shelver.expect('Apply change?', 0)
 
371
        shelver.expect('Apply change?', 0)
 
372
        shelver.expect('Apply 2 change(s)?', 0)
373
373
        shelver.run()
374
374
        self.assertFileEqual(LINES_AJ, 'tree/foo')
375
375
 
381
381
        shelver = ExpectShelver(tree, tree.basis_tree(),
382
382
                                reporter=shelf_ui.ApplyReporter())
383
383
        self.addCleanup(shelver.finalize)
384
 
        shelver.expect('Apply binary changes?', '&yes\n&No\n&finish\n&quit', 0)
385
 
        shelver.expect('Apply 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
384
        shelver.expect('Apply binary changes?', 0)
 
385
        shelver.expect('Apply 1 change(s)?', 0)
386
386
        shelver.run()
387
387
        self.assertFileEqual(LINES_AJ, 'tree/foo')
388
388
 
394
394
        shelver = ExpectShelver(tree, tree.basis_tree(),
395
395
                                reporter=shelf_ui.ApplyReporter())
396
396
        self.addCleanup(shelver.finalize)
397
 
        shelver.expect('Rename "bar" => "foo"?', '&yes\n&No\n&finish\n&quit', 0)
398
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 0)
399
 
        shelver.expect('Apply change?', '&yes\n&No\n&finish\n&quit', 0)
400
 
        shelver.expect('Apply 3 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
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)
401
401
        shelver.run()
402
402
        self.assertFileEqual(LINES_AJ, 'tree/foo')
403
403
 
409
409
        shelver = ExpectShelver(tree, tree.basis_tree(),
410
410
                                reporter=shelf_ui.ApplyReporter())
411
411
        self.addCleanup(shelver.finalize)
412
 
        shelver.expect('Add file "foo"?', '&yes\n&No\n&finish\n&quit', 0)
413
 
        shelver.expect('Apply 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
412
        shelver.expect('Add file "foo"?', 0)
 
413
        shelver.expect('Apply 1 change(s)?', 0)
414
414
        shelver.run()
415
415
        self.assertFileEqual(LINES_AJ, 'tree/foo')
416
416
 
424
424
        shelver = ExpectShelver(tree, tree.basis_tree(),
425
425
                                reporter=shelf_ui.ApplyReporter())
426
426
        self.addCleanup(shelver.finalize)
427
 
        shelver.expect('Delete file "foo"?', '&yes\n&No\n&finish\n&quit', 0)
428
 
        shelver.expect('Apply 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
427
        shelver.expect('Delete file "foo"?', 0)
 
428
        shelver.expect('Apply 1 change(s)?', 0)
429
429
        shelver.run()
430
430
        self.assertPathDoesNotExist('tree/foo')
431
431
 
438
438
        shelver = ExpectShelver(tree, tree.basis_tree(),
439
439
                               reporter=shelf_ui.ApplyReporter())
440
440
        self.addCleanup(shelver.finalize)
441
 
        shelver.expect('Change "foo" from directory to a file?', '&yes\n&No\n&finish\n&quit', 0)
442
 
        shelver.expect('Apply 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
441
        shelver.expect('Change "foo" from directory to a file?', 0)
 
442
        shelver.expect('Apply 1 change(s)?', 0)
443
443
 
444
444
    def test_shelve_modify_target(self):
445
445
        self.requireFeature(features.SymlinkFeature)
454
454
        shelver = ExpectShelver(tree, tree.basis_tree(),
455
455
                                reporter=shelf_ui.ApplyReporter())
456
456
        self.addCleanup(shelver.finalize)
457
 
        shelver.expect('Change target of "baz" from "vax" to "bar"?', '&yes\n&No\n&finish\n&quit',
 
457
        shelver.expect('Change target of "baz" from "vax" to "bar"?',
458
458
                       0)
459
 
        shelver.expect('Apply 1 change(s)?', '&yes\n&No\n&finish\n&quit', 0)
 
459
        shelver.expect('Apply 1 change(s)?', 0)
460
460
        shelver.run()
461
461
        self.assertEqual('bar', os.readlink('tree/baz'))
462
462