~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-03-31 01:47:15 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20060331014715-127c9cda9bbc1e6f
Strip trailing / from input location

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from bzrlib.diff import _patch_header_date
 
1
#!/usr/bin/python
 
2
 
2
3
import bzrlib.tests
3
4
import os.path
4
5
 
5
6
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
6
7
    ORIGINAL = '\n\nhello test world\n\n'
7
8
    MODIFIED = '\n\ngoodbye test world\n\n'
8
 
    DIFF_HEADER = "=== modified file '%(filename)s'\n"
9
 
    DIFF_1 = """--- %(filename)s\t%(old_date)s
10
 
+++ %(filename)s\t%(new_date)s
 
9
    DIFF_HEADER = "=== modified file 'a/test_file'\n"
 
10
    DIFF_1 = """--- a/test_file\t
 
11
+++ b/test_file\t
11
12
@@ -1,4 +1,4 @@
12
13
 
13
14
 
15
16
+goodbye test world
16
17
 
17
18
"""
18
 
    DIFF_2 = """--- test_file\t%(old_date)s
19
 
+++ test_file\t%(new_date)s
 
19
    DIFF_2 = """--- a/test_file\t
 
20
+++ b/test_file\t
20
21
@@ -1,4 +1,4 @@
21
22
 
22
23
 
24
25
+hello test world
25
26
 
26
27
"""
27
 
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
28
 
        old_tree = self.tree.basis_tree()
29
 
        old_date = _patch_header_date(old_tree, 
30
 
                                      old_tree.inventory.path2id(filename),
31
 
                                      filename)
32
 
        new_date = _patch_header_date(self.tree, 
33
 
                                      self.tree.inventory.path2id(filename),
34
 
                                      filename)
35
 
        keys = { 'filename' : filename , 'old_date': old_date, 
36
 
                 'new_date': new_date}
37
 
        hdr  = self.DIFF_HEADER % keys
38
 
        diff = diff % keys
39
 
        self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n')
40
 
 
41
 
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
42
 
                     new_date=None):
43
 
        old_tree = self.tree.basis_tree()
44
 
        old_date = _patch_header_date(old_tree, 
45
 
                                      old_tree.inventory.path2id(filename),
46
 
                                      filename)
47
 
        diff = diff % { 'filename' : filename, 'old_date': old_date,
48
 
                        'new_date': new_date}
49
 
        shelf = open(os.path.join(self.tree.basedir,
50
 
                '.shelf/shelves/default/' + idx)).read()
51
 
        shelf = shelf[shelf.index('\n') + 1:] # skip the message
52
 
        self.assertEqual(shelf, diff)
53
 
 
54
28
    def test_shelf(self):
55
29
        self.__test_loop(1)
56
30
 
58
32
        self.__test_loop(10)
59
33
 
60
34
    def __test_loop(self, count):
61
 
        self.tree = self.make_branch_and_tree('.')
62
 
        self.__create_and_add_test_file()
 
35
        tree = self.make_branch_and_tree('.')
 
36
        self.__create_and_add_test_file(tree)
63
37
 
64
38
        while count > 0:
65
39
            count -= 1
66
40
 
67
41
            # Modify the test file
68
 
            # write in binary mode because on win32 line-endings should be LF
69
 
            f = file('test_file', 'wb')
70
 
            f.write(self.MODIFIED)
71
 
            f.close()
 
42
            file('test_file', 'w').write(self.MODIFIED)
72
43
 
73
 
            self._check_diff()
74
 
            
75
 
            new_date = _patch_header_date(self.tree, 
76
 
                self.tree.inventory.path2id('test_file'), 'test_file')
 
44
            # Check the diff is right
 
45
            self.assertEqual(self.capture('diff', retcode=1),
 
46
                self.DIFF_HEADER + self.DIFF_1 + '\n')
77
47
 
78
48
            # Shelve the changes
79
49
            self.run_bzr('shelve', '--all', retcode=0)
84
54
            # Make sure the file is actually back the way it was
85
55
            self.assertEqual(file('test_file').read(), self.ORIGINAL)
86
56
 
87
 
            self._check_shelf('00', new_date=new_date)
 
57
            # Check the shelf is right
 
58
            shelf = open(os.path.join(tree.branch.base,
 
59
                        '.shelf/shelves/default/00')).read()
 
