~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_shelf_ui.py

  • Committer: Alexander Belchenko
  • Date: 2009-08-27 07:30:31 UTC
  • mto: (4595.14.1 1.18)
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: bialix@ukr.net-20090827073031-dgm9i4kx8610p8tq
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006)

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 
69
69
    def test_unexpected_prompt_failure(self):
70
70
        tree = self.create_shelvable_tree()
 
71
        tree.lock_tree_write()
 
72
        self.addCleanup(tree.unlock)
71
73
        shelver = ExpectShelver(tree, tree.basis_tree())
72
74
        e = self.assertRaises(AssertionError, shelver.run)
73
75
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
74
76
 
75
77
    def test_wrong_prompt_failure(self):
76
78
        tree = self.create_shelvable_tree()
 
79
        tree.lock_tree_write()
 
80
        self.addCleanup(tree.unlock)
77
81
        shelver = ExpectShelver(tree, tree.basis_tree())
78
82
        shelver.expect('foo', 'y')
79
83
        e = self.assertRaises(AssertionError, shelver.run)
81
85
 
82
86
    def test_shelve_not_diff(self):
83
87
        tree = self.create_shelvable_tree()
 
88
        tree.lock_tree_write()
 
89
        self.addCleanup(tree.unlock)
84
90
        shelver = ExpectShelver(tree, tree.basis_tree())
85
91
        shelver.expect('Shelve? [yNfq?]', 'n')
86
92
        shelver.expect('Shelve? [yNfq?]', 'n')
90
96
 
91
97
    def test_shelve_diff_no(self):
92
98
        tree = self.create_shelvable_tree()
 
99
        tree.lock_tree_write()
 
100
        self.addCleanup(tree.unlock)
93
101
        shelver = ExpectShelver(tree, tree.basis_tree())
94
102
        shelver.expect('Shelve? [yNfq?]', 'y')
95
103
        shelver.expect('Shelve? [yNfq?]', 'y')
99
107
 
100
108
    def test_shelve_diff(self):
101
109
        tree = self.create_shelvable_tree()
 
110
        tree.lock_tree_write()
 
111
        self.addCleanup(tree.unlock)
102
112
        shelver = ExpectShelver(tree, tree.basis_tree())
103
113
        shelver.expect('Shelve? [yNfq?]', 'y')
104
114
        shelver.expect('Shelve? [yNfq?]', 'y')
108
118
 
109
119
    def test_shelve_one_diff(self):
110
120
        tree = self.create_shelvable_tree()
 
121
        tree.lock_tree_write()
 
122
        self.addCleanup(tree.unlock)
111
123
        shelver = ExpectShelver(tree, tree.basis_tree())
112
124
        shelver.expect('Shelve? [yNfq?]', 'y')
113
125
        shelver.expect('Shelve? [yNfq?]', 'n')
118
130
    def test_shelve_binary_change(self):
119
131
        tree = self.create_shelvable_tree()
120
132
        self.build_tree_contents([('tree/foo', '\x00')])
 
133
        tree.lock_tree_write()
 
134
        self.addCleanup(tree.unlock)
121
135
        shelver = ExpectShelver(tree, tree.basis_tree())
122
136
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
123
137
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
127
141
    def test_shelve_rename(self):
128
142
        tree = self.create_shelvable_tree()
129
143
        tree.rename_one('foo', 'bar')
 
144
        tree.lock_tree_write()
 
145
        self.addCleanup(tree.unlock)
130
146
        shelver = ExpectShelver(tree, tree.basis_tree())
131
147
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
132
148
        shelver.expect('Shelve? [yNfq?]', 'y')
138
154
    def test_shelve_deletion(self):
139
155
        tree = self.create_shelvable_tree()
140
156
        os.unlink('tree/foo')
 
157
        tree.lock_tree_write()
 
158
        self.addCleanup(tree.unlock)
141
159
        shelver = ExpectShelver(tree, tree.basis_tree())
142
160
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
143
161
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
149
167
        tree.commit('add tree root')
150
168
        self.build_tree(['tree/foo'])
151
169
        tree.add('foo')
 
170
        tree.lock_tree_write()
 
171
        self.addCleanup(tree.unlock)
152
172
        shelver = ExpectShelver(tree, tree.basis_tree())
153
173
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
154
174
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
159
179
        tree = self.create_shelvable_tree()
160
180
        os.unlink('tree/foo')
161
181
        os.mkdir('tree/foo')
 
182
        tree.lock_tree_write()
 
