0.16.89
by Aaron Bentley
Add tests for Shelver |
1 |
# Copyright (C) 2008 Canonical Ltd
|
2 |
#
|
|
0.16.101
by Aaron Bentley
Update GPL formatting and copyright |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
16 |
|
17 |
||
18 |
from cStringIO import StringIO |
|
0.16.91
by Aaron Bentley
Test finish and quit |
19 |
import os |
0.16.108
by Aaron Bentley
Shelf supports multiple diff writers. |
20 |
import sys |
0.16.89
by Aaron Bentley
Add tests for Shelver |
21 |
|
4595.9.5
by Aaron Bentley
Add expected failures for shelving root changes. |
22 |
from bzrlib import ( |
23 |
errors, |
|
24 |
shelf_ui, |
|
25 |
revision, |
|
26 |
tests, |
|
27 |
)
|
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
28 |
|
29 |
||
30 |
class ExpectShelver(shelf_ui.Shelver): |
|
31 |
"""A variant of Shelver that intercepts console activity, for testing."""
|
|
32 |
||
4100.3.4
by Aaron Bentley
Clean up signatures |
33 |
def __init__(self, work_tree, target_tree, diff_writer=None, |
34 |
auto=False, auto_apply=False, file_list=None, message=None, |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
35 |
destroy=False, reporter=None): |
0.16.108
by Aaron Bentley
Shelf supports multiple diff writers. |
36 |
shelf_ui.Shelver.__init__(self, work_tree, target_tree, diff_writer, |
4100.3.4
by Aaron Bentley
Clean up signatures |
37 |
auto, auto_apply, file_list, message, |
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
38 |
destroy, reporter=reporter) |
0.16.89
by Aaron Bentley
Add tests for Shelver |
39 |
self.expected = [] |
40 |
self.diff_writer = StringIO() |
|
41 |
||
42 |
def expect(self, prompt, response): |
|
43 |
self.expected.append((prompt, response)) |
|
44 |
||
45 |
def prompt(self, message): |
|
46 |
try: |
|
47 |
prompt, response = self.expected.pop(0) |
|
48 |
except IndexError: |
|
49 |
raise AssertionError('Unexpected prompt: %s' % message) |
|
50 |
if prompt != message: |
|
51 |
raise AssertionError('Wrong prompt: %s' % message) |
|
52 |
return response |
|
53 |
||
54 |
||
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
55 |
LINES_AJ = 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\n' |
56 |
||
57 |
||
58 |
LINES_ZY = 'z\nb\nc\nd\ne\nf\ng\nh\ni\ny\n' |
|
59 |
||
60 |
||
61 |
LINES_AY = 'a\nb\nc\nd\ne\nf\ng\nh\ni\ny\n' |
|
62 |
||
63 |
||
0.16.89
by Aaron Bentley
Add tests for Shelver |
64 |
class TestShelver(tests.TestCaseWithTransport): |
65 |
||
66 |
def create_shelvable_tree(self): |
|
67 |
tree = self.make_branch_and_tree('tree') |
|
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
68 |
self.build_tree_contents([('tree/foo', LINES_AJ)]) |
0.16.89
by Aaron Bentley
Add tests for Shelver |
69 |
tree.add('foo', 'foo-id') |
70 |
tree.commit('added foo') |
|
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
71 |
self.build_tree_contents([('tree/foo', LINES_ZY)]) |
0.16.89
by Aaron Bentley
Add tests for Shelver |
72 |
return tree |
73 |
||
74 |
def test_unexpected_prompt_failure(self): |
|
75 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
76 |
tree.lock_tree_write() |
77 |
self.addCleanup(tree.unlock) |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
78 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
79 |
e = self.assertRaises(AssertionError, shelver.run) |
|
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
80 |
self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e)) |
0.16.89
by Aaron Bentley
Add tests for Shelver |
81 |
|
82 |
def test_wrong_prompt_failure(self): |
|
83 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
84 |
tree.lock_tree_write() |
85 |
self.addCleanup(tree.unlock) |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
86 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
87 |
shelver.expect('foo', 'y') |
|
88 |
e = self.assertRaises(AssertionError, shelver.run) |
|
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
89 |
self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e)) |
0.16.89
by Aaron Bentley
Add tests for Shelver |
90 |
|
91 |
def test_shelve_not_diff(self): |
|
92 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
93 |
tree.lock_tree_write() |
94 |
self.addCleanup(tree.unlock) |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
95 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
96 |
shelver.expect('Shelve? [yNfq?]', 'n') |
97 |
shelver.expect('Shelve? [yNfq?]', 'n') |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
98 |
# No final shelving prompt because no changes were selected
|
99 |
shelver.run() |
|
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
100 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
0.16.89
by Aaron Bentley
Add tests for Shelver |
101 |
|
102 |
def test_shelve_diff_no(self): |
|
103 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
104 |
tree.lock_tree_write() |
105 |
self.addCleanup(tree.unlock) |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
106 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
107 |
shelver.expect('Shelve? [yNfq?]', 'y') |
108 |
shelver.expect('Shelve? [yNfq?]', 'y') |
|
109 |
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n') |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
110 |
shelver.run() |
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
111 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
0.16.89
by Aaron Bentley
Add tests for Shelver |
112 |
|
113 |
def test_shelve_diff(self): |
|
114 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
115 |
tree.lock_tree_write() |
116 |
self.addCleanup(tree.unlock) |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
117 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
118 |
shelver.expect('Shelve? [yNfq?]', 'y') |
119 |
shelver.expect('Shelve? [yNfq?]', 'y') |
|
120 |
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y') |
|
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
121 |
shelver.run() |
122 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
123 |
||
124 |
def test_shelve_one_diff(self): |
|
125 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
126 |
tree.lock_tree_write() |
127 |
self.addCleanup(tree.unlock) |
|
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
128 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
129 |
shelver.expect('Shelve? [yNfq?]', 'y') |
130 |
shelver.expect('Shelve? [yNfq?]', 'n') |
|
131 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
132 |
shelver.run() |
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
133 |
self.assertFileEqual(LINES_AY, 'tree/foo') |
0.16.89
by Aaron Bentley
Add tests for Shelver |
134 |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
135 |
def test_shelve_binary_change(self): |
136 |
tree = self.create_shelvable_tree() |
|
137 |
self.build_tree_contents([('tree/foo', '\x00')]) |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
138 |
tree.lock_tree_write() |
139 |
self.addCleanup(tree.unlock) |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
140 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
141 |
shelver.expect('Shelve binary changes? [yNfq?]', 'y') |
142 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
143 |
shelver.run() |
144 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
145 |
||
0.16.89
by Aaron Bentley
Add tests for Shelver |
146 |
def test_shelve_rename(self): |
147 |
tree = self.create_shelvable_tree() |
|
148 |
tree.rename_one('foo', 'bar') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
149 |
tree.lock_tree_write() |
150 |
self.addCleanup(tree.unlock) |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
151 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
152 |
shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y') |
153 |
shelver.expect('Shelve? [yNfq?]', 'y') |
|
154 |
shelver.expect('Shelve? [yNfq?]', 'y') |
|
155 |
shelver.expect('Shelve 3 change(s)? [yNfq?]', 'y') |
|
0.16.89
by Aaron Bentley
Add tests for Shelver |
156 |
shelver.run() |
0.16.90
by Aaron Bentley
Handle shelving multiple diff hunks |
157 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
0.16.91
by Aaron Bentley
Test finish and quit |
158 |
|
159 |
def test_shelve_deletion(self): |
|
160 |
tree = self.create_shelvable_tree() |
|
161 |
os.unlink('tree/foo') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
162 |
tree.lock_tree_write() |
163 |
self.addCleanup(tree.unlock) |
|
0.16.91
by Aaron Bentley
Test finish and quit |
164 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
165 |
shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y') |
166 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
|
0.16.91
by Aaron Bentley
Test finish and quit |
167 |
shelver.run() |
168 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
169 |
||
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
170 |
def test_shelve_creation(self): |
171 |
tree = self.make_branch_and_tree('tree') |
|
172 |
tree.commit('add tree root') |
|
173 |
self.build_tree(['tree/foo']) |
|
174 |
tree.add('foo') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
175 |
tree.lock_tree_write() |
176 |
self.addCleanup(tree.unlock) |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
177 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
178 |
shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y') |
179 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
180 |
shelver.run() |
181 |
self.failIfExists('tree/foo') |
|
182 |
||
183 |
def test_shelve_kind_change(self): |
|
184 |
tree = self.create_shelvable_tree() |
|
185 |
os.unlink('tree/foo') |
|
186 |
os.mkdir('tree/foo') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
187 |
tree.lock_tree_write() |
188 |
self.addCleanup(tree.unlock) |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
189 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
190 |
shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]', |
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
191 |
'y') |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
192 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
193 |
|
4119.5.1
by James Westby
Shelve can now shelve changes to a symlink's target. |
194 |
def test_shelve_modify_target(self): |
4526.6.12
by Aaron Bentley
Updates from review. |
195 |
self.requireFeature(tests.SymlinkFeature) |
4119.5.1
by James Westby
Shelve can now shelve changes to a symlink's target. |
196 |
tree = self.create_shelvable_tree() |
197 |
os.symlink('bar', 'tree/baz') |
|
198 |
tree.add('baz', 'baz-id') |
|
199 |
tree.commit("Add symlink") |
|
200 |
os.unlink('tree/baz') |
|
201 |
os.symlink('vax', 'tree/baz') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
202 |
tree.lock_tree_write() |
203 |
self.addCleanup(tree.unlock) |
|
4119.5.1
by James Westby
Shelve can now shelve changes to a symlink's target. |
204 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
205 |
shelver.expect('Shelve changing target of "baz" from "bar" to ' |
|
206 |
'"vax"? [yNfq?]', 'y') |
|
207 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
|
208 |
shelver.run() |
|
209 |
self.assertEqual('bar', os.readlink('tree/baz')) |
|
210 |
||
0.16.91
by Aaron Bentley
Test finish and quit |
211 |
def test_shelve_finish(self): |
212 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
213 |
tree.lock_tree_write() |
214 |
self.addCleanup(tree.unlock) |
|
0.16.91
by Aaron Bentley
Test finish and quit |
215 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
216 |
shelver.expect('Shelve? [yNfq?]', 'f') |
217 |
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y') |
|
0.16.91
by Aaron Bentley
Test finish and quit |
218 |
shelver.run() |
219 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
220 |
||
221 |
def test_shelve_quit(self): |
|
222 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
223 |
tree.lock_tree_write() |
224 |
self.addCleanup(tree.unlock) |
|
0.16.91
by Aaron Bentley
Test finish and quit |
225 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
226 |
shelver.expect('Shelve? [yNfq?]', 'q') |
0.16.103
by Aaron Bentley
raise UserAbort instead of doing sys.exit |
227 |
self.assertRaises(errors.UserAbort, shelver.run) |
0.16.91
by Aaron Bentley
Test finish and quit |
228 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
229 |
|
230 |
def test_shelve_all(self): |
|
231 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
232 |
shelver = ExpectShelver.from_args(sys.stdout, all=True, |
233 |
directory='tree') |
|
234 |
try: |
|
235 |
shelver.run() |
|
236 |
finally: |
|
237 |
shelver.work_tree.unlock() |
|
0.16.92
by Aaron Bentley
Test kind, add, binary, --all |
238 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
0.16.93
by Aaron Bentley
Test shelving one file |
239 |
|
240 |
def test_shelve_filename(self): |
|
241 |
tree = self.create_shelvable_tree() |
|
242 |
self.build_tree(['tree/bar']) |
|
243 |
tree.add('bar') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
244 |
tree.lock_tree_write() |
245 |
self.addCleanup(tree.unlock) |
|
0.16.93
by Aaron Bentley
Test shelving one file |
246 |
shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar']) |
3990.4.1
by Daniel Watkins
Changed all shelve tests to expect a '?'. |
247 |
shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y') |
248 |
shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y') |
|
0.16.93
by Aaron Bentley
Test shelving one file |
249 |
shelver.run() |
0.16.94
by Aaron Bentley
Add unshelve tests |
250 |
|
3990.4.2
by Daniel Watkins
Added test for help option. |
251 |
def test_shelve_help(self): |
252 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
253 |
tree.lock_tree_write() |
254 |
self.addCleanup(tree.unlock) |
|
3990.4.2
by Daniel Watkins
Added test for help option. |
255 |
shelver = ExpectShelver(tree, tree.basis_tree()) |
256 |
shelver.expect('Shelve? [yNfq?]', '?') |
|
257 |
shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f') |
|
258 |
shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y') |
|
259 |
shelver.run() |
|
260 |
||
4100.3.1
by Aaron Bentley
Implement shelve --destroy |
261 |
def test_shelve_distroy(self): |
262 |
tree = self.create_shelvable_tree() |
|
263 |
shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True, |
|
264 |
directory='tree', destroy=True) |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
265 |
try: |
266 |
shelver.run() |
|
267 |
finally: |
|
268 |
shelver.work_tree.unlock() |
|
4100.3.1
by Aaron Bentley
Implement shelve --destroy |
269 |
self.assertIs(None, tree.get_shelf_manager().last_shelf()) |
270 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
271 |
||
4595.9.5
by Aaron Bentley
Add expected failures for shelving root changes. |
272 |
@staticmethod
|
273 |
def shelve_all(tree, target_revision_id): |
|
274 |
tree.lock_write() |
|
275 |
try: |
|
276 |
target = tree.branch.repository.revision_tree(target_revision_id) |
|
277 |
shelver = shelf_ui.Shelver(tree, target, auto=True, |
|
278 |
auto_apply=True) |
|
279 |
shelver.run() |
|
280 |
finally: |
|
281 |
tree.unlock() |
|
282 |
||
283 |
def test_shelve_old_root_deleted(self): |
|
284 |
tree1 = self.make_branch_and_tree('tree1') |
|
285 |
tree1.commit('add root') |
|
286 |
tree2 = self.make_branch_and_tree('tree2') |
|
287 |
rev2 = tree2.commit('add root') |
|
288 |
tree1.merge_from_branch(tree2.branch, |
|
289 |
from_revision=revision.NULL_REVISION) |
|
290 |
tree1.commit('Replaced root entry') |
|
291 |
# This is essentially assertNotRaises(InconsistentDelta)
|
|
292 |
self.expectFailure('Cannot shelve replacing a root entry', |
|
293 |
self.assertRaises, AssertionError, |
|
294 |
self.assertRaises, errors.InconsistentDelta, |
|
295 |
self.shelve_all, tree1, rev2) |
|
296 |
||
297 |
def test_shelve_split(self): |
|
298 |
outer_tree = self.make_branch_and_tree('outer') |
|
299 |
outer_tree.commit('Add root') |
|
300 |
inner_tree = self.make_branch_and_tree('outer/inner') |
|
301 |
rev2 = inner_tree.commit('Add root') |
|
302 |
outer_tree.subsume(inner_tree) |
|
4595.9.6
by Aaron Bentley
Update from review. |
303 |
# This is essentially assertNotRaises(ValueError).
|
304 |
# The ValueError is 'None is not a valid file id'.
|
|
4595.9.5
by Aaron Bentley
Add expected failures for shelving root changes. |
305 |
self.expectFailure('Cannot shelve a join back to the inner tree.', |
306 |
self.assertRaises, AssertionError, |
|
307 |
self.assertRaises, ValueError, self.shelve_all, |
|
308 |
outer_tree, rev2) |
|
309 |
||
0.16.94
by Aaron Bentley
Add unshelve tests |
310 |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
311 |
class TestApplyReporter(TestShelver): |
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
312 |
|
313 |
def test_shelve_not_diff(self): |
|
314 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
315 |
tree.lock_tree_write() |
316 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
317 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
318 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
319 |
shelver.expect('Apply change? [yNfq?]', 'n') |
320 |
shelver.expect('Apply change? [yNfq?]', 'n') |
|
321 |
# No final shelving prompt because no changes were selected
|
|
322 |
shelver.run() |
|
323 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
|
324 |
||
325 |
def test_shelve_diff_no(self): |
|
326 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
327 |
tree.lock_tree_write() |
328 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
329 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
330 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
331 |
shelver.expect('Apply change? [yNfq?]', 'y') |
332 |
shelver.expect('Apply change? [yNfq?]', 'y') |
|
333 |
shelver.expect('Apply 2 change(s)? [yNfq?]', 'n') |
|
334 |
shelver.run() |
|
335 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
|
336 |
||
337 |
def test_shelve_diff(self): |
|
338 |
tree = self.create_shelvable_tree() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
339 |
tree.lock_tree_write() |
340 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
341 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
342 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
343 |
shelver.expect('Apply change? [yNfq?]', 'y') |
344 |
shelver.expect('Apply change? [yNfq?]', 'y') |
|
345 |
shelver.expect('Apply 2 change(s)? [yNfq?]', 'y') |
|
346 |
shelver.run() |
|
347 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
348 |
||
349 |
def test_shelve_binary_change(self): |
|
350 |
tree = self.create_shelvable_tree() |
|
351 |
self.build_tree_contents([('tree/foo', '\x00')]) |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
352 |
tree.lock_tree_write() |
353 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
354 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
355 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
356 |
shelver.expect('Apply binary changes? [yNfq?]', 'y') |
357 |
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y') |
|
358 |
shelver.run() |
|
359 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
360 |
||
361 |
def test_shelve_rename(self): |
|
362 |
tree = self.create_shelvable_tree() |
|
363 |
tree.rename_one('foo', 'bar') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
364 |
tree.lock_tree_write() |
365 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
366 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
367 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
368 |
shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y') |
369 |
shelver.expect('Apply change? [yNfq?]', 'y') |
|
370 |
shelver.expect('Apply change? [yNfq?]', 'y') |
|
371 |
shelver.expect('Apply 3 change(s)? [yNfq?]', 'y') |
|
372 |
shelver.run() |
|
373 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
374 |
||
375 |
def test_shelve_deletion(self): |
|
376 |
tree = self.create_shelvable_tree() |
|
377 |
os.unlink('tree/foo') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
378 |
tree.lock_tree_write() |
379 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
380 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
381 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
382 |
shelver.expect('Add file "foo"? [yNfq?]', 'y') |
383 |
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y') |
|
384 |
shelver.run() |
|
385 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
|
386 |
||
387 |
def test_shelve_creation(self): |
|
388 |
tree = self.make_branch_and_tree('tree') |
|
389 |
tree.commit('add tree root') |
|
390 |
self.build_tree(['tree/foo']) |
|
391 |
tree.add('foo') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
392 |
tree.lock_tree_write() |
393 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
394 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
395 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
396 |
shelver.expect('Delete file "foo"? [yNfq?]', 'y') |
397 |
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y') |
|
398 |
shelver.run() |
|
399 |
self.failIfExists('tree/foo') |
|
400 |
||
401 |
def test_shelve_kind_change(self): |
|
402 |
tree = self.create_shelvable_tree() |
|
403 |
os.unlink('tree/foo') |
|
404 |
os.mkdir('tree/foo') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
405 |
tree.lock_tree_write() |
406 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
407 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
408 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
409 |
shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y') |
410 |
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y') |
|
411 |
||
412 |
def test_shelve_modify_target(self): |
|
4526.6.12
by Aaron Bentley
Updates from review. |
413 |
self.requireFeature(tests.SymlinkFeature) |
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
414 |
tree = self.create_shelvable_tree() |
415 |
os.symlink('bar', 'tree/baz') |
|
416 |
tree.add('baz', 'baz-id') |
|
417 |
tree.commit("Add symlink") |
|
418 |
os.unlink('tree/baz') |
|
419 |
os.symlink('vax', 'tree/baz') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
420 |
tree.lock_tree_write() |
421 |
self.addCleanup(tree.unlock) |
|
4526.7.1
by Aaron Bentley
Make vocabulary part of reporter. |
422 |
shelver = ExpectShelver(tree, tree.basis_tree(), |
423 |
reporter=shelf_ui.ApplyReporter()) |
|
4526.6.1
by Aaron Bentley
Reverse the way changes are described by Shelver. |
424 |
shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]', |
425 |
'y') |
|
426 |
shelver.expect('Apply 1 change(s)? [yNfq?]', 'y') |
|
427 |
shelver.run() |
|
428 |
self.assertEqual('bar', os.readlink('tree/baz')) |
|
429 |
||
430 |
||
0.16.94
by Aaron Bentley
Add unshelve tests |
431 |
class TestUnshelver(tests.TestCaseWithTransport): |
432 |
||
433 |
def create_tree_with_shelf(self): |
|
434 |
tree = self.make_branch_and_tree('tree') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
435 |
tree.lock_write() |
436 |
try: |
|
437 |
self.build_tree_contents([('tree/foo', LINES_AJ)]) |
|
438 |
tree.add('foo', 'foo-id') |
|
439 |
tree.commit('added foo') |
|
440 |
self.build_tree_contents([('tree/foo', LINES_ZY)]) |
|
441 |
shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True, |
|
442 |
auto=True).run() |
|
443 |
finally: |
|
444 |
tree.unlock() |
|
0.16.94
by Aaron Bentley
Add unshelve tests |
445 |
return tree |
446 |
||
447 |
def test_unshelve(self): |
|
448 |
tree = self.create_tree_with_shelf() |
|
449 |
tree.lock_write() |
|
450 |
self.addCleanup(tree.unlock) |
|
451 |
manager = tree.get_shelf_manager() |
|
452 |
shelf_ui.Unshelver(tree, manager, 1, True, True, True).run() |
|
453 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
|
454 |
||
455 |
def test_unshelve_args(self): |
|
456 |
tree = self.create_tree_with_shelf() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
457 |
unshelver = shelf_ui.Unshelver.from_args(directory='tree') |
458 |
try: |
|
459 |
unshelver.run() |
|
460 |
finally: |
|
461 |
unshelver.tree.unlock() |
|
0.16.94
by Aaron Bentley
Add unshelve tests |
462 |
self.assertFileEqual(LINES_ZY, 'tree/foo') |
463 |
self.assertIs(None, tree.get_shelf_manager().last_shelf()) |
|
464 |
||
465 |
def test_unshelve_args_dry_run(self): |
|
466 |
tree = self.create_tree_with_shelf() |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
467 |
unshelver = shelf_ui.Unshelver.from_args(directory='tree', |
468 |
action='dry-run') |
|
469 |
try: |
|
470 |
unshelver.run() |
|
471 |
finally: |
|
472 |
unshelver.tree.unlock() |
|
0.16.94
by Aaron Bentley
Add unshelve tests |
473 |
self.assertFileEqual(LINES_AJ, 'tree/foo') |
474 |
self.assertEqual(1, tree.get_shelf_manager().last_shelf()) |
|
475 |
||
476 |
def test_unshelve_args_delete_only(self): |
|
477 |
tree = self.make_branch_and_tree('tree') |
|
478 |
manager = tree.get_shelf_manager() |
|
479 |
shelf_file = manager.new_shelf()[1] |
|
480 |
try: |
|
481 |
shelf_file.write('garbage') |
|
482 |
finally: |
|
483 |
shelf_file.close() |
|
484 |
unshelver = shelf_ui.Unshelver.from_args(directory='tree', |
|
485 |
action='delete-only') |
|
4595.13.2
by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006) |
486 |
try: |
487 |
unshelver.run() |
|
488 |
finally: |
|
489 |
unshelver.tree.unlock() |
|
0.16.94
by Aaron Bentley
Add unshelve tests |
490 |
self.assertIs(None, manager.last_shelf()) |
3990.2.1
by Daniel Watkins
Added test for unshelve being passed an invalid shelf_id. |
491 |
|
492 |
def test_unshelve_args_invalid_shelf_id(self): |
|
493 |
tree = self.make_branch_and_tree('tree') |
|
494 |
manager = tree.get_shelf_manager() |
|
495 |
shelf_file = manager.new_shelf()[1] |
|
496 |
try: |
|
497 |
shelf_file.write('garbage') |
|
498 |
finally: |
|
499 |
shelf_file.close() |
|
500 |
self.assertRaises(errors.InvalidShelfId, |
|
3999.1.1
by Ian Clatworthy
Improve shelf documentation & fix backtrace (Daniel Watkins) |
501 |
shelf_ui.Unshelver.from_args, directory='tree', |
502 |
action='delete-only', shelf_id='foo') |