60
            shelf = shelf[shelf.index('\n') + 1:] # skip the message
 
61
            self.assertEqual(shelf, self.DIFF_1)
88
62
 
89
63
            # Unshelve
90
64
            self.run_bzr('unshelve', '--all', retcode=0)
91
65
 
92
 
            self._check_diff()
 
66
            # Check the diff is right again
 
67
            self.assertEqual(self.capture('diff', retcode=1),
 
68
                self.DIFF_HEADER + self.DIFF_1 + '\n')
93
69
 
94
70
            # Check the shelved patch was backed up
95
 
            self._check_shelf('00~', new_date=new_date)
 
71
            shelf = open(os.path.join(tree.branch.base,
 
72
                        '.shelf/shelves/default/00~')).read()
 
73
            shelf = shelf[shelf.index('\n') + 1:] # skip the message
 
74
            self.assertEqual(shelf, self.DIFF_1)
96
75
 
97
76
            # Make sure the file is back the way it should be
98
77
            self.assertEqual(file('test_file').read(), self.MODIFIED)
99
78
 
100
79
    def test_shelf_nothing_to_shelve(self):
101
80
        import os.path
102
 
        self.tree = self.make_branch_and_tree('.')
103
 
        self.__create_and_add_test_file()
 
81
        tree = self.make_branch_and_tree('.')
 
82
        self.__create_and_add_test_file(tree)
104
83
 
105
84
        # Shelve the changes
106
85
        self.run_bzr('shelve', '--all', retcode=3)
107
86
 
108
 
        if os.path.exists(os.path.join(self.tree.branch.base,
 
87
        if os.path.exists(os.path.join(tree.branch.base,
109
88
                '.shelf/shelves/default/00')):
110
89
            self.fail("Shelf exists, but it shouldn't")
111
90
 
112
 
    def __create_and_add_test_file(self, filename='test_file'):
113
 
        # write in binary mode because on win32 line-endings should be LF
114
 
        f = open(filename, 'wb')
 
91
    def __create_and_add_test_file(self, tree, filename='test_file'):
 
92
        f = open(filename, 'w')
115
93
        f.write(self.ORIGINAL)
116
94
        f.close()
117
 
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(), filename)))
118
 
        self.tree.commit(message='add %s' % filename)
 
95
        tree.add(tree.relpath(os.path.join(os.getcwd(), filename)))
 
96
        tree.commit(message='add %s' % filename)
119
97
 
120
98
    def test_shelf_with_revision(self):
121
 
        self.tree = self.make_branch_and_tree('.')
 
99
        tree = self.make_branch_and_tree('.')
122
100
 
123
 
        self.__create_and_add_test_file()
 
101
        self.__create_and_add_test_file(tree)
124
102
 
125
103
        # Modify the test file and commit it
126
104
        self.build_tree_contents([('test_file', self.MODIFIED)])
127
 
        self.tree.commit(message='update test_file')
 
105
        tree.commit(message='update test_file')
128
106
 
129
107
        # Shelve the changes
130
108
        self.run_bzr('shelve', '--all', '-r', '1', retcode=0)
131
109
 
132
 
        self._check_diff(self.DIFF_2)
 
110
        # Check the diff is right
 
111
        self.assertEqual(self.capture('diff', retcode=1),
 
112
            self.DIFF_HEADER + self.DIFF_2 + '\n')
133
113
 
134
114
        # Make sure the file is the way it should be
135
115
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
141
121
        self.assertEqual(file('test_file').read(), self.MODIFIED)
142
122
 
143
123
    def test_shelf_with_two_revisions(self):
144
 
        self.tree = self.make_branch_and_tree('.')
 
124
        tree = self.make_branch_and_tree('.')
145
125
 
146
126
        cmd = 'shelve --all -r 1..2'
147
127
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
150
130
            'bzr: ERROR: shelve only accepts a single revision parameter.')
151
131
 
152
132
    def test_shelf_show_basic(self):
153
 
        self.tree = self.make_branch_and_tree('.')
154
 
        self.__create_and_add_test_file()
155
 
        self.__test_show(self.tree, '00')
 
133
        tree = self.make_branch_and_tree('.')
 
134
        self.__create_and_add_test_file(tree)
 
