0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
1 |
#!/usr/bin/python
|
2 |
||
291
by Aaron Bentley
Adjusted to selftest -> tests change |
3 |
import bzrlib.tests |
0.2.6
by Michael Ellerman
Make tests work with new bzr API, we can't use _transport anymore. |
4 |
import os.path |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
5 |
|
0.2.26
by Michael Ellerman
Update tests for BzrDir changes, use test helpers to save future pain. |
6 |
class ShelfTests(bzrlib.tests.TestCaseWithTransport): |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
7 |
ORIGINAL = '\n\nhello test world\n\n' |
8 |
MODIFIED = '\n\ngoodbye test world\n\n' |
|
0.1.108
by Michael Ellerman
Update tests for -p0 format diffs by default. |
9 |
DIFF_HEADER = "=== modified file '%(filename)s'\n" |
10 |
DIFF_1 = """--- %(filename)s\t |
|
11 |
+++ %(filename)s\t |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
12 |
@@ -1,4 +1,4 @@
|
13 |
|
|
14 |
|
|
15 |
-hello test world
|
|
16 |
+goodbye test world
|
|
17 |
|
|
18 |
"""
|
|
0.1.108
by Michael Ellerman
Update tests for -p0 format diffs by default. |
19 |
DIFF_2 = """--- test_file\t |
20 |
+++ test_file\t |
|
0.1.40
by Michael Ellerman
Update test with revision to actually test the shelf worked properly. |
21 |
@@ -1,4 +1,4 @@
|
22 |
|
|
23 |
|
|
24 |
-goodbye test world
|
|
25 |
+hello test world
|
|
26 |
|
|
27 |
"""
|
|
0.1.103
by Michael Ellerman
Add test machinery to cope with subdirectories. |
28 |
def _check_diff(self, diff=DIFF_1, filename='test_file'): |
29 |
keys = { 'filename' : filename } |
|
30 |
hdr = self.DIFF_HEADER % keys |
|
31 |
diff = diff % keys |
|
32 |
self.assertEqual(self.capture('diff', retcode=1), hdr + diff + '\n') |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
33 |
|
0.1.103
by Michael Ellerman
Add test machinery to cope with subdirectories. |
34 |
def _check_shelf(self, idx, diff=DIFF_1, filename='test_file'): |
35 |
diff = diff % { 'filename' : filename } |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
36 |
shelf = open(os.path.join(self.tree.branch.base, |
37 |
'.shelf/shelves/default/' + idx)).read() |
|
38 |
shelf = shelf[shelf.index('\n') + 1:] # skip the message |
|
39 |
self.assertEqual(shelf, diff) |
|
40 |
||
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
41 |
def test_shelf(self): |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
42 |
self.__test_loop(1) |
43 |
||
44 |
def test_shelf_multi(self): |
|
45 |
self.__test_loop(10) |
|
46 |
||
47 |
def __test_loop(self, count): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
48 |
self.tree = self.make_branch_and_tree('.') |
49 |
self.__create_and_add_test_file() |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
50 |
|
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
51 |
while count > 0: |
52 |
count -= 1 |
|
53 |
||
54 |
# Modify the test file
|
|
55 |
file('test_file', 'w').write(self.MODIFIED) |
|
56 |
||
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
57 |
self._check_diff() |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
58 |
|
59 |
# Shelve the changes
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
60 |
self.run_bzr('shelve', '--all', retcode=0) |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
61 |
|
62 |
# Make sure there is no diff anymore
|
|
63 |
self.assertEqual(self.capture('diff', retcode=0), '') |
|
64 |
||
65 |
# Make sure the file is actually back the way it was
|
|
66 |
self.assertEqual(file('test_file').read(), self.ORIGINAL) |
|
67 |
||
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
68 |
self._check_shelf('00') |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
69 |
|
70 |
# Unshelve
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
71 |
self.run_bzr('unshelve', '--all', retcode=0) |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
72 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
73 |
self._check_diff() |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
74 |
|
0.1.84
by Michael Ellerman
Backup the patch when we unshelve. Suggested by Christian Reis. |
75 |
# Check the shelved patch was backed up
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
76 |
self._check_shelf('00~') |
0.1.84
by Michael Ellerman
Backup the patch when we unshelve. Suggested by Christian Reis. |
77 |
|
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
78 |
# Make sure the file is back the way it should be
|
79 |
self.assertEqual(file('test_file').read(), self.MODIFIED) |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
80 |
|
81 |
def test_shelf_nothing_to_shelve(self): |
|
82 |
import os.path |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
83 |
self.tree = self.make_branch_and_tree('.') |
84 |
self.__create_and_add_test_file() |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
85 |
|
86 |
# Shelve the changes
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
87 |
self.run_bzr('shelve', '--all', retcode=3) |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
88 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
89 |
if os.path.exists(os.path.join(self.tree.branch.base, |
0.2.26
by Michael Ellerman
Update tests for BzrDir changes, use test helpers to save future pain. |
90 |
'.shelf/shelves/default/00')): |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
91 |
self.fail("Shelf exists, but it shouldn't") |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
92 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
93 |
def __create_and_add_test_file(self, filename='test_file'): |
0.1.98
by Michael Ellerman
Add a test for shelving in a subdirectory |
94 |
f = open(filename, 'w') |
95 |
f.write(self.ORIGINAL) |
|
96 |
f.close() |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
97 |
self.tree.add(self.tree.relpath(os.path.join(os.getcwd(), filename))) |
98 |
self.tree.commit(message='add %s' % filename) |
|
0.2.26
by Michael Ellerman
Update tests for BzrDir changes, use test helpers to save future pain. |
99 |
|
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
100 |
def test_shelf_with_revision(self): |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
101 |
self.tree = self.make_branch_and_tree('.') |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
102 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
103 |
self.__create_and_add_test_file() |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
104 |
|
105 |
# Modify the test file and commit it
|
|
0.2.26
by Michael Ellerman
Update tests for BzrDir changes, use test helpers to save future pain. |
106 |
self.build_tree_contents([('test_file', self.MODIFIED)]) |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
107 |
self.tree.commit(message='update test_file') |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
108 |
|
109 |
# Shelve the changes
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
110 |
self.run_bzr('shelve', '--all', '-r', '1', retcode=0) |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
111 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
112 |
self._check_diff(self.DIFF_2) |
0.1.40
by Michael Ellerman
Update test with revision to actually test the shelf worked properly. |
113 |
|
114 |
# Make sure the file is the way it should be
|
|
115 |
self.assertEqual(file('test_file').read(), self.ORIGINAL) |
|
116 |
||
117 |
# Unshelve
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
118 |
self.run_bzr('unshelve', '--all', retcode=0) |
0.1.40
by Michael Ellerman
Update test with revision to actually test the shelf worked properly. |
119 |
|
120 |
# Make sure the file is back the way it should be
|
|
121 |
self.assertEqual(file('test_file').read(), self.MODIFIED) |
|
122 |
||
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
123 |
def test_shelf_with_two_revisions(self): |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
124 |
self.tree = self.make_branch_and_tree('.') |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
125 |
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
126 |
cmd = 'shelve --all -r 1..2' |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
127 |
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None) |
128 |
||
129 |
self.assertEqual(stderr.split('\n')[0], |
|
295
by Aaron Bentley
Fixed test case failure |
130 |
'bzr: ERROR: shelve only accepts a single revision parameter.') |
281
by Aaron Bentley
Handled whitespace branch names better |
131 |
|
0.2.27
by Michael Ellerman
Add basic test for shelf show |
132 |
def test_shelf_show_basic(self): |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
133 |
self.tree = self.make_branch_and_tree('.') |
134 |
self.__create_and_add_test_file() |
|
135 |
self.__test_show(self.tree, '00') |
|
0.2.27
by Michael Ellerman
Add basic test for shelf show |
136 |
|
0.2.28
by Michael Ellerman
More tests of shelf show |
137 |
def __test_show(self, tree, patch): |
0.2.27
by Michael Ellerman
Add basic test for shelf show |
138 |
# Modify the test file
|
0.2.28
by Michael Ellerman
More tests of shelf show |
139 |
self.build_tree_contents([('test_file', 'patch %s\n' % patch)]) |
0.2.27
by Michael Ellerman
Add basic test for shelf show |
140 |
|
141 |
# Shelve the changes
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
142 |
self.run_bzr('shelve', '--all', retcode=0) |
0.2.27
by Michael Ellerman
Add basic test for shelf show |
143 |
|
144 |
# Make sure there is no diff anymore
|
|
145 |
self.assertEqual(self.capture('diff', retcode=0), '') |
|
146 |
||
147 |
# Check the shelf is right
|
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
148 |
shelf = open(os.path.join(self.tree.branch.base, |
0.2.28
by Michael Ellerman
More tests of shelf show |
149 |
'.shelf/shelves/default', patch)).read() |
150 |
self.assertTrue('patch %s' % patch in shelf) |
|
151 |
||
152 |
# Check the shown output is right
|
|
153 |
shown = self.capture('shelf show %s' % patch, retcode=0) |
|
154 |
self.assertEqual(shown, shelf) |
|
155 |
||
156 |
def test_shelf_show_multi(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
157 |
self.tree = self.make_branch_and_tree('.') |
158 |
self.__create_and_add_test_file() |
|
159 |
self.__test_show(self.tree, '00') |
|
160 |
self.__test_show(self.tree, '01') |
|
161 |
self.__test_show(self.tree, '02') |
|
0.2.28
by Michael Ellerman
More tests of shelf show |
162 |
|
163 |
# Now check we can show a previously shelved patch
|
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
164 |
shelf = open(os.path.join(self.tree.branch.base, |
0.2.27
by Michael Ellerman
Add basic test for shelf show |
165 |
'.shelf/shelves/default/00')).read() |
0.2.28
by Michael Ellerman
More tests of shelf show |
166 |
self.assertTrue('patch 00' in shelf) |
0.2.27
by Michael Ellerman
Add basic test for shelf show |
167 |
|
168 |
# Check the shown output is right
|
|
169 |
shown = self.capture('shelf show 00', retcode=0) |
|
170 |
self.assertEqual(shown, shelf) |
|
0.2.30
by Michael Ellerman
Test for shelf show with no patch to show. |
171 |
|
172 |
def test_shelf_show_with_no_patch(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
173 |
self.tree = self.make_branch_and_tree('.') |
0.2.30
by Michael Ellerman
Test for shelf show with no patch to show. |
174 |
stderr = self.run_bzr_captured(['shelf', 'show', '00'], retcode=None)[1] |
175 |
self.assertTrue("Patch '00' doesn't exist on shelf default!" in stderr) |
|
176 |
||
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
177 |
def test_shelf_unshelve_failure(self): |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
178 |
self.tree = self.make_branch_and_tree('.') |
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
179 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
180 |
self.__create_and_add_test_file() |
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
181 |
|
182 |
# Modify the test file
|
|
183 |
file('test_file', 'w').write(self.MODIFIED) |
|
184 |
||
185 |
# Shelve the changes
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
186 |
self.run_bzr('shelve', '--all', retcode=0) |
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
187 |
|
188 |
# Write an unapplyable patch into the shelf
|
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
189 |
shelf = open(os.path.join(self.tree.branch.base, |
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
190 |
'.shelf/shelves/default/00'), 'w') |
191 |
shelf.write(self.DIFF_2) |
|
192 |
shelf.close() |
|
193 |
||
194 |
# Unshelve, should fail
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
195 |
self.run_bzr('unshelve', '--all', retcode=3) |
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
196 |
|
197 |
# Make sure the patch is still there, eventhough it's broken
|
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
198 |
shelf = open(os.path.join(self.tree.branch.base, |
0.1.76
by Michael Ellerman
Add a test to make sure we don't delete the shelved patch if unshelving |
199 |
'.shelf/shelves/default/00')).read() |
200 |
self.assertEqual(shelf, self.DIFF_2) |
|
0.1.77
by Michael Ellerman
When unshelving, try to patch with --dry-run first, if that fails bail out. |
201 |
|
202 |
# Working tree should be unchanged
|
|
203 |
diff = self.capture('diff', retcode=0) |
|
204 |
self.assertEqual(diff, '') |
|
205 |
||
206 |
def test_shelf_unshelve_failure_two_hunks(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
207 |
self.tree = self.make_branch_and_tree('.') |
0.1.77
by Michael Ellerman
When unshelving, try to patch with --dry-run first, if that fails bail out. |
208 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
209 |
self.__create_and_add_test_file() |
210 |
self.__create_and_add_test_file(filename='test_file2') |
|
0.1.77
by Michael Ellerman
When unshelving, try to patch with --dry-run first, if that fails bail out. |
211 |
|
212 |
# Modify the test files
|
|
213 |
file('test_file', 'w').write(self.MODIFIED) |
|
214 |
file('test_file2', 'w').write(self.MODIFIED) |
|
215 |
||
216 |
# Shelve the changes
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
217 |
self.run_bzr('shelve', '--all', retcode=0) |
0.1.77
by Michael Ellerman
When unshelving, try to patch with --dry-run first, if that fails bail out. |
218 |
|
219 |
# Put the changes to test_file back, the shelved patch won't apply now
|
|
220 |
file('test_file', 'w').write(self.MODIFIED) |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
221 |
self.tree.commit(message='screw up test_file') |
0.1.77
by Michael Ellerman
When unshelving, try to patch with --dry-run first, if that fails bail out. |
222 |
|
223 |
# Unshelve, should fail
|
|
0.1.80
by Michael Ellerman
After extensive user testing, ie. me using it, I've decided --pick should be |
224 |
self.run_bzr('unshelve', '--all', retcode=3) |
0.1.77
by Michael Ellerman
When unshelving, try to patch with --dry-run first, if that fails bail out. |
225 |
|
226 |
# Working tree should be unchanged
|
|
227 |
diff = self.capture('diff', retcode=0) |
|
228 |
self.assertEqual(diff, '') |
|
0.1.84
by Michael Ellerman
Backup the patch when we unshelve. Suggested by Christian Reis. |
229 |
|
0.1.91
by Michael Ellerman
Add --force option to unshelve, which runs the shelved changes through |
230 |
# Force should succeed and modify test_file2, but leave shelf
|
231 |
self.run_bzr('unshelve', '--force', '--all', retcode=0) |
|
232 |
self.assertEqual(open('test_file2').read(), self.MODIFIED) |
|
233 |
self.assertTrue(os.path.exists('.shelf/shelves/default/00')) |
|
234 |
||
0.1.84
by Michael Ellerman
Backup the patch when we unshelve. Suggested by Christian Reis. |
235 |
def test_shelf_after_unshelve(self): |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
236 |
self.tree = self.make_branch_and_tree('.') |
0.1.84
by Michael Ellerman
Backup the patch when we unshelve. Suggested by Christian Reis. |
237 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
238 |
self.__create_and_add_test_file() |
239 |
self.__create_and_add_test_file(filename='test_file2') |
|
0.1.84
by Michael Ellerman
Backup the patch when we unshelve. Suggested by Christian Reis. |
240 |
|
241 |
# Modify the test files
|
|
242 |
file('test_file', 'w').write(self.MODIFIED) |
|
243 |
file('test_file2', 'w').write(self.MODIFIED) |
|
244 |
||
245 |
# Shelve the changes
|
|
246 |
self.run_bzr('shelve', '--all', 'test_file', retcode=0) |
|
247 |
self.run_bzr('shelve', '--all', 'test_file2', retcode=0) |
|
248 |
||
249 |
# Unshelve
|
|
250 |
self.run_bzr('unshelve', '--all', retcode=0) |
|
251 |
||
252 |
# We should now have 00 and 01~
|
|
253 |
self.assertTrue(os.path.exists('.shelf/shelves/default/00')) |
|
254 |
self.assertTrue(os.path.exists('.shelf/shelves/default/01~')) |
|
255 |
||
256 |
# Check ls works
|
|
257 |
list = self.capture('shelf ls', retcode=0).split('\n') |
|
258 |
for line in list: |
|
259 |
self.assertFalse(line.startswith(' 01')) |
|
260 |
||
261 |
# Unshelve, if unshelve is confused by the backup it will fail
|
|
262 |
self.run_bzr('unshelve', '--all', retcode=0) |
|
0.1.85
by Michael Ellerman
Add a test for delete |
263 |
|
264 |
def test_shelf_delete(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
265 |
self.tree = self.make_branch_and_tree('.') |
0.1.85
by Michael Ellerman
Add a test for delete |
266 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
267 |
self.__create_and_add_test_file() |
268 |
self.__create_and_add_test_file(filename='test_file2') |
|
0.1.85
by Michael Ellerman
Add a test for delete |
269 |
|
270 |
# Modify the test files
|
|
271 |
file('test_file', 'w').write(self.MODIFIED) |
|
272 |
file('test_file2', 'w').write(self.MODIFIED) |
|
273 |
||
274 |
# Shelve the changes
|
|
275 |
self.run_bzr('shelve', '--all', 'test_file', retcode=0) |
|
276 |
self.run_bzr('shelve', '--all', 'test_file2', retcode=0) |
|
277 |
||
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
278 |
self._check_shelf('00') |
0.1.100
by Michael Ellerman
Backup the shelved patch when we delete in "shelf delete". |
279 |
|
0.1.85
by Michael Ellerman
Add a test for delete |
280 |
# Delete 00
|
281 |
self.run_bzr('shelf', 'delete', '00', retcode=0) |
|
282 |
||
0.1.100
by Michael Ellerman
Backup the shelved patch when we delete in "shelf delete". |
283 |
# We should now have 01 but not 00, but we should have 00~
|
0.1.85
by Michael Ellerman
Add a test for delete |
284 |
self.assertFalse(os.path.exists('.shelf/shelves/default/00')) |
0.1.100
by Michael Ellerman
Backup the shelved patch when we delete in "shelf delete". |
285 |
self.assertTrue(os.path.exists('.shelf/shelves/default/00~')) |
0.1.85
by Michael Ellerman
Add a test for delete |
286 |
self.assertTrue(os.path.exists('.shelf/shelves/default/01')) |
287 |
||
0.1.100
by Michael Ellerman
Backup the shelved patch when we delete in "shelf delete". |
288 |
# Check the backup is right
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
289 |
self._check_shelf('00~') |
0.1.100
by Michael Ellerman
Backup the shelved patch when we delete in "shelf delete". |
290 |
|
0.1.85
by Michael Ellerman
Add a test for delete |
291 |
# Check ls works
|
292 |
list = self.capture('shelf ls', retcode=0).split('\n') |
|
293 |
for line in list: |
|
294 |
self.assertFalse(line.startswith(' 00')) |
|
295 |
||
296 |
# Unshelve should unshelve 01
|
|
297 |
self.run_bzr('unshelve', '--all', retcode=0) |
|
298 |
self.assertEqual(file('test_file2').read(), self.MODIFIED) |
|
0.1.86
by Michael Ellerman
Add a test to make sure we can cope with gaps in the patch numbering. |
299 |
|
300 |
def test_shelf_gaps(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
301 |
self.tree = self.make_branch_and_tree('.') |
302 |
self.__create_and_add_test_file() |
|
0.1.86
by Michael Ellerman
Add a test to make sure we can cope with gaps in the patch numbering. |
303 |
file('test_file', 'w').write(self.MODIFIED) |
304 |
self.run_bzr('shelve', '--all', 'test_file', retcode=0) |
|
305 |
file('test_file', 'w').write(self.MODIFIED) |
|
306 |
self.run_bzr('shelve', '--all', 'test_file', retcode=0) |
|
307 |
||
308 |
# Now delete 00, leaving 01, next shelve should go into 02
|
|
309 |
self.run_bzr('shelf', 'delete', '0', retcode=0) |
|
310 |
self.assertFalse(os.path.exists('.shelf/shelves/default/00')) |
|
311 |
self.assertFalse(os.path.exists('.shelf/shelves/default/02')) |
|
312 |
file('test_file', 'w').write(self.MODIFIED) |
|
313 |
self.run_bzr('shelve', '--all', 'test_file', retcode=0) |
|
314 |
self.assertFalse(os.path.exists('.shelf/shelves/default/00')) |
|
315 |
self.assertTrue(os.path.exists('.shelf/shelves/default/02')) |
|
0.1.87
by Michael Ellerman
Add support for detecting and upgrading from old format shelves. |
316 |
|
317 |
def test_shelf_upgrade(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
318 |
self.tree = self.make_branch_and_tree('.') |
0.1.87
by Michael Ellerman
Add support for detecting and upgrading from old format shelves. |
319 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
320 |
self.__create_and_add_test_file() |
0.1.87
by Michael Ellerman
Add support for detecting and upgrading from old format shelves. |
321 |
|
322 |
# Modify then shelve, so we're not upgrading to 00, just for kicks
|
|
323 |
file('test_file', 'w').write(self.MODIFIED) |
|
324 |
self.run_bzr('shelve', '--all', 'test_file', retcode=0) |
|
325 |
||
326 |
open('.bzr-shelf', 'w').write('First old shelf') |
|
327 |
open('.bzr-shelf-1', 'w').write('Second old shelf') |
|
328 |
open('.bzr-shelf-3', 'w').write('Fourth old shelf') |
|
329 |
||
330 |
# shelve and unshelve should bitch and do nothing
|
|
331 |
file('test_file', 'w').write('blah blah blah') |
|
332 |
self.run_bzr('shelve', '--all', retcode=3) |
|
333 |
self.assertFalse(os.path.exists('.shelf/shelves/default/01')) |
|
334 |
self.assertEqual(file('test_file').read(), 'blah blah blah') |
|
335 |
self.run_bzr('unshelve', '--all', retcode=3) |
|
336 |
self.assertTrue(os.path.exists('.shelf/shelves/default/00')) |
|
337 |
||
338 |
# Upgrade, make sure it worked
|
|
339 |
self.run_bzr('shelf', 'upgrade', retcode=0) |
|
340 |
self.assertEqual(open('.shelf/shelves/default/01').read(), |
|
341 |
'First old shelf') |
|
342 |
self.assertEqual(open('.shelf/shelves/default/02').read(), |
|
343 |
'Second old shelf') |
|
344 |
self.assertEqual(open('.shelf/shelves/default/03').read(), |
|
345 |
'Fourth old shelf') |
|
346 |
||
347 |
# Check the old shelves got backed up right
|
|
348 |
self.assertTrue(os.path.exists('.bzr-shelf~')) |
|
349 |
self.assertTrue(os.path.exists('.bzr-shelf-1~')) |
|
350 |
self.assertTrue(os.path.exists('.bzr-shelf-3~')) |
|
351 |
self.assertFalse(os.path.exists('.bzr-shelf')) |
|
352 |
self.assertFalse(os.path.exists('.bzr-shelf-1')) |
|
353 |
self.assertFalse(os.path.exists('.bzr-shelf-3')) |
|
354 |
||
355 |
# Shelve should work now
|
|
356 |
self.run_bzr('shelve', '--all', retcode=0) |
|
0.1.89
by Michael Ellerman
Add support for unshelving -p0 patches, for backward compatibility. |
357 |
|
0.1.108
by Michael Ellerman
Update tests for -p0 format diffs by default. |
358 |
def test_shelf_p1_patch(self): |
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
359 |
self.tree = self.make_branch_and_tree('.') |
0.1.89
by Michael Ellerman
Add support for unshelving -p0 patches, for backward compatibility. |
360 |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
361 |
self.__create_and_add_test_file() |
0.1.89
by Michael Ellerman
Add support for unshelving -p0 patches, for backward compatibility. |
362 |
|
363 |
# Run a benign shelf command to setup .shelf for us
|
|
364 |
self.run_bzr('shelf', 'ls', retcode=0) |
|
365 |
||
366 |
# Fake a -p0 shelved patch
|
|
0.1.103
by Michael Ellerman
Add test machinery to cope with subdirectories. |
367 |
diff = self.DIFF_1 % { 'filename' : 'test_file' } |
0.1.108
by Michael Ellerman
Update tests for -p0 format diffs by default. |
368 |
diff = diff.replace('--- ', '--- a/') |
369 |
diff = diff.replace('+++ ', '+++ b/') |
|
0.1.89
by Michael Ellerman
Add support for unshelving -p0 patches, for backward compatibility. |
370 |
open('.shelf/shelves/default/00', 'w').write(diff) |
371 |
||
372 |
# This should work
|
|
373 |
self.run_bzr('unshelve', '--all', retcode=0) |
|
374 |
||
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
375 |
self._check_diff() |
0.1.98
by Michael Ellerman
Add a test for shelving in a subdirectory |
376 |
|
377 |
def test_shelf_shelve_in_subdir(self): |
|
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
378 |
self.tree = self.make_branch_and_tree('.') |
0.1.103
by Michael Ellerman
Add test machinery to cope with subdirectories. |
379 |
|
380 |
subdir = 'subdir' |
|
381 |
os.mkdir(subdir) |
|
382 |
self.tree.add(subdir) |
|
383 |
os.chdir(subdir) |
|
384 |
||
0.1.102
by Michael Ellerman
Factor out some common test functionality. |
385 |
self.__create_and_add_test_file() |
0.1.98
by Michael Ellerman
Add a test for shelving in a subdirectory |
386 |
|
387 |
# Modify the test file
|
|
388 |
file('test_file', 'w').write(self.MODIFIED) |
|
389 |
||
390 |
# Shelve the changes
|
|
391 |
self.run_bzr('shelve', '--all', retcode=0) |
|
392 |
||
393 |
# Working tree should be unchanged
|
|
394 |
diff = self.capture('diff', retcode=0) |
|
395 |
self.assertEqual(diff, '') |
|
396 |
||
397 |
# Unshelve, should succeed
|
|
398 |
self.run_bzr('unshelve', '--all', retcode=0) |
|
399 |
||
0.1.103
by Michael Ellerman
Add test machinery to cope with subdirectories. |
400 |
self._check_diff(filename='subdir/test_file') |
0.1.104
by Michael Ellerman
Use show_diff_trees() in BzrPatchSource, reduce the size of the v0.7 |
401 |
|
402 |
# Make sure relative filenames work ok
|
|
403 |
self.run_bzr('shelve', 'test_file', '--all', retcode=0) |
|
0.1.105
by Michael Ellerman
Error properly if we get an invalid subcommand for 'shelf'. |
404 |
|
405 |
def test_shelf_shelf_bogus_subcommand(self): |
|
406 |
self.tree = self.make_branch_and_tree('.') |
|
407 |
self.run_bzr('shelf', 'foo', retcode=3) # <- retcode == 3 |