~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2011, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
    tests,
28
28
)
29
29
from bzrlib.tests import script
 
30
from bzrlib.tests import (
 
31
    features,
 
32
    )
30
33
 
31
34
 
32
35
class ExpectShelver(shelf_ui.Shelver):
41
44
        self.expected = []
42
45
        self.diff_writer = StringIO()
43
46
 
44
 
    def expect(self, prompt, response):
45
 
        self.expected.append((prompt, response))
 
47
    def expect(self, message, response):
 
48
        self.expected.append((message, response))
46
49
 
47
 
    def prompt(self, message):
 
50
    def prompt(self, message, choices, default):
48
51
        try:
49
 
            prompt, response = self.expected.pop(0)
 
52
            expected_message, response = self.expected.pop(0)
50
53
        except IndexError:
51
54
            raise AssertionError('Unexpected prompt: %s' % message)
52
 
        if prompt != message:
 
55
        if message != expected_message:
53
56
            raise AssertionError('Wrong prompt: %s' % message)
 
57
        if choices != '&yes\n&No\n&finish\n&quit':
 
58
            raise AssertionError('Wrong choices: %s' % choices)
54
59
        return response
55
60
 
56
61
 
83
88
        shelver = ExpectShelver(tree, tree.basis_tree())
84
89
        self.addCleanup(shelver.finalize)
85
90
        e = self.assertRaises(AssertionError, shelver.run)
86
 
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
 
91
        self.assertEqual('Unexpected prompt: Shelve?', str(e))
87
92
 
88
93
    def test_wrong_prompt_failure(self):
89
94
        tree = self.create_shelvable_tree()
91
96
        self.addCleanup(tree.unlock)
92
97
        shelver = ExpectShelver(tree, tree.basis_tree())
93
98
        self.addCleanup(shelver.finalize)
94
 
        shelver.expect('foo', 'y')
 
99
        shelver.expect('foo', 0)
95
100
        e = self.assertRaises(AssertionError, shelver.run)
96
 
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
 
101
        self.assertEqual('Wrong prompt: Shelve?', str(e))
97
102
 
98
103
    def test_shelve_not_diff(self):
99
104
        tree = self.create_shelvable_tree()
101
106
        self.addCleanup(tree.unlock)
102
107
        shelver = ExpectShelver(tree, tree.basis_tree())
103
108
        self.addCleanup(shelver.finalize)
104
 
        shelver.expect('Shelve? [yNfq?]', 'n')
105
 
        shelver.expect('Shelve? [yNfq?]', 'n')
 
109
        shelver.expect('Shelve?', 1)
 
110
        shelver.expect('Shelve?', 1)
106
111
        # No final shelving prompt because no changes were selected
107
112
        shelver.run()
108
113
        self.assertFileEqual(LINES_ZY, 'tree/foo')
113
118
        self.addCleanup(tree.unlock)
114
119
        shelver = ExpectShelver(tree, tree.basis_tree())
115
120
        self.addCleanup(shelver.finalize)
116
 
        shelver.expect('Shelve? [yNfq?]', 'y')
117
 
        shelver.expect('Shelve? [yNfq?]', 'y')
118
 
        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)
119
124
        shelver.run()
120
125
        self.assertFileEqual(LINES_ZY, 'tree/foo')
121
126
 
125
130
        self.addCleanup(tree.unlock)
126
131
        shelver = ExpectShelver(tree, tree.basis_tree())
127
132
        self.addCleanup(shelver.finalize)
128
 
        shelver.expect('Shelve? [yNfq?]', 'y')
129
 
        shelver.expect('Shelve? [yNfq?]', 'y')
130
 
        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)
131
136
        shelver.run()
132
137
        self.assertFileEqual(LINES_AJ, 'tree/foo')
133
138
 
137
142
        self.addCleanup(tree.unlock)
138
143
        shelver = ExpectShelver(tree, tree.basis_tree())
139
144
        self.addCleanup(shelver.finalize)
140
 
        shelver.expect('Shelve? [yNfq?]', 'y')
141
 
        shelver.expect('Shelve? [yNfq?]', 'n')
142
 
        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)
143
148
        shelver.run()
144
149
        self.assertFileEqual(LINES_AY, 'tree/foo')
145
150
 
150
155
        self.addCleanup(tree.unlock)
151
156
        shelver = ExpectShelver(tree, tree.basis_tree())
152
157
        self.addCleanup(shelver.finalize)
153
 
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
154
 
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
 
158
        shelver.expect('Shelve binary changes?', 0)
 
159
        shelver.expect('Shelve 1 change(s)?', 0)
155
160
        shelver.run()
156
161
        self.assertFileEqual(LINES_AJ, 'tree/foo')
157
162
 
162
167
        self.addCleanup(tree.unlock)
163
168
        shelver = ExpectShelver(tree, tree.basis_tree())