135
        self.__test_show(tree, '00')
156
136
 
157
137
    def __test_show(self, tree, patch):
158
138
        # Modify the test file
165
145
        self.assertEqual(self.capture('diff', retcode=0), '')
166
146
 
167
147
        # Check the shelf is right
168
 
        shelf = open(os.path.join(self.tree.basedir,
 
148
        shelf = open(os.path.join(tree.branch.base,
169
149
                    '.shelf/shelves/default', patch)).read()
170
150
        self.assertTrue('patch %s' % patch in shelf)
171
151
 
174
154
        self.assertEqual(shown, shelf)
175
155
 
176
156
    def test_shelf_show_multi(self):
177
 
        self.tree = self.make_branch_and_tree('.')
178
 
        self.__create_and_add_test_file()
179
 
        self.__test_show(self.tree, '00')
180
 
        self.__test_show(self.tree, '01')
181
 
        self.__test_show(self.tree, '02')
 
157
        tree = self.make_branch_and_tree('.')
 
158
        self.__create_and_add_test_file(tree)
 
159
        self.__test_show(tree, '00')
 
160
        self.__test_show(tree, '01')
 
161
        self.__test_show(tree, '02')
182
162
 
183
163
        # Now check we can show a previously shelved patch
184
 
        shelf = open(os.path.join(self.tree.basedir,
 
164
        shelf = open(os.path.join(tree.branch.base,
185
165
                    '.shelf/shelves/default/00')).read()
186
166
        self.assertTrue('patch 00' in shelf)
187
167
 
189
169
        shown = self.capture('shelf show 00', retcode=0)
190
170
        self.assertEqual(shown, shelf)
191
171
 
192
 
    def test_shelf_show_unspecified(self):
193
 
        self.tree = self.make_branch_and_tree('.')
194
 
        self.__create_and_add_test_file()
195
 
        self.__test_show(self.tree, '00')
196
 
        self.__test_show(self.tree, '01')
197
 
        self.__test_show(self.tree, '02')
198
 
 
199
 
        # Check that not specifying at patch gets us the most recent
200
 
        shelf = open(os.path.join(self.tree.basedir,
201
 
                    '.shelf/shelves/default/02')).read()
202
 
        self.assertTrue('patch 02' in shelf)
203
 
 
204
 
        # Check the shown output is right
205
 
        shown = self.capture('shelf show', retcode=0)
206
 
        self.assertEqual(shown, shelf)
207
 
 
208
172
    def test_shelf_show_with_no_patch(self):
209
 
        self.tree = self.make_branch_and_tree('.')
 
173
        tree = self.make_branch_and_tree('.')
210
174
        stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1]
211
175
        self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr)
212
176
 
213
177
    def test_shelf_unshelve_failure(self):
214
 
        self.tree = self.make_branch_and_tree('.')
 
178
        tree = self.make_branch_and_tree('.')
215
179
 
216
 
        self.__create_and_add_test_file()
 
180
        self.__create_and_add_test_file(tree)
217
181
 
218
182
        # Modify the test file
219
183
        file('test_file', 'w').write(self.MODIFIED)
222
186
        self.run_bzr('shelve', '--all', retcode=0)
223
187
 
224
188
        # Write an unapplyable patch into the shelf
225
 
        shelf = open(os.path.join(self.tree.basedir,
 
189
        shelf = open(os.path.join(tree.branch.base,
226
190
                    '.shelf/shelves/default/00'), 'w')
227
191
        shelf.write(self.DIFF_2)
228
192
        shelf.close()
231
195
        self.run_bzr('unshelve', '--all', retcode=3)
232
196
 
233
197
        # Make sure the patch is still there, eventhough it's broken
234
 
        shelf = open(os.path.join(self.tree.basedir,
 
198
        shelf = open(os.path.join(tree.branch.base,
235
199
                    '.shelf/shelves/default/00')).read()
236
200
        self.assertEqual(shelf, self.DIFF_2)
237
201
 
240
204
        self.assertEqual(diff, '')
241
205
 
242
206
    def test_shelf_unshelve_failure_two_hunks(self):
243
 
        self.tree = self.make_branch_and_tree('.')
 
207
        tree = self.make_branch_and_tree('.')
244
208
 
245
 
        self.__create_and_add_test_file()
246
 
        self.__create_and_add_test_file(filename='test_file2')
 
209
        self.__create_and_add_test_file(tree)
 
210
        self.__create_and_add_test_file(tree, filename='test_file2')
247
211
 
248
212
        # Modify the test files
249
213
        file('test_file', 'w').write(self.MODIFIED)
254
218
 
255
219
        # Put the changes to test_file back, the shelved patch won't apply now
256
220
        file('test_file', 'w').write(self.MODIFIED)
257
 
        self.tree.commit(message='screw up test_file')
 
221
        tree.commit(message='screw up test_file')
258
222
 
259
223
        # Unshelve, should fail
260
224
        self.run_bzr('unshelve', '--all', retcode=3)
269
233
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
270
234
 
271
235
    def test_shelf_after_unshelve(self):
272
 
        self.tree = self.make_branch_and_tree('.')
 
236
        tree = self.make_branch_and_tree('.')
273
237
 
274
 
        self.__create_and_add_test_file()
275
 
        self.__create_and_add_test_file(filename='test_file2')
 
238
        self.__create_and_add_test_file(tree)
 
239
        self.__create_and_add_test_file(tree, filename='test_file2')
276
240
 
277
241
        # Modify the test files
278
242
        file('test_file', 'w').write(self.MODIFIED)
290
254
        self.assertTrue(os.path.exists('.shelf/shelves/default/01~'))
291
255
 
292
256
        # Check ls works
293
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
294
 
        for line in lines:
 
257
        list = self.capture('shelf ls', retcode=0).split('\n')
 
258
        for line in list:
295
259
            self.assertFalse(line.startswith(' 01'))
296
260
 
297
261
        # Unshelve, if unshelve is confused by the backup it will fail
298
262
        self.run_bzr('unshelve', '--all', retcode=0)
299
263
 
300
264
    def test_shelf_delete(self):
301
 
        self.tree = self.make_branch_and_tree('.')
 
265
        tree = self.make_branch_and_tree('.')
302
266
 
303
 
        self.__create_and_add_test_file()
304
 
        self.__create_and_add_test_file(filename='test_file2')
 
267
        self.__create_and_add_test_file(tree)
 
268
        self.__create_and_add_test_file(tree, filename='test_file2')
305
269
 
306
270
        # Modify the test files
307
 
        # write in binary mode because on win32 line-endings should be LF
308
 
        f = file('test_file', 'wb')
309
 
        f.write(self.MODIFIED)
310
 
        f.close()
311
 
        f = file('test_file2', 'wb')
312
 
        f.write(self.MODIFIED)
313
 
        f.close()
314
 
        new_date = _patch_header_date(self.tree, 
315
 
            self.tree.inventory.path2id('test_file'), 'test_file')
 
271
        file('test_file', 'w').write(self.MODIFIED)
 
272
        file('test_file2', 'w').write(self.MODIFIED)
316
273
 
317
274
        # Shelve the changes
318
275
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
319
276
        self.run_bzr('shelve', '--all', 'test_file2', retcode=0)
320
277
 
321
 
        self._check_shelf('00', new_date=new_date)
322
 
 
323
278
        # Delete 00
324
279
        self.run_bzr('shelf', 'delete', '00', retcode=0)
325
280
 
326
 
        # We should now have 01 but not 00, but we should have 00~
 
281
        # We should now have 01 but not 00
327
282
        self.assertFalse(os.path.exists('.shelf/shelves/default/00'))
328
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/00~'))
329
283
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
330
284
 
331
 
        # Check the backup is right
332
 
        self._check_shelf('00~', new_date=new_date)
333
 
 
334
285
        # Check ls works
335
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
336
 
        for line in lines:
 
286
        list = self.capture('shelf ls', retcode=0).split('\n')
 
287
        for line in list:
337
288
            self.assertFalse(line.startswith(' 00'))
338
289
 
339
290
        # Unshelve should unshelve 01
341
292
        self.assertEqual(file('test_file2').read(), self.MODIFIED)
342
293
 
343
294
    def test_shelf_gaps(self):
344
 
        self.tree = self.make_branch_and_tree('.')
345
 
        self.__create_and_add_test_file()
 
295
        tree = self.make_branch_and_tree('.')
 
296
        self.__create_and_add_test_file(tree)
346
297
        file('test_file', 'w').write(self.MODIFIED)
347
298
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
348
299
        file('test_file', 'w').write(self.MODIFIED)
358
309
        self.assertTrue(os.path.exists('.shelf/shelves/default/02'))
359
310
 
360
311
    def test_shelf_upgrade(self):
361
 
        self.tree = self.make_branch_and_tree('.')
 
312
        tree = self.make_branch_and_tree('.')
362
313
 
363
 
        self.__create_and_add_test_file()
 
314
        self.__create_and_add_test_file(tree)
364
315
 
365
316
        # Modify then shelve, so we're not upgrading to 00, just for kicks
366
317
        file('test_file', 'w').write(self.MODIFIED)
398
349
        # Shelve should work now
399
350
        self.run_bzr('shelve', '--all', retcode=0)
400
351
 
401
 
    def test_shelf_p1_patch(self):
402
 
        self.tree = self.make_branch_and_tree('.')
 
352
    def test_shelf_p0_patch(self):
 
353
        tree = self.make_branch_and_tree('.')
403
354
 
404
 
        self.__create_and_add_test_file()
 
355
        self.__create_and_add_test_file(tree)
405
356
 
406
357
        # Run a benign shelf command to setup .shelf for us
407
358
        self.run_bzr('shelf', 'ls', retcode=0)
408
359
 
409
 
        old_tree = self.tree.basis_tree()
410
 
        old_date = _patch_header_date(old_tree, 
411
 
                                      old_tree.inventory.path2id('test_file'),
412
 
                                      'test_file')
413
 
        new_date = _patch_header_date(self.tree, 
414
 
                                      self.tree.inventory.path2id('test_file'),
415
 
                                      'test_file')
416
360
        # Fake a -p0 shelved patch
417
 
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
418
 
                               'new_date' : new_date}
419
 
        diff = diff.replace('--- ', '--- a/')
420
 
        diff = diff.replace('+++ ', '+++ b/')
 
361
        diff = self.DIFF_1
 
362
        diff = diff.replace('a/', '')
 
363
        diff = diff.replace('b/', '')
421
364
        open('.shelf/shelves/default/00', 'w').write(diff)
422
365
 
423
366
        # This should work
424
367
        self.run_bzr('unshelve', '--all', retcode=0)
425
368
 
426
 
        self._check_diff()
 
369
        # Check the diff is right
 
370
        self.assertEqual(self.capture('diff', retcode=1),
 
371
            self.DIFF_HEADER + self.DIFF_1 + '\n')
427
372
 
428
373
    def test_shelf_shelve_in_subdir(self):
429
 
        self.tree = self.make_branch_and_tree('.')
430
 
 
431
 
        subdir = 'subdir'
432
 
        os.mkdir(subdir)
433
 
        self.tree.add(subdir)
434
 
        os.chdir(subdir)
435
 
 
436
 
        self.__create_and_add_test_file()
 
374
        tree = self.make_branch_and_tree('.')
 
375
 
 
376
        self.__create_and_add_test_file(tree)
437
377
 
438
378
        # Modify the test file
439
 
        # write in binary mode because on win32 line-endings should be LF
440
 
        f = file('test_file', 'wb')
441
 
        f.write(self.MODIFIED)
442
 
        f.close()
 
379
        file('test_file', 'w').write(self.MODIFIED)
443
380
 
444
381
        # Shelve the changes
445
382
        self.run_bzr('shelve', '--all', retcode=0)
451
388
        # Unshelve, should succeed
452
389
        self.run_bzr('unshelve', '--all', retcode=0)
453
390
 
454
 
        self._check_diff(filename='subdir/test_file')
455
 
 
456
 
        # Make sure relative filenames work ok
457
 
        self.run_bzr('shelve', 'test_file', '--all', retcode=0)
458
 
 
459
 
    def test_shelf_shelf_bogus_subcommand(self):
460
 
        self.tree = self.make_branch_and_tree('.')
461
 
        self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3
462
 
 
463
 
    def test_shelf_OOO_unshelve(self):
464
 
        self.tree = self.make_branch_and_tree('.')
465
 
 
466
 
        for i in range(1, 5):
467
 
            self.__create_and_add_test_file(filename='test_file%d' % i)
468
 
 
469
 
        # Modify the test files
470
 
        for i in range(1, 5):
471
 
            file('test_file%d' % i, 'w').write(self.MODIFIED)
472
 
 
473
 
        # Shelve the changes
474
 
        for i in range(1, 5):
475
 
            self.run_bzr('shelve', '--all', 'test_file%d' % i, retcode=0)
476
 
 
477
 
        # Check shelving worked
478
 
        for i in range(1, 5):
479
 
            self.assertEqual(file('test_file%d' % i).read(), self.ORIGINAL)
480
 
 
481
 
        # We should now have 00-03
482
 
        for i in range(0, 4):
483
 
            self.assertTrue(os.path.exists('.shelf/shelves/default/0%d' % i))
484
 
 
485
 
        # Unshelve 00
486
 
        self.run_bzr('unshelve', '--all', '00', retcode=0)
487
 
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
488
 
 
489
 
        # Check ls works
490
 
        lines = self.capture('shelf ls', retcode=0).split('\n')
491
 
        for line in lines:
492
 
            self.assertFalse(line.startswith(' 00'))
493
 
 
494
 
        # Check we can reshelve once we've unshelved out of order, should be 04
495
 
        self.assertFalse(os.path.exists('.shelf/shelves/default/04'))
496
 
        self.run_bzr('shelve', '--all')
497
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/04'))
498
 
 
499
 
        # Check ls works
500
 
        text = self.capture('shelf ls', retcode=0)
501
 
        for line in text.split('\n'):
502
 
            self.assertFalse(line.startswith(' 00'))
503
 
 
504
 
        # We now have 01,02,03,04
505
 
        # Unshelve 02
506
 
        self.run_bzr('unshelve', '--all', '02', retcode=0)
507
 
        self.assertEqual(file('test_file3').read(), self.MODIFIED)
508
 
 
509
 
        # Unshelve the default, this is the reshelved 00, hence modifies file 1
510
 
        self.run_bzr('unshelve', '--all', retcode=0)
511
 
        self.assertEqual(file('test_file1').read(), self.MODIFIED)
512
 
 
513
 
    def test_shelf_switch_basic(self):
514
 
        self.tree = self.make_branch_and_tree('.')
515
 
        self.__create_and_add_test_file()
516
 
 
517
 
        # This should go to "default"
518
 
        file('test_file', 'w').write(self.MODIFIED)
519
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
520
 
 
521
 
        # Switch to "other"
522
 
        self.run_bzr('shelf', 'switch', 'other', retcode=0)
523
 
        file('test_file', 'w').write(self.MODIFIED)
524
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
525
 
 
526
 
        # Check it worked
527
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/00'))
528
 
        self.assertFalse(os.path.exists('.shelf/shelves/default/01'))
529
 
        self.assertTrue(os.path.exists('.shelf/shelves/other/00'))
530
 
 
531
 
        # Switch back
532
 
        self.run_bzr('shelf', 'switch', 'default', retcode=0)
533
 
        file('test_file', 'w').write(self.MODIFIED)
534
 
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
535
 
 
536
 
        # Check that worked
537
 
        self.assertTrue(os.path.exists('.shelf/shelves/default/01'))
538
 
        self.assertFalse(os.path.exists('.shelf/shelves/other/01'))
539
 
 
540
 
    def test_shelf_bad_patch_arg(self):
541
 
        self.tree = self.make_branch_and_tree('.')
542
 
 
543
 
        # Check the bad arg handling
544
 
        stdout, error = self.run_bzr_captured(['unshelve', '01'], retcode=3)
545
 
        self.assertTrue("Patch '01' doesn't exist on shelf" in error)
546
 
 
547
 
        stdout, error = self.run_bzr_captured(['unshelve', 'foo'], retcode=3)
548
 
        self.assertTrue("Invalid patch name 'foo'" in error)
549
 
 
550
 
        # Hex and is cracky, so it shouldn't work
551
 
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
552
 
        self.assertTrue("Invalid patch name '0x00'" in error)
 
391
        # Check the diff is right
 
392
        self.assertEqual(self.capture('diff', retcode=1),
 
393
            self.DIFF_HEADER + self.DIFF_1 + '\n')