183
        self.addCleanup(tree.unlock)
162
184
        shelver = ExpectShelver(tree, tree.basis_tree())
163
185
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
164
186
                       'y')
172
194
        tree.commit("Add symlink")
173
195
        os.unlink('tree/baz')
174
196
        os.symlink('vax', 'tree/baz')
 
197
        tree.lock_tree_write()
 
198
        self.addCleanup(tree.unlock)
175
199
        shelver = ExpectShelver(tree, tree.basis_tree())
176
200
        shelver.expect('Shelve changing target of "baz" from "bar" to '
177
201
                '"vax"? [yNfq?]', 'y')
181
205
 
182
206
    def test_shelve_finish(self):
183
207
        tree = self.create_shelvable_tree()
 
208
        tree.lock_tree_write()
 
209
        self.addCleanup(tree.unlock)
184
210
        shelver = ExpectShelver(tree, tree.basis_tree())
185
211
        shelver.expect('Shelve? [yNfq?]', 'f')
186
212
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
189
215
 
190
216
    def test_shelve_quit(self):
191
217
        tree = self.create_shelvable_tree()
 
218
        tree.lock_tree_write()
 
219
        self.addCleanup(tree.unlock)
192
220
        shelver = ExpectShelver(tree, tree.basis_tree())
193
221
        shelver.expect('Shelve? [yNfq?]', 'q')
194
222
        self.assertRaises(errors.UserAbort, shelver.run)
196
224
 
197
225
    def test_shelve_all(self):
198
226
        tree = self.create_shelvable_tree()
199
 
        ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
 
227
        shelver = ExpectShelver.from_args(sys.stdout, all=True,
 
228
            directory='tree')
 
229
        try:
 
230
            shelver.run()
 
231
        finally:
 
232
            shelver.work_tree.unlock()
200
233
        self.assertFileEqual(LINES_AJ, 'tree/foo')
201
234
 
202
235
    def test_shelve_filename(self):
203
236
        tree = self.create_shelvable_tree()
204
237
        self.build_tree(['tree/bar'])
205
238
        tree.add('bar')
 
239
        tree.lock_tree_write()
 
240
        self.addCleanup(tree.unlock)
206
241
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
207
242
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
208
243
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
210
245
 
211
246
    def test_shelve_help(self):
212
247
        tree = self.create_shelvable_tree()
 
248
        tree.lock_tree_write()
 
249
        self.addCleanup(tree.unlock)
213
250
        shelver = ExpectShelver(tree, tree.basis_tree())
214
251
        shelver.expect('Shelve? [yNfq?]', '?')
215
252
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
220
257
        tree = self.create_shelvable_tree()
221
258
        shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
222
259
                                             directory='tree', destroy=True)
223
 
        shelver.run()
 
260
        try:
 
261
            shelver.run()
 
262
        finally:
 
263
            shelver.work_tree.unlock()
224
264
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
225
265
        self.assertFileEqual(LINES_AJ, 'tree/foo')
226
266
 
229
269
 
230
270
    def test_shelve_not_diff(self):
231
271
        tree = self.create_shelvable_tree()
 
272
        tree.lock_tree_write()
 
273
        self.addCleanup(tree.unlock)
232
274
        shelver = ExpectShelver(tree, tree.basis_tree(),
233
275
                                reporter=shelf_ui.ApplyReporter())
234
276
        shelver.expect('Apply change? [yNfq?]', 'n')
239
281
 
240
282
    def test_shelve_diff_no(self):
241
283
        tree = self.create_shelvable_tree()
 
284
        tree.lock_tree_write()
 
285
        self.addCleanup(tree.unlock)
242
286
        shelver = ExpectShelver(tree, tree.basis_tree(),
243
287
                                reporter=shelf_ui.ApplyReporter())
244
288
        shelver.expect('Apply change? [yNfq?]', 'y')
249
293
 
250
294
    def test_shelve_diff(self):
251
295
        tree = self.create_shelvable_tree()
 
296
        tree.lock_tree_write()
 
297
        self.addCleanup(tree.unlock)
252
298
        shelver = ExpectShelver(tree, tree.basis_tree(),
253
299
                                reporter=shelf_ui.ApplyReporter())
254
300
        shelver.expect('Apply change? [yNfq?]', 'y')
260
306
    def test_shelve_binary_change(self):
261
307
        tree = self.create_shelvable_tree()
262
308
        self.build_tree_contents([('tree/foo', '\x00')])
 
309
        tree.lock_tree_write()
 
