/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Robert Collins
  • Date: 2009-08-25 19:29:41 UTC
  • mfrom: (4648 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4649.
  • Revision ID: robertc@robertcollins.net-20090825192941-x2kg9ikhsapjbs7b
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import sys
21
21
 
22
 
from bzrlib import errors, shelf_ui, tests
 
22
from bzrlib import (
 
23
    errors,
 
24
    shelf_ui,
 
25
    revision,
 
26
    tests,
 
27
)
23
28
 
24
29
 
25
30
class ExpectShelver(shelf_ui.Shelver):
67
72
        return tree
68
73
 
69
74
    def test_unexpected_prompt_failure(self):
 
75
        self.thisFailsStrictLockCheck()
70
76
        tree = self.create_shelvable_tree()
71
77
        shelver = ExpectShelver(tree, tree.basis_tree())
72
78
        e = self.assertRaises(AssertionError, shelver.run)
73
79
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
74
80
 
75
81
    def test_wrong_prompt_failure(self):
 
82
        self.thisFailsStrictLockCheck()
76
83
        tree = self.create_shelvable_tree()
77
84
        shelver = ExpectShelver(tree, tree.basis_tree())
78
85
        shelver.expect('foo', 'y')
80
87
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
81
88
 
82
89
    def test_shelve_not_diff(self):
 
90
        self.thisFailsStrictLockCheck()
83
91
        tree = self.create_shelvable_tree()
84
92
        shelver = ExpectShelver(tree, tree.basis_tree())
85
93
        shelver.expect('Shelve? [yNfq?]', 'n')
89
97
        self.assertFileEqual(LINES_ZY, 'tree/foo')
90
98
 
91
99
    def test_shelve_diff_no(self):
 
100
        self.thisFailsStrictLockCheck()
92
101
        tree = self.create_shelvable_tree()
93
102
        shelver = ExpectShelver(tree, tree.basis_tree())
94
103
        shelver.expect('Shelve? [yNfq?]', 'y')
98
107
        self.assertFileEqual(LINES_ZY, 'tree/foo')
99
108
 
100
109
    def test_shelve_diff(self):
 
110
        self.thisFailsStrictLockCheck()
101
111
        tree = self.create_shelvable_tree()
102
112
        shelver = ExpectShelver(tree, tree.basis_tree())
103
113
        shelver.expect('Shelve? [yNfq?]', 'y')
107
117
        self.assertFileEqual(LINES_AJ, 'tree/foo')
108
118
 
109
119
    def test_shelve_one_diff(self):
 
120
        self.thisFailsStrictLockCheck()
110
121
        tree = self.create_shelvable_tree()
111
122
        shelver = ExpectShelver(tree, tree.basis_tree())
112
123
        shelver.expect('Shelve? [yNfq?]', 'y')
116
127
        self.assertFileEqual(LINES_AY, 'tree/foo')
117
128
 
118
129
    def test_shelve_binary_change(self):
 
130
        self.thisFailsStrictLockCheck()
119
131
        tree = self.create_shelvable_tree()
120
132
        self.build_tree_contents([('tree/foo', '\x00')])
121
133
        shelver = ExpectShelver(tree, tree.basis_tree())
125
137
        self.assertFileEqual(LINES_AJ, 'tree/foo')
126
138
 
127
139
    def test_shelve_rename(self):
 
140
        self.thisFailsStrictLockCheck()
128
141
        tree = self.create_shelvable_tree()
129
142
        tree.rename_one('foo', 'bar')
130
143
        shelver = ExpectShelver(tree, tree.basis_tree())
136
149
        self.assertFileEqual(LINES_AJ, 'tree/foo')
137
150
 
138
151
    def test_shelve_deletion(self):
 
152
        self.thisFailsStrictLockCheck()
139
153
        tree = self.create_shelvable_tree()
140
154
        os.unlink('tree/foo')
141
155
        shelver = ExpectShelver(tree, tree.basis_tree())
145
159
        self.assertFileEqual(LINES_AJ, 'tree/foo')
146
160
 
147
161
    def test_shelve_creation(self):
 
162
        self.thisFailsStrictLockCheck()
148
163
        tree = self.make_branch_and_tree('tree')
149
164
        tree.commit('add tree root')
150
165
        self.build_tree(['tree/foo'])
156
171
        self.failIfExists('tree/foo')
157
172
 
158
173
    def test_shelve_kind_change(self):
 
174
        self.thisFailsStrictLockCheck()
159
175
        tree = self.create_shelvable_tree()
160
176
        os.unlink('tree/foo')
161
177
        os.mkdir('tree/foo')
165
181
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
166
182
 
167
183
    def test_shelve_modify_target(self):
 
184
        self.thisFailsStrictLockCheck()
168
185
        self.requireFeature(tests.SymlinkFeature)
169
186
        tree = self.create_shelvable_tree()
170
187
        os.symlink('bar', 'tree/baz')
180
197
        self.assertEqual('bar', os.readlink('tree/baz'))
181
198
 
182
199
    def test_shelve_finish(self):
 
200
        self.thisFailsStrictLockCheck()
183
201
        tree = self.create_shelvable_tree()
184
202
        shelver = ExpectShelver(tree, tree.basis_tree())
185
203
        shelver.expect('Shelve? [yNfq?]', 'f')
188
206
        self.assertFileEqual(LINES_AJ, 'tree/foo')
189
207
 
190
208
    def test_shelve_quit(self):
 
209
        self.thisFailsStrictLockCheck()
191
210
        tree = self.create_shelvable_tree()
192
211
        shelver = ExpectShelver(tree, tree.basis_tree())
193
212
        shelver.expect('Shelve? [yNfq?]', 'q')
195
214
        self.assertFileEqual(LINES_ZY, 'tree/foo')
196
215
 
197
216
    def test_shelve_all(self):
 
217
        self.thisFailsStrictLockCheck()
198
218
        tree = self.create_shelvable_tree()
199
219
        ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
200
220
        self.assertFileEqual(LINES_AJ, 'tree/foo')
201
221
 
202
222
    def test_shelve_filename(self):
 
223
        self.thisFailsStrictLockCheck()
203
224
        tree = self.create_shelvable_tree()
204
225
        self.build_tree(['tree/bar'])
205
226
        tree.add('bar')
209
230
        shelver.run()
210
231
 
211
232
    def test_shelve_help(self):
 
233
        self.thisFailsStrictLockCheck()
212
234
        tree = self.create_shelvable_tree()
213
235
        shelver = ExpectShelver(tree, tree.basis_tree())
214
236
        shelver.expect('Shelve? [yNfq?]', '?')
217
239
        shelver.run()
218
240
 
219
241
    def test_shelve_distroy(self):
 
242
        self.thisFailsStrictLockCheck()
220
243
        tree = self.create_shelvable_tree()
221
244
        shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
222
245
                                             directory='tree', destroy=True)
