bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2255.2.137
by John Arbash Meinel
Move the WorkingTree.move() tests into their own module |
1 |
# Copyright (C) 2006 Canonical Ltd
|
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
"""Tests for interface conformance of 'workingtree.put_mkdir'"""
|
|
19 |
||
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
20 |
import os |
21 |
||
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
22 |
from bzrlib import ( |
23 |
errors, |
|
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
24 |
osutils, |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
25 |
)
|
26 |
||
|
2255.2.137
by John Arbash Meinel
Move the WorkingTree.move() tests into their own module |
27 |
from bzrlib.workingtree_4 import WorkingTreeFormat4 |
28 |
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree |
|
29 |
||
30 |
||
31 |
class TestMove(TestCaseWithWorkingTree): |
|
32 |
||
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
33 |
def get_tree_layout(self, tree): |
34 |
"""Get the (path, file_id) pairs for the current tree.""" |
|
35 |
tree.lock_read() |
|
36 |
try: |
|
37 |
return [(path, ie.file_id) for path, ie |
|
38 |
in tree.iter_entries_by_dir()] |
|
39 |
finally: |
|
40 |
tree.unlock() |
|
41 |
||
42 |
def assertTreeLayout(self, expected, tree): |
|
43 |
"""Check that the tree has the correct layout.""" |
|
44 |
actual = self.get_tree_layout(tree) |
|
45 |
self.assertEqual(expected, actual) |
|
46 |
||
|
2255.2.137
by John Arbash Meinel
Move the WorkingTree.move() tests into their own module |
47 |
def test_move_correct_call_named(self): |
48 |
"""tree.move has the deprecated parameter 'to_name'. |
|
49 |
It has been replaced by 'to_dir' for consistency.
|
|
50 |
Test the new API using named parameter
|
|
51 |
"""
|
|
52 |
self.build_tree(['a1', 'sub1/']) |
|
53 |
tree = self.make_branch_and_tree('.') |
|
54 |
tree.add(['a1', 'sub1']) |
|
55 |
tree.commit('initial commit') |
|
56 |
tree.move(['a1'], to_dir='sub1', after=False) |
|
57 |
||
58 |
def test_move_correct_call_unnamed(self): |
|
59 |
"""tree.move has the deprecated parameter 'to_name'. |
|
60 |
It has been replaced by 'to_dir' for consistency.
|
|
61 |
Test the new API using unnamed parameter
|
|
62 |
"""
|
|
63 |
self.build_tree(['a1', 'sub1/']) |
|
64 |
tree = self.make_branch_and_tree('.') |
|
65 |
tree.add(['a1', 'sub1']) |
|
66 |
tree.commit('initial commit') |
|
67 |
tree.move(['a1'], 'sub1', after=False) |
|
68 |
||
69 |
def test_move_deprecated_wrong_call(self): |
|
70 |
"""tree.move has the deprecated parameter 'to_name'. |
|
71 |
It has been replaced by 'to_dir' for consistency.
|
|
72 |
Test the new API using wrong parameter
|
|
73 |
"""
|
|
74 |
self.build_tree(['a1', 'sub1/']) |
|
75 |
tree = self.make_branch_and_tree('.') |
|
76 |
tree.add(['a1', 'sub1']) |
|
77 |
tree.commit('initial commit') |
|
78 |
self.assertRaises(TypeError, tree.move, ['a1'], |
|
79 |
to_this_parameter_does_not_exist='sub1', |
|
80 |
after=False) |
|
81 |
||
82 |
def test_move_deprecated_call(self): |
|
83 |
"""tree.move has the deprecated parameter 'to_name'. |
|
84 |
It has been replaced by 'to_dir' for consistency.
|
|
85 |
Test the new API using deprecated parameter
|
|
86 |
"""
|
|
87 |
self.build_tree(['a1', 'sub1/']) |
|
88 |
tree = self.make_branch_and_tree('.') |
|
89 |
tree.add(['a1', 'sub1']) |
|
90 |
tree.commit('initial commit') |
|
91 |
||
92 |
try: |
|
93 |
self.callDeprecated(['The parameter to_name was deprecated' |
|
94 |
' in version 0.13. Use to_dir instead'], |
|
95 |
tree.move, ['a1'], to_name='sub1', |
|
96 |
after=False) |
|
97 |
except TypeError: |
|
98 |
# WorkingTreeFormat4 doesn't have to maintain api compatibility
|
|
99 |
# since it was deprecated before the class was introduced.
|
|
100 |
if not isinstance(self.workingtree_format, WorkingTreeFormat4): |
|
101 |
raise
|
|
102 |
||
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
103 |
def test_move_target_not_dir(self): |
104 |
tree = self.make_branch_and_tree('.') |
|
105 |
self.build_tree(['a']) |
|
106 |
tree.add(['a']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
107 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
108 |
|
109 |
self.assertRaises(errors.BzrMoveFailedError, |
|
110 |
tree.move, ['a'], 'not-a-dir') |
|
111 |
||
112 |
def test_move_non_existent(self): |
|
113 |
tree = self.make_branch_and_tree('.') |
|
114 |
self.build_tree(['a/']) |
|
115 |
tree.add(['a']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
116 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
117 |
self.assertRaises(errors.BzrMoveFailedError, |
118 |
tree.move, ['not-a-file'], 'a') |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
119 |
self.assertRaises(errors.BzrMoveFailedError, |
120 |
tree.move, ['not-a-file'], '') |
|
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
121 |
|
122 |
def test_move_target_not_versioned(self): |
|
123 |
tree = self.make_branch_and_tree('.') |
|
124 |
self.build_tree(['a/', 'b']) |
|
125 |
tree.add(['b']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
126 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
127 |
self.assertRaises(errors.BzrMoveFailedError, |
128 |
tree.move, ['b'], 'a') |
|
129 |
||
130 |
# TODO: jam 20070225 What about a test when the target is now a directory,
|
|
131 |
# but in the past it was a file. Theoretically WorkingTree should
|
|
132 |
# notice the kind change.
|
|
133 |
||
134 |
def test_move_unversioned(self): |
|
135 |
tree = self.make_branch_and_tree('.') |
|
136 |
self.build_tree(['a/', 'b']) |
|
137 |
tree.add(['a']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
138 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
139 |
self.assertRaises(errors.BzrMoveFailedError, |
140 |
tree.move, ['b'], 'a') |
|
141 |
||
142 |
def test_move_multi_unversioned(self): |
|
143 |
tree = self.make_branch_and_tree('.') |
|
144 |
self.build_tree(['a/', 'b', 'c', 'd']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
145 |
tree.add(['a', 'c', 'd'], ['a-id', 'c-id', 'd-id']) |
146 |
tree.commit('initial', rev_id='rev-1') |
|
147 |
root_id = tree.get_root_id() |
|
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
148 |
self.assertRaises(errors.BzrMoveFailedError, |
149 |
tree.move, ['c', 'b', 'd'], 'a') |
|
150 |
self.assertRaises(errors.BzrMoveFailedError, |
|
151 |
tree.move, ['b', 'c', 'd'], 'a') |
|
152 |
self.assertRaises(errors.BzrMoveFailedError, |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
153 |
tree.move, ['d', 'c', 'b'], 'a') |
154 |
if osutils.lexists('a/c'): |
|
155 |
# If 'c' was actually moved, then 'd' should have also been moved
|
|
156 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), |
|
157 |
('a/c', 'c-id'), ('a/d', 'd-id')], tree) |
|
158 |
else: |
|
159 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'), |
|
160 |
('d', 'd-id')], tree) |
|
161 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'), |
|
162 |
('d', 'd-id')], tree.basis_tree()) |
|
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
163 |
|
164 |
def test_move_subdir(self): |
|
165 |
tree = self.make_branch_and_tree('.') |
|
166 |
self.build_tree(['a', 'b/', 'b/c']) |
|
167 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
168 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
169 |
root_id = tree.get_root_id() |
170 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
|
171 |
('b/c', 'c-id')], tree) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
172 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
173 |
('b/c', 'c-id')], tree.basis_tree()) |
|
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
174 |
a_contents = tree.get_file_text('a-id') |
175 |
tree.move(['a'], 'b') |
|
176 |
self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'), |
|
177 |
('b/c', 'c-id')], tree) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
178 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
179 |
('b/c', 'c-id')], tree.basis_tree()) |
|
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
180 |
self.failIfExists('a') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
181 |
self.assertFileEqual(a_contents, 'b/a') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
182 |
|
183 |
def test_move_parent_dir(self): |
|
184 |
tree = self.make_branch_and_tree('.') |
|
185 |
self.build_tree(['a', 'b/', 'b/c']) |
|
186 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
187 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
188 |
root_id = tree.get_root_id() |
189 |
c_contents = tree.get_file_text('c-id') |
|
190 |
tree.move(['b/c'], '') |
|
191 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
|
192 |
('c', 'c-id')], tree) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
193 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
194 |
('b/c', 'c-id')], tree.basis_tree()) |
|
|
2255.2.138
by John Arbash Meinel
implement several new WorkingTree.move() tests |
195 |
self.failIfExists('b/c') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
196 |
self.assertFileEqual(c_contents, 'c') |
197 |
||
198 |
def test_move_fail_consistent(self): |
|
199 |
tree = self.make_branch_and_tree('.') |
|
200 |
self.build_tree(['a', 'b/', 'b/a', 'c']) |
|
201 |
tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
202 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
203 |
root_id = tree.get_root_id() |
204 |
# Target already exists
|
|
205 |
self.assertRaises(errors.RenameFailedFilesExist, |
|
206 |
tree.move, ['c', 'a'], 'b') |
|
207 |
# 'c' may or may not have been moved, but either way the tree should
|
|
208 |
# maintain a consistent state.
|
|
209 |
if osutils.lexists('c'): |
|
210 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
|
211 |
('c', 'c-id')], tree) |
|
212 |
else: |
|
213 |
self.failUnlessExists('b/c') |
|
214 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
|
215 |
('b/c', 'c-id')], tree) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
216 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'), |
217 |
('c', 'c-id')], tree.basis_tree()) |
|
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
218 |
|
219 |
def test_move_onto_self(self): |
|
220 |
tree = self.make_branch_and_tree('.') |
|
221 |
self.build_tree(['b/', 'b/a']) |
|
222 |
tree.add(['b', 'b/a'], ['b-id', 'a-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
223 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
224 |
|
225 |
self.assertRaises(errors.BzrMoveFailedError, |
|
226 |
tree.move, ['b/a'], 'b') |
|
227 |
||
228 |
def test_move_onto_self_root(self): |
|
229 |
tree = self.make_branch_and_tree('.') |
|
230 |
self.build_tree(['a']) |
|
231 |
tree.add(['a'], ['a-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
232 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
233 |
|
234 |
self.assertRaises(errors.BzrMoveFailedError, |
|
235 |
tree.move, ['a'], 'a') |
|
236 |
||
237 |
def test_move_after(self): |
|
238 |
tree = self.make_branch_and_tree('.') |
|
239 |
self.build_tree(['a', 'b/']) |
|
240 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
241 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
242 |
root_id = tree.get_root_id() |
243 |
os.rename('a', 'b/a') |
|
244 |
||
245 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
|
246 |
tree) |
|
247 |
# We don't need after=True as long as source is missing and target
|
|
248 |
# exists.
|
|
249 |
tree.move(['a'], 'b') |
|
250 |
self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')], |
|
251 |
tree) |
|
|
2255.2.141
by John Arbash Meinel
Some small changes to move tests. |
252 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
253 |
tree.basis_tree()) |
|
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
254 |
|
255 |
def test_move_after_with_after(self): |
|
256 |
tree = self.make_branch_and_tree('.') |
|
257 |
self.build_tree(['a', 'b/']) |
|
258 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
259 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
260 |
root_id = tree.get_root_id() |
261 |
os.rename('a', 'b/a') |
|
262 |
||
263 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
|
264 |
tree) |
|
265 |
# Passing after=True should work as well
|
|
266 |
tree.move(['a'], 'b', after=True) |
|
267 |
self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')], |
|
268 |
tree) |
|
|
2255.2.141
by John Arbash Meinel
Some small changes to move tests. |
269 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
270 |
tree.basis_tree()) |
|
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
271 |
|
272 |
def test_move_after_no_target(self): |
|
273 |
tree = self.make_branch_and_tree('.') |
|
274 |
self.build_tree(['a', 'b/']) |
|
275 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
276 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
277 |
root_id = tree.get_root_id() |
278 |
||
279 |
# Passing after when the file hasn't been move raises an exception
|
|
280 |
self.assertRaises(errors.BzrMoveFailedError, |
|
281 |
tree.move, ['a'], 'b', after=True) |
|
|
2255.2.141
by John Arbash Meinel
Some small changes to move tests. |
282 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
283 |
tree.basis_tree()) |
|
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
284 |
|
285 |
def test_move_after_source_and_dest(self): |
|
286 |
tree = self.make_branch_and_tree('.') |
|
287 |
self.build_tree(['a', 'b/', 'b/a']) |
|
288 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
|
2255.2.140
by John Arbash Meinel
Update tests to ensure basis tree is not modified |
289 |
tree.commit('initial', rev_id='rev-1') |
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
290 |
root_id = tree.get_root_id() |
291 |
||
292 |
# TODO: jam 20070225 I would usually use 'rb', but assertFileEqual
|
|
293 |
# uses 'r'.
|
|
294 |
a_file = open('a', 'r') |
|
295 |
try: |
|
296 |
a_text = a_file.read() |
|
297 |
finally: |
|
298 |
a_file.close() |
|
299 |
ba_file = open('b/a', 'r') |
|
300 |
try: |
|
301 |
ba_text = ba_file.read() |
|
302 |
finally: |
|
303 |
ba_file.close() |
|
304 |
||
305 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
|
306 |
tree) |
|
307 |
self.assertRaises(errors.RenameFailedFilesExist, |
|
308 |
tree.move, ['a'], 'b', after=False) |
|
309 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
|
310 |
tree) |
|
311 |
self.assertFileEqual(a_text, 'a') |
|
312 |
self.assertFileEqual(ba_text, 'b/a') |
|
313 |
# But you can pass after=True
|
|
314 |
tree.move(['a'], 'b', after=True) |
|
315 |
self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')], |
|
316 |
tree) |
|
|
2255.2.141
by John Arbash Meinel
Some small changes to move tests. |
317 |
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')], |
318 |
tree.basis_tree()) |
|
|
2255.2.139
by John Arbash Meinel
test cases for moving after a file has already been moved. |
319 |
# But it shouldn't actually move anything
|
320 |
self.assertFileEqual(a_text, 'a') |
|
321 |
self.assertFileEqual(ba_text, 'b/a') |
|
|
2255.2.146
by John Arbash Meinel
Implement move_directory by factoring out move_one |
322 |
|
323 |
def test_move_directory(self): |
|
324 |
tree = self.make_branch_and_tree('.') |
|
325 |
self.build_tree(['a/', 'a/b', 'a/c/', 'a/c/d', 'e/']) |
|
326 |
tree.add(['a', 'a/b', 'a/c', 'a/c/d', 'e'], |
|
327 |
['a-id', 'b-id', 'c-id', 'd-id', 'e-id']) |
|
328 |
tree.commit('initial', rev_id='rev-1') |
|
329 |
root_id = tree.get_root_id() |
|
330 |
||
331 |
tree.move(['a'], 'e') |
|
332 |
self.assertTreeLayout([('', root_id), ('e', 'e-id'), ('e/a', 'a-id'), |
|
333 |
('e/a/b', 'b-id'), ('e/a/c', 'c-id'), |
|
334 |
('e/a/c/d', 'd-id')], tree) |