310
        self.addCleanup(tree.unlock)
263
311
        shelver = ExpectShelver(tree, tree.basis_tree(),
264
312
                                reporter=shelf_ui.ApplyReporter())
265
313
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
270
318
    def test_shelve_rename(self):
271
319
        tree = self.create_shelvable_tree()
272
320
        tree.rename_one('foo', 'bar')
 
321
        tree.lock_tree_write()
 
322
        self.addCleanup(tree.unlock)
273
323
        shelver = ExpectShelver(tree, tree.basis_tree(),
274
324
                                reporter=shelf_ui.ApplyReporter())
275
325
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
282
332
    def test_shelve_deletion(self):
283
333
        tree = self.create_shelvable_tree()
284
334
        os.unlink('tree/foo')
 
335
        tree.lock_tree_write()
 
336
        self.addCleanup(tree.unlock)
285
337
        shelver = ExpectShelver(tree, tree.basis_tree(),
286
338
                                reporter=shelf_ui.ApplyReporter())
287
339
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
294
346
        tree.commit('add tree root')
295
347
        self.build_tree(['tree/foo'])
296
348
        tree.add('foo')
 
349
        tree.lock_tree_write()
 
350
        self.addCleanup(tree.unlock)
297
351
        shelver = ExpectShelver(tree, tree.basis_tree(),
298
352
                                reporter=shelf_ui.ApplyReporter())
299
353
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
305
359
        tree = self.create_shelvable_tree()
306
360
        os.unlink('tree/foo')
307
361
        os.mkdir('tree/foo')
 
362
        tree.lock_tree_write()
 
363
        self.addCleanup(tree.unlock)
308
364
        shelver = ExpectShelver(tree, tree.basis_tree(),
309
365
                               reporter=shelf_ui.ApplyReporter())
310
366
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
318
374
        tree.commit("Add symlink")
319
375
        os.unlink('tree/baz')
320
376
        os.symlink('vax', 'tree/baz')
 
377
        tree.lock_tree_write()
 
378
        self.addCleanup(tree.unlock)
321
379
        shelver = ExpectShelver(tree, tree.basis_tree(),
322
380
                                reporter=shelf_ui.ApplyReporter())
323
381
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
331
389
 
332
390
    def create_tree_with_shelf(self):
333
391
        tree = self.make_branch_and_tree('tree')
334
 
        self.build_tree_contents([('tree/foo', LINES_AJ)])
335
 
        tree.add('foo', 'foo-id')
336
 
        tree.commit('added foo')
337
 
        self.build_tree_contents([('tree/foo', LINES_ZY)])
338
 
        shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
339
 
                         auto=True).run()
 
392
        tree.lock_write()
 
393
        try:
 
394
            self.build_tree_contents([('tree/foo', LINES_AJ)])
 
395
            tree.add('foo', 'foo-id')
 
396
            tree.commit('added foo')
 
397
            self.build_tree_contents([('tree/foo', LINES_ZY)])
 
398
            shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
 
399
                             auto=True).run()
 
400
        finally:
 
401
            tree.unlock()
340
402
        return tree
341
403
 
342
404
    def test_unshelve(self):
349
411
 
350
412
    def test_unshelve_args(self):
351
413
        tree = self.create_tree_with_shelf()
352
 
        shelf_ui.Unshelver.from_args(directory='tree').run()
 
414
        unshelver = shelf_ui.Unshelver.from_args(directory='tree')
 
415
        try:
 
416
            unshelver.run()
 
417
        finally:
 
418
            unshelver.tree.unlock()
353
419
        self.assertFileEqual(LINES_ZY, 'tree/foo')
354
420
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
355
421
 
356
422
    def test_unshelve_args_dry_run(self):
357
423
        tree = self.create_tree_with_shelf()
358
 
        shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
 
424
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
 
425
            action='dry-run')
 
426
        try:
 
427
            unshelver.run()
 
428
        finally:
 
429
            unshelver.tree.unlock()
359
430
        self.assertFileEqual(LINES_AJ, 'tree/foo')
360
431
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
361
432
 
369
440
            shelf_file.close()
370
441
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
371
442
                                                 action='delete-only')
372
 
        unshelver.run()
 
443
        try:
 
444
            unshelver.run()
 
445
        finally:
 
446
            unshelver.tree.unlock()
373
447
        self.assertIs(None, manager.last_shelf())
374
448
 
375
449
    def test_unshelve_args_invalid_shelf_id(self):