224
247
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
225
248
        self.assertFileEqual(LINES_AJ, 'tree/foo')
226
249
 
 
250
    @staticmethod
 
251
    def shelve_all(tree, target_revision_id):
 
252
        tree.lock_write()
 
253
        try:
 
254
            target = tree.branch.repository.revision_tree(target_revision_id)
 
255
            shelver = shelf_ui.Shelver(tree, target, auto=True,
 
256
                                       auto_apply=True)
 
257
            shelver.run()
 
258
        finally:
 
259
            tree.unlock()
 
260
 
 
261
    def test_shelve_old_root_deleted(self):
 
262
        tree1 = self.make_branch_and_tree('tree1')
 
263
        tree1.commit('add root')
 
264
        tree2 = self.make_branch_and_tree('tree2')
 
265
        rev2 = tree2.commit('add root')
 
266
        tree1.merge_from_branch(tree2.branch,
 
267
                                from_revision=revision.NULL_REVISION)
 
268
        tree1.commit('Replaced root entry')
 
269
        # This is essentially assertNotRaises(InconsistentDelta)
 
270
        self.expectFailure('Cannot shelve replacing a root entry',
 
271
                           self.assertRaises, AssertionError,
 
272
                           self.assertRaises, errors.InconsistentDelta,
 
273
                           self.shelve_all, tree1, rev2)
 
274
 
 
275
    def test_shelve_split(self):
 
276
        outer_tree = self.make_branch_and_tree('outer')
 
277
        outer_tree.commit('Add root')
 
278
        inner_tree = self.make_branch_and_tree('outer/inner')
 
279
        rev2 = inner_tree.commit('Add root')
 
280
        outer_tree.subsume(inner_tree)
 
281
        # This is essentially assertNotRaises(ValueError).
 
282
        # The ValueError is 'None is not a valid file id'.
 
283
        self.expectFailure('Cannot shelve a join back to the inner tree.',
 
284
                           self.assertRaises, AssertionError,
 
285
                           self.assertRaises, ValueError, self.shelve_all,
 
286
                           outer_tree, rev2)
 
287
 
227
288
 
228
289
class TestApplyReporter(TestShelver):
229
290
 
230
291
    def test_shelve_not_diff(self):
 
292
        self.thisFailsStrictLockCheck()
231
293
        tree = self.create_shelvable_tree()
232
294
        shelver = ExpectShelver(tree, tree.basis_tree(),
233
295
                                reporter=shelf_ui.ApplyReporter())
