66
78
self.build_tree_contents([('tree/foo', LINES_ZY)])
82
class TestShelver(ShelfTestCase):
69
84
def test_unexpected_prompt_failure(self):
70
self.thisFailsStrictLockCheck()
71
85
tree = self.create_shelvable_tree()
86
tree.lock_tree_write()
87
self.addCleanup(tree.unlock)
72
88
shelver = ExpectShelver(tree, tree.basis_tree())
89
self.addCleanup(shelver.finalize)
73
90
e = self.assertRaises(AssertionError, shelver.run)
74
self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
91
self.assertEqual('Unexpected prompt: Shelve?', str(e))
76
93
def test_wrong_prompt_failure(self):
77
self.thisFailsStrictLockCheck()
78
94
tree = self.create_shelvable_tree()
95
tree.lock_tree_write()
96
self.addCleanup(tree.unlock)
79
97
shelver = ExpectShelver(tree, tree.basis_tree())
80
shelver.expect('foo', 'y')
98
self.addCleanup(shelver.finalize)
99
shelver.expect('foo', 0)
81
100
e = self.assertRaises(AssertionError, shelver.run)
82
self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
101
self.assertEqual('Wrong prompt: Shelve?', str(e))
84
103
def test_shelve_not_diff(self):
85
self.thisFailsStrictLockCheck()
86
104
tree = self.create_shelvable_tree()
105
tree.lock_tree_write()
106
self.addCleanup(tree.unlock)
87
107
shelver = ExpectShelver(tree, tree.basis_tree())
88
shelver.expect('Shelve? [yNfq?]', 'n')
89
shelver.expect('Shelve? [yNfq?]', 'n')
108
self.addCleanup(shelver.finalize)
109
shelver.expect('Shelve?', 1)
110
shelver.expect('Shelve?', 1)
90
111
# No final shelving prompt because no changes were selected
92
113
self.assertFileEqual(LINES_ZY, 'tree/foo')
94
115
def test_shelve_diff_no(self):
95
self.thisFailsStrictLockCheck()
96
116
tree = self.create_shelvable_tree()
117
tree.lock_tree_write()
118
self.addCleanup(tree.unlock)
97
119
shelver = ExpectShelver(tree, tree.basis_tree())
98
shelver.expect('Shelve? [yNfq?]', 'y')
99
shelver.expect('Shelve? [yNfq?]', 'y')
100
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n')
120
self.addCleanup(shelver.finalize)
121
shelver.expect('Shelve?', 0)
122
shelver.expect('Shelve?', 0)
123
shelver.expect('Shelve 2 change(s)?', 1)
102
125
self.assertFileEqual(LINES_ZY, 'tree/foo')
104
127
def test_shelve_diff(self):
105
self.thisFailsStrictLockCheck()
106
128
tree = self.create_shelvable_tree()
129
tree.lock_tree_write()
130
self.addCleanup(tree.unlock)
107
131
shelver = ExpectShelver(tree, tree.basis_tree())
108
shelver.expect('Shelve? [yNfq?]', 'y')
109
shelver.expect('Shelve? [yNfq?]', 'y')
110
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
132
self.addCleanup(shelver.finalize)
133
shelver.expect('Shelve?', 0)
134
shelver.expect('Shelve?', 0)
135
shelver.expect('Shelve 2 change(s)?', 0)
112
137
self.assertFileEqual(LINES_AJ, 'tree/foo')
114
139
def test_shelve_one_diff(self):
115
self.thisFailsStrictLockCheck()
116
140
tree = self.create_shelvable_tree()
141
tree.lock_tree_write()
142
self.addCleanup(tree.unlock)
117
143
shelver = ExpectShelver(tree, tree.basis_tree())
118
shelver.expect('Shelve? [yNfq?]', 'y')
119
shelver.expect('Shelve? [yNfq?]', 'n')
120
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
144
self.addCleanup(shelver.finalize)
145
shelver.expect('Shelve?', 0)
146
shelver.expect('Shelve?', 1)
147
shelver.expect('Shelve 1 change(s)?', 0)
122
149
self.assertFileEqual(LINES_AY, 'tree/foo')
124
151
def test_shelve_binary_change(self):
125
self.thisFailsStrictLockCheck()
126
152
tree = self.create_shelvable_tree()
127
153
self.build_tree_contents([('tree/foo', '\x00')])
154
tree.lock_tree_write()
155
self.addCleanup(tree.unlock)
128
156
shelver = ExpectShelver(tree, tree.basis_tree())
129
shelver.expect('Shelve binary changes? [yNfq?]', 'y')
130
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
157
self.addCleanup(shelver.finalize)
158
shelver.expect('Shelve binary changes?', 0)
159
shelver.expect('Shelve 1 change(s)?', 0)
132
161
self.assertFileEqual(LINES_AJ, 'tree/foo')
134
163
def test_shelve_rename(self):
135
self.thisFailsStrictLockCheck()
136
164
tree = self.create_shelvable_tree()
137
165
tree.rename_one('foo', 'bar')
166
tree.lock_tree_write()
167
self.addCleanup(tree.unlock)
138
168
shelver = ExpectShelver(tree, tree.basis_tree())
139
shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
140
shelver.expect('Shelve? [yNfq?]', 'y')
141
shelver.expect('Shelve? [yNfq?]', 'y')
142
shelver.expect('Shelve 3 change(s)? [yNfq?]', 'y')
169
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)
144
175
self.assertFileEqual(LINES_AJ, 'tree/foo')
146
177
def test_shelve_deletion(self):
147
self.thisFailsStrictLockCheck()
148
178
tree = self.create_shelvable_tree()
149
179
os.unlink('tree/foo')
180
tree.lock_tree_write()
181
self.addCleanup(tree.unlock)
150
182
shelver = ExpectShelver(tree, tree.basis_tree())
151
shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
152
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
183
self.addCleanup(shelver.finalize)
184
shelver.expect('Shelve removing file "foo"?', 0)
185
shelver.expect('Shelve 1 change(s)?', 0)
154
187
self.assertFileEqual(LINES_AJ, 'tree/foo')
156
189
def test_shelve_creation(self):
157
self.thisFailsStrictLockCheck()
158
190
tree = self.make_branch_and_tree('tree')
159
191
tree.commit('add tree root')
160
192
self.build_tree(['tree/foo'])
194
tree.lock_tree_write()
195
self.addCleanup(tree.unlock)
162
196
shelver = ExpectShelver(tree, tree.basis_tree())
163
shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
164
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
197
self.addCleanup(shelver.finalize)
198
shelver.expect('Shelve adding file "foo"?', 0)
199
shelver.expect('Shelve 1 change(s)?', 0)
166
self.failIfExists('tree/foo')
201
self.assertPathDoesNotExist('tree/foo')
168
203
def test_shelve_kind_change(self):
169
self.thisFailsStrictLockCheck()
170
204
tree = self.create_shelvable_tree()
171
205
os.unlink('tree/foo')
172
206
os.mkdir('tree/foo')
207
tree.lock_tree_write()
208
self.addCleanup(tree.unlock)
173
209
shelver = ExpectShelver(tree, tree.basis_tree())
174
shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
176
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
210
self.addCleanup(shelver.finalize)
211
shelver.expect('Shelve changing "foo" from file to directory?',
213
shelver.expect('Shelve 1 change(s)?', 0)
178
215
def test_shelve_modify_target(self):
179
self.thisFailsStrictLockCheck()
180
self.requireFeature(tests.SymlinkFeature)
216
self.requireFeature(features.SymlinkFeature)
181
217
tree = self.create_shelvable_tree()
182
218
os.symlink('bar', 'tree/baz')
183
219
tree.add('baz', 'baz-id')
184
220
tree.commit("Add symlink")
185
221
os.unlink('tree/baz')
186
222
os.symlink('vax', 'tree/baz')
223
tree.lock_tree_write()
224
self.addCleanup(tree.unlock)
187
225
shelver = ExpectShelver(tree, tree.basis_tree())
226
self.addCleanup(shelver.finalize)
188
227
shelver.expect('Shelve changing target of "baz" from "bar" to '
189
'"vax"? [yNfq?]', 'y')
190
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
229
shelver.expect('Shelve 1 change(s)?', 0)
192
231
self.assertEqual('bar', os.readlink('tree/baz'))
194
233
def test_shelve_finish(self):
195
self.thisFailsStrictLockCheck()
196
234
tree = self.create_shelvable_tree()
235
tree.lock_tree_write()
236
self.addCleanup(tree.unlock)
197
237
shelver = ExpectShelver(tree, tree.basis_tree())
198
shelver.expect('Shelve? [yNfq?]', 'f')
199
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
238
self.addCleanup(shelver.finalize)
239
shelver.expect('Shelve?', 2)
240
shelver.expect('Shelve 2 change(s)?', 0)
201
242
self.assertFileEqual(LINES_AJ, 'tree/foo')
203
244
def test_shelve_quit(self):
204
self.thisFailsStrictLockCheck()
205
245
tree = self.create_shelvable_tree()
246
tree.lock_tree_write()
247
self.addCleanup(tree.unlock)
206
248
shelver = ExpectShelver(tree, tree.basis_tree())
207
shelver.expect('Shelve? [yNfq?]', 'q')
249
self.addCleanup(shelver.finalize)
250
shelver.expect('Shelve?', 3)
208
251
self.assertRaises(errors.UserAbort, shelver.run)
209
252
self.assertFileEqual(LINES_ZY, 'tree/foo')
211
254
def test_shelve_all(self):
212
self.thisFailsStrictLockCheck()
213
255
tree = self.create_shelvable_tree()
214
ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
256
shelver = ExpectShelver.from_args(sys.stdout, all=True,
215
262
self.assertFileEqual(LINES_AJ, 'tree/foo')
217
264
def test_shelve_filename(self):
218
self.thisFailsStrictLockCheck()
219
265
tree = self.create_shelvable_tree()
220
266
self.build_tree(['tree/bar'])
268
tree.lock_tree_write()
269
self.addCleanup(tree.unlock)
222
270
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
223
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
224
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
227
def test_shelve_help(self):
228
self.thisFailsStrictLockCheck()
229
tree = self.create_shelvable_tree()
230
shelver = ExpectShelver(tree, tree.basis_tree())
231
shelver.expect('Shelve? [yNfq?]', '?')
232
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
233
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
236
def test_shelve_distroy(self):
237
self.thisFailsStrictLockCheck()
271
self.addCleanup(shelver.finalize)
272
shelver.expect('Shelve adding file "bar"?', 0)
273
shelver.expect('Shelve 1 change(s)?', 0)
276
def test_shelve_destroy(self):
238
277
tree = self.create_shelvable_tree()
239
278
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
240
279
directory='tree', destroy=True)
280
self.addCleanup(shelver.finalize)
242
282
self.assertIs(None, tree.get_shelf_manager().last_shelf())
243
283
self.assertFileEqual(LINES_AJ, 'tree/foo')
246
class TestApplyReporter(TestShelver):
286
def shelve_all(tree, target_revision_id):
289
target = tree.branch.repository.revision_tree(target_revision_id)
290
shelver = shelf_ui.Shelver(tree, target, auto=True,
299
def test_shelve_old_root_preserved(self):
300
tree1 = self.make_branch_and_tree('tree1')
301
tree1.commit('add root')
302
tree1_root_id = tree1.get_root_id()
303
tree2 = self.make_branch_and_tree('tree2')
304
rev2 = tree2.commit('add root')
305
self.assertNotEquals(tree1_root_id, tree2.get_root_id())
306
tree1.merge_from_branch(tree2.branch,
307
from_revision=revision.NULL_REVISION)
308
tree1.commit('merging in tree2')
309
self.assertEquals(tree1_root_id, tree1.get_root_id())
310
# This is essentially assertNotRaises(InconsistentDelta)
311
# With testtools 0.9.9, it can be rewritten as:
312
# with ExpectedException(AssertionError,
313
# 'InconsistentDelta not raised'):
314
# with ExpectedException(errors.InconsistentDelta, ''):
315
# self.shelve_all(tree1, rev2)
316
e = self.assertRaises(AssertionError, self.assertRaises,
317
errors.InconsistentDelta, self.shelve_all, tree1,
319
self.assertContainsRe('InconsistentDelta not raised', str(e))
321
def test_shelve_split(self):
322
outer_tree = self.make_branch_and_tree('outer')
323
outer_tree.commit('Add root')
324
inner_tree = self.make_branch_and_tree('outer/inner')
325
rev2 = inner_tree.commit('Add root')
326
outer_tree.subsume(inner_tree)
327
# This is essentially assertNotRaises(ValueError).
328
# The ValueError is 'None is not a valid file id'.
329
self.expectFailure('Cannot shelve a join back to the inner tree.',
330
self.assertRaises, AssertionError,
331
self.assertRaises, ValueError, self.shelve_all,
335
class TestApplyReporter(ShelfTestCase):
248
337
def test_shelve_not_diff(self):
249
self.thisFailsStrictLockCheck()
250
338
tree = self.create_shelvable_tree()
339
tree.lock_tree_write()
340
self.addCleanup(tree.unlock)
251
341
shelver = ExpectShelver(tree, tree.basis_tree(),
252
342
reporter=shelf_ui.ApplyReporter())
253
shelver.expect('Apply change? [yNfq?]', 'n')
254
shelver.expect('Apply change? [yNfq?]', 'n')
343
self.addCleanup(shelver.finalize)
344
shelver.expect('Apply change?', 1)
345
shelver.expect('Apply change?', 1)
255
346
# No final shelving prompt because no changes were selected
257
348
self.assertFileEqual(LINES_ZY, 'tree/foo')
259
350
def test_shelve_diff_no(self):
260
self.thisFailsStrictLockCheck()
261
351
tree = self.create_shelvable_tree()
352
tree.lock_tree_write()
353
self.addCleanup(tree.unlock)
262
354
shelver = ExpectShelver(tree, tree.basis_tree(),
263
355
reporter=shelf_ui.ApplyReporter())
264
shelver.expect('Apply change? [yNfq?]', 'y')
265
shelver.expect('Apply change? [yNfq?]', 'y')
266
shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
356
self.addCleanup(shelver.finalize)
357
shelver.expect('Apply change?', 0)
358
shelver.expect('Apply change?', 0)
359
shelver.expect('Apply 2 change(s)?', 1)
268
361
self.assertFileEqual(LINES_ZY, 'tree/foo')
270
363
def test_shelve_diff(self):
271
self.thisFailsStrictLockCheck()
272
364
tree = self.create_shelvable_tree()
365
tree.lock_tree_write()
366
self.addCleanup(tree.unlock)
273
367
shelver = ExpectShelver(tree, tree.basis_tree(),
274
368
reporter=shelf_ui.ApplyReporter())
275
shelver.expect('Apply change? [yNfq?]', 'y')
276
shelver.expect('Apply change? [yNfq?]', 'y')
277
shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
369
self.addCleanup(shelver.finalize)
370
shelver.expect('Apply change?', 0)
371
shelver.expect('Apply change?', 0)
372
shelver.expect('Apply 2 change(s)?', 0)
279
374
self.assertFileEqual(LINES_AJ, 'tree/foo')
281
376
def test_shelve_binary_change(self):
282
self.thisFailsStrictLockCheck()
283
377
tree = self.create_shelvable_tree()
284
378
self.build_tree_contents([('tree/foo', '\x00')])
379
tree.lock_tree_write()
380
self.addCleanup(tree.unlock)
285
381
shelver = ExpectShelver(tree, tree.basis_tree(),
286
382
reporter=shelf_ui.ApplyReporter())
287
shelver.expect('Apply binary changes? [yNfq?]', 'y')
288
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
383
self.addCleanup(shelver.finalize)
384
shelver.expect('Apply binary changes?', 0)
385
shelver.expect('Apply 1 change(s)?', 0)
290
387
self.assertFileEqual(LINES_AJ, 'tree/foo')
292
389
def test_shelve_rename(self):
293
self.thisFailsStrictLockCheck()
294
390
tree = self.create_shelvable_tree()
295
391
tree.rename_one('foo', 'bar')
392
tree.lock_tree_write()
393
self.addCleanup(tree.unlock)
296
394
shelver = ExpectShelver(tree, tree.basis_tree(),
297
395
reporter=shelf_ui.ApplyReporter())
298
shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
299
shelver.expect('Apply change? [yNfq?]', 'y')
300
shelver.expect('Apply change? [yNfq?]', 'y')
301
shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
396
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)
303
402
self.assertFileEqual(LINES_AJ, 'tree/foo')
305
404
def test_shelve_deletion(self):
306
self.thisFailsStrictLockCheck()
307
405
tree = self.create_shelvable_tree()
308
406
os.unlink('tree/foo')
407
tree.lock_tree_write()
408
self.addCleanup(tree.unlock)
309
409
shelver = ExpectShelver(tree, tree.basis_tree(),
310
410
reporter=shelf_ui.ApplyReporter())
311
shelver.expect('Add file "foo"? [yNfq?]', 'y')
312
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
411
self.addCleanup(shelver.finalize)
412
shelver.expect('Add file "foo"?', 0)
413
shelver.expect('Apply 1 change(s)?', 0)
314
415
self.assertFileEqual(LINES_AJ, 'tree/foo')
316
417
def test_shelve_creation(self):
317
self.thisFailsStrictLockCheck()
318
418
tree = self.make_branch_and_tree('tree')
319
419
tree.commit('add tree root')
320
420
self.build_tree(['tree/foo'])
422
tree.lock_tree_write()
423
self.addCleanup(tree.unlock)
322
424
shelver = ExpectShelver(tree, tree.basis_tree(),
323
425
reporter=shelf_ui.ApplyReporter())
324
shelver.expect('Delete file "foo"? [yNfq?]', 'y')
325
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
426
self.addCleanup(shelver.finalize)
427
shelver.expect('Delete file "foo"?', 0)
428
shelver.expect('Apply 1 change(s)?', 0)
327
self.failIfExists('tree/foo')
430
self.assertPathDoesNotExist('tree/foo')
329
432
def test_shelve_kind_change(self):
330
self.thisFailsStrictLockCheck()
331
433
tree = self.create_shelvable_tree()
332
434
os.unlink('tree/foo')
333
435
os.mkdir('tree/foo')
436
tree.lock_tree_write()
437
self.addCleanup(tree.unlock)
334
438
shelver = ExpectShelver(tree, tree.basis_tree(),
335
439
reporter=shelf_ui.ApplyReporter())
336
shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
337
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
440
self.addCleanup(shelver.finalize)
441
shelver.expect('Change "foo" from directory to a file?', 0)
442
shelver.expect('Apply 1 change(s)?', 0)
339
444
def test_shelve_modify_target(self):
340
self.thisFailsStrictLockCheck()
341
self.requireFeature(tests.SymlinkFeature)
445
self.requireFeature(features.SymlinkFeature)
342
446
tree = self.create_shelvable_tree()
343
447
os.symlink('bar', 'tree/baz')
344
448
tree.add('baz', 'baz-id')
345
449
tree.commit("Add symlink")
346
450
os.unlink('tree/baz')
347
451
os.symlink('vax', 'tree/baz')
452
tree.lock_tree_write()
453
self.addCleanup(tree.unlock)
348
454
shelver = ExpectShelver(tree, tree.basis_tree(),
349
455
reporter=shelf_ui.ApplyReporter())
350
shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
352
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
456
self.addCleanup(shelver.finalize)
457
shelver.expect('Change target of "baz" from "vax" to "bar"?',
459
shelver.expect('Apply 1 change(s)?', 0)
354
461
self.assertEqual('bar', os.readlink('tree/baz'))