164
169
        self.addCleanup(shelver.finalize)
165
 
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
166
 
        shelver.expect('Shelve? [yNfq?]', 'y')
167
 
        shelver.expect('Shelve? [yNfq?]', 'y')
168
 
        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)
169
174
        shelver.run()
170
175
        self.assertFileEqual(LINES_AJ, 'tree/foo')
171
176
 
176
181
        self.addCleanup(tree.unlock)
177
182
        shelver = ExpectShelver(tree, tree.basis_tree())
178
183
        self.addCleanup(shelver.finalize)
179
 
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
180
 
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
 
184
        shelver.expect('Shelve removing file "foo"?', 0)
 
185
        shelver.expect('Shelve 1 change(s)?', 0)
181
186
        shelver.run()
182
187
        self.assertFileEqual(LINES_AJ, 'tree/foo')
183
188
 
190
195
        self.addCleanup(tree.unlock)
191
196
        shelver = ExpectShelver(tree, tree.basis_tree())
192
197
        self.addCleanup(shelver.finalize)
193
 
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
194
 
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
 
198
        shelver.expect('Shelve adding file "foo"?', 0)
 
199
        shelver.expect('Shelve 1 change(s)?', 0)
195
200
        shelver.run()
196
201
        self.assertPathDoesNotExist('tree/foo')
197
202
 
203
208
        self.addCleanup(tree.unlock)
204
209
        shelver = ExpectShelver(tree, tree.basis_tree())
205
210
        self.addCleanup(shelver.finalize)
206
 
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
207
 
                       'y')
208
 
        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)
209
214
 
210
215
    def test_shelve_modify_target(self):
211
 
        self.requireFeature(tests.SymlinkFeature)
 
216
        self.requireFeature(features.SymlinkFeature)
212
217
        tree = self.create_shelvable_tree()
213
218
        os.symlink('bar', 'tree/baz')
214
219
        tree.add('baz', 'baz-id')
220
225
        shelver = ExpectShelver(tree, tree.basis_tree())
221
226
        self.addCleanup(shelver.finalize)
222
227
        shelver.expect('Shelve changing target of "baz" from "bar" to '
223
 
                '"vax"? [yNfq?]', 'y')
224
 
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
 
228
                '"vax"?', 0)
 
229
        shelver.expect('Shelve 1 change(s)?', 0)
225
230
        shelver.run()
226
231
        self.assertEqual('bar', os.readlink('tree/baz'))
227
232
 
231
236
        self.addCleanup(tree.unlock)
232
237
        shelver = ExpectShelver(tree, tree.basis_tree())
233
238
        self.addCleanup(shelver.finalize)
234
 
        shelver.expect('Shelve? [yNfq?]', 'f')
235
 
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
 
239
        shelver.expect('Shelve?', 2)
 
240
        shelver.expect('Shelve 2 change(s)?', 0)
236
241
        shelver.run()
237
242
        self.assertFileEqual(LINES_AJ, 'tree/foo')
238
243
 
242
247
        self.addCleanup(tree.unlock)
243
248
        shelver = ExpectShelver(tree, tree.basis_tree())
244
249
        self.addCleanup(shelver.finalize)
245
 
        shelver.expect('Shelve? [yNfq?]', 'q')
 
250
        shelver.expect('Shelve?', 3)
246
251
        self.assertRaises(errors.UserAbort, shelver.run)
247
252
        self.assertFileEqual(LINES_ZY, 'tree/foo')
248
253
 
264
269
        self.addCleanup(tree.unlock)
265
270
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
266
271
        self.addCleanup(shelver.finalize)
267
 
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
268
 
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
269
 
        shelver.run()
270
 
 
271
 
    def test_shelve_help(self):
272
 
        tree = self.create_shelvable_tree()
273
 
        tree.lock_tree_write()
274
 
        self.addCleanup(tree.unlock)
275
 
        shelver = ExpectShelver(tree, tree.basis_tree())
276
 
        self.addCleanup(shelver.finalize)
277
 
        shelver.expect('Shelve? [yNfq?]', '?')
278
 
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
279
 
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
 
272
        shelver.expect('Shelve adding file "bar"?', 0)
 
273
        shelver.expect('Shelve 1 change(s)?', 0)
280
274
        shelver.run()
281
275
 
282
276
    def test_shelve_destroy(self):
308
302
        tree1_root_id = tree1.get_root_id()
309
303
        tree2 = self.make_branch_and_tree('tree2')
310
304
        rev2 = tree2.commit('add root')
311
 
        self.assertNotEquals(tree1_root_id, tree2.get_root_id())
 
305
        self.assertNotEqual(tree1_root_id, tree2.get_root_id())
312
306
        tree1.merge_from_branch(tree2.branch,
313
307
                                from_revision=revision.NULL_REVISION)
314
308
        tree1.commit('merging in tree2')