238
300
        self.assertFileEqual(LINES_ZY, 'tree/foo')
239
301
 
240
302
    def test_shelve_diff_no(self):
 
303
        self.thisFailsStrictLockCheck()
241
304
        tree = self.create_shelvable_tree()
242
305
        shelver = ExpectShelver(tree, tree.basis_tree(),
243
306
                                reporter=shelf_ui.ApplyReporter())
248
311
        self.assertFileEqual(LINES_ZY, 'tree/foo')
249
312
 
250
313
    def test_shelve_diff(self):
 
314
        self.thisFailsStrictLockCheck()
251
315
        tree = self.create_shelvable_tree()
252
316
        shelver = ExpectShelver(tree, tree.basis_tree(),
253
317
                                reporter=shelf_ui.ApplyReporter())
258
322
        self.assertFileEqual(LINES_AJ, 'tree/foo')
259
323
 
260
324
    def test_shelve_binary_change(self):
 
325
        self.thisFailsStrictLockCheck()
261
326
        tree = self.create_shelvable_tree()
262
327
        self.build_tree_contents([('tree/foo', '\x00')])
263
328
        shelver = ExpectShelver(tree, tree.basis_tree(),
268
333
        self.assertFileEqual(LINES_AJ, 'tree/foo')
269
334
 
270
335
    def test_shelve_rename(self):
 
336
        self.thisFailsStrictLockCheck()
271
337
        tree = self.create_shelvable_tree()
272
338
        tree.rename_one('foo', 'bar')
273
339
        shelver = ExpectShelver(tree, tree.basis_tree(),
280
346
        self.assertFileEqual(LINES_AJ, 'tree/foo')
281
347
 
282
348
    def test_shelve_deletion(self):
 
349
        self.thisFailsStrictLockCheck()
283
350
        tree = self.create_shelvable_tree()
284
351
        os.unlink('tree/foo')
285
352
        shelver = ExpectShelver(tree, tree.basis_tree(),
290
357
        self.assertFileEqual(LINES_AJ, 'tree/foo')
291
358
 
292
359
    def test_shelve_creation(self):
 
360
        self.thisFailsStrictLockCheck()
293
361
        tree = self.make_branch_and_tree('tree')
294
362
        tree.commit('add tree root')
295
363
        self.build_tree(['tree/foo'])
302
370
        self.failIfExists('tree/foo')
303
371
 
304
372
    def test_shelve_kind_change(self):
 
373
        self.thisFailsStrictLockCheck()
305
374
        tree = self.create_shelvable_tree()
306
375
        os.unlink('tree/foo')
307
376
        os.mkdir('tree/foo')
311
380
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
312
381
 
313
382
    def test_shelve_modify_target(self):
 
383
        self.thisFailsStrictLockCheck()
314
384
        self.requireFeature(tests.SymlinkFeature)
315
385
        tree = self.create_shelvable_tree()
316
386
        os.symlink('bar', 'tree/baz')
340
410
        return tree
341
411
 
342
412
    def test_unshelve(self):
 
413
        self.thisFailsStrictLockCheck()
343
414
        tree = self.create_tree_with_shelf()
344
415
        tree.lock_write()
345
416
        self.addCleanup(tree.unlock)
348
419
        self.assertFileEqual(LINES_ZY, 'tree/foo')
349
420
 
350
421
    def test_unshelve_args(self):
 
422
        self.thisFailsStrictLockCheck()
351
423
        tree = self.create_tree_with_shelf()
352
424
        shelf_ui.Unshelver.from_args(directory='tree').run()
353
425
        self.assertFileEqual(LINES_ZY, 'tree/foo')
354
426
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
355
427
 
356
428
    def test_unshelve_args_dry_run(self):
 
429
        self.thisFailsStrictLockCheck()
357
430
        tree = self.create_tree_with_shelf()
358
431
        shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
359
432
        self.assertFileEqual(LINES_AJ, 'tree/foo')
360
433
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
361
434
 
362
435
    def test_unshelve_args_delete_only(self):
 
436
        self.thisFailsStrictLockCheck()
363
437
        tree = self.make_branch_and_tree('tree')
364
438
        manager = tree.get_shelf_manager()
365
439
        shelf_file = manager.new_shelf()[1]
373
447
        self.assertIs(None, manager.last_shelf())
374
448
 
375
449
    def test_unshelve_args_invalid_shelf_id(self):
 
450
        self.thisFailsStrictLockCheck()
376
451
        tree = self.make_branch_and_tree('tree')
377
452
        manager = tree.get_shelf_manager()
378
453
        shelf_file = manager.new_shelf()[1]