315
 
        self.assertEquals(tree1_root_id, tree1.get_root_id())
 
309
        self.assertEqual(tree1_root_id, tree1.get_root_id())
316
310
        # This is essentially assertNotRaises(InconsistentDelta)
317
311
        # With testtools 0.9.9, it can be rewritten as:
318
312
        # with ExpectedException(AssertionError,
347
341
        shelver = ExpectShelver(tree, tree.basis_tree(),
348
342
                                reporter=shelf_ui.ApplyReporter())
349
343
        self.addCleanup(shelver.finalize)
350
 
        shelver.expect('Apply change? [yNfq?]', 'n')
351
 
        shelver.expect('Apply change? [yNfq?]', 'n')
 
344
        shelver.expect('Apply change?', 1)
 
345
        shelver.expect('Apply change?', 1)
352
346
        # No final shelving prompt because no changes were selected
353
347
        shelver.run()
354
348
        self.assertFileEqual(LINES_ZY, 'tree/foo')
360
354
        shelver = ExpectShelver(tree, tree.basis_tree(),
361
355
                                reporter=shelf_ui.ApplyReporter())
362
356
        self.addCleanup(shelver.finalize)
363
 
        shelver.expect('Apply change? [yNfq?]', 'y')
364
 
        shelver.expect('Apply change? [yNfq?]', 'y')
365
 
        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)
366
360
        shelver.run()
367
361
        self.assertFileEqual(LINES_ZY, 'tree/foo')
368
362
 
373
367
        shelver = ExpectShelver(tree, tree.basis_tree(),
374
368
                                reporter=shelf_ui.ApplyReporter())
375
369
        self.addCleanup(shelver.finalize)
376
 
        shelver.expect('Apply change? [yNfq?]', 'y')
377
 
        shelver.expect('Apply change? [yNfq?]', 'y')
378
 
        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)
379
373
        shelver.run()
380
374
        self.assertFileEqual(LINES_AJ, 'tree/foo')
381
375
 
387
381
        shelver = ExpectShelver(tree, tree.basis_tree(),
388
382
                                reporter=shelf_ui.ApplyReporter())
389
383
        self.addCleanup(shelver.finalize)
390
 
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
391
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
 
384
        shelver.expect('Apply binary changes?', 0)
 
385
        shelver.expect('Apply 1 change(s)?', 0)
392
386
        shelver.run()
393
387
        self.assertFileEqual(LINES_AJ, 'tree/foo')
394
388
 
400
394
        shelver = ExpectShelver(tree, tree.basis_tree(),
401
395
                                reporter=shelf_ui.ApplyReporter())
402
396
        self.addCleanup(shelver.finalize)
403
 
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
404
 
        shelver.expect('Apply change? [yNfq?]', 'y')
405
 
        shelver.expect('Apply change? [yNfq?]', 'y')
406
 
        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)
407
401
        shelver.run()
408
402
        self.assertFileEqual(LINES_AJ, 'tree/foo')
409
403
 
415
409
        shelver = ExpectShelver(tree, tree.basis_tree(),
416
410
                                reporter=shelf_ui.ApplyReporter())
417
411
        self.addCleanup(shelver.finalize)
418
 
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
419
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
 
412
        shelver.expect('Add file "foo"?', 0)
 
413
        shelver.expect('Apply 1 change(s)?', 0)
420
414
        shelver.run()
421
415
        self.assertFileEqual(LINES_AJ, 'tree/foo')
422
416
 
430
424
        shelver = ExpectShelver(tree, tree.basis_tree(),
431
425
                                reporter=shelf_ui.ApplyReporter())
432
426
        self.addCleanup(shelver.finalize)
433
 
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
434
 
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
 
427
        shelver.expect('Delete file "foo"?', 0)
 
428
        shelver.expect('Apply 1 change(s)?', 0)
435
429
        shelver.run()
436
430
        self.assertPathDoesNotExist('tree/foo')
437
431
 
444
438
        shelver = ExpectShelver(tree, tree.basis_tree(),
445
439
                               reporter=shelf_ui.ApplyReporter())
446
440
        self.addCleanup(shelver.finalize)
447
 
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
448
 
        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)
449
443
 
450
444
    def test_shelve_modify_target(self):
451
 
        self.requireFeature(tests.SymlinkFeature)
 
445
        self.requireFeature(features.SymlinkFeature)
452
446
        tree = self.create_shelvable_tree()
453
447
        os.symlink('bar', 'tree/baz')
454
448
        tree.add('baz', 'baz-id')
460
454
        shelver = ExpectShelver(tree, tree.basis_tree(),
461
455
                                reporter=shelf_ui.ApplyReporter())
462
456
        self.addCleanup(shelver.finalize)
463
 
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
464
 
                       'y')
465
 
        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)
466
460
        shelver.run()
467
461
        self.assertEqual('bar', os.readlink('tree/baz'))
468
462