bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
1 |
# Copyright (C) 2006, 2007 Canonical Ltd
|
|
1852.6.7
by Robert Collins
Fix up new tree_implementations __init__.py header. |
2 |
#
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
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.
|
|
|
1852.6.7
by Robert Collins
Fix up new tree_implementations __init__.py header. |
7 |
#
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
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.
|
|
|
1852.6.7
by Robert Collins
Fix up new tree_implementations __init__.py header. |
12 |
#
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
18 |
"""Tree implementation tests for bzr.
|
|
19 |
||
20 |
These test the conformance of all the tree variations to the expected API.
|
|
21 |
Specific tests for individual variations are in other places such as:
|
|
22 |
- tests/test_tree.py
|
|
23 |
- tests/test_revision.py
|
|
24 |
- tests/test_workingtree.py
|
|
25 |
- tests/workingtree_implementations/*.py.
|
|
26 |
"""
|
|
27 |
||
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
28 |
from bzrlib import ( |
29 |
errors, |
|
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
30 |
tests, |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
31 |
transform, |
32 |
)
|
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
33 |
from bzrlib.transport import get_transport |
34 |
from bzrlib.tests import ( |
|
35 |
adapt_modules, |
|
36 |
default_transport, |
|
37 |
TestCaseWithTransport, |
|
38 |
TestLoader, |
|
39 |
TestSuite, |
|
40 |
)
|
|
41 |
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir |
|
|
2079.1.1
by John Arbash Meinel
Create a deprecated bzrlib.tree.RevisionTree() in favor of bzrlib.revisiontree.RevisionTree() |
42 |
from bzrlib.revisiontree import RevisionTree |
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
43 |
from bzrlib.workingtree import (WorkingTreeFormat, |
44 |
WorkingTreeTestProviderAdapter, |
|
45 |
_legacy_formats, |
|
46 |
)
|
|
|
2255.2.64
by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations' |
47 |
from bzrlib.workingtree_4 import ( |
48 |
DirStateRevisionTree, |
|
49 |
WorkingTreeFormat4, |
|
50 |
)
|
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
51 |
|
52 |
||
53 |
def return_parameter(something): |
|
54 |
"""A trivial thunk to return its input.""" |
|
55 |
return something |
|
56 |
||
57 |
||
58 |
def revision_tree_from_workingtree(tree): |
|
59 |
"""Create a revision tree from a working tree.""" |
|
60 |
revid = tree.commit('save tree', allow_pointless=True) |
|
61 |
return tree.branch.repository.revision_tree(revid) |
|
62 |
||
63 |
||
|
2255.2.64
by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations' |
64 |
def _dirstate_tree_from_workingtree(tree): |
65 |
revid = tree.commit('save tree', allow_pointless=True) |
|
66 |
return tree.basis_tree() |
|
67 |
||
68 |
||
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
69 |
class TestTreeImplementationSupport(TestCaseWithTransport): |
70 |
||
71 |
def test_revision_tree_from_workingtree(self): |
|
72 |
tree = self.make_branch_and_tree('.') |
|
73 |
tree = revision_tree_from_workingtree(tree) |
|
74 |
self.assertIsInstance(tree, RevisionTree) |
|
75 |
||
76 |
||
77 |
class TestCaseWithTree(TestCaseWithBzrDir): |
|
78 |
||
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
79 |
def make_branch_and_tree(self, relpath): |
80 |
made_control = self.make_bzrdir(relpath, format= |
|
81 |
self.workingtree_format._matchingbzrdir) |
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
82 |
made_control.create_repository() |
83 |
made_control.create_branch() |
|
84 |
return self.workingtree_format.initialize(made_control) |
|
85 |
||
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
86 |
def _convert_tree(self, tree, converter=None): |
87 |
"""helper to convert using the converter or a supplied one.""" |
|
88 |
# convert that to the final shape
|
|
89 |
if converter is None: |
|
90 |
converter = self.workingtree_to_test_tree |
|
91 |
return converter(tree) |
|
92 |
||
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
93 |
def get_tree_no_parents_no_content(self, empty_tree, converter=None): |
94 |
"""Make a tree with no parents and no contents from empty_tree. |
|
95 |
|
|
96 |
:param empty_tree: A working tree with no content and no parents to
|
|
97 |
modify.
|
|
98 |
"""
|
|
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
99 |
empty_tree.set_root_id('empty-root-id') |
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
100 |
return self._convert_tree(empty_tree, converter) |
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
101 |
|
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
102 |
def _make_abc_tree(self, tree): |
103 |
"""setup an abc content tree.""" |
|
104 |
files = ['a', 'b/', 'b/c'] |
|
|
2255.2.15
by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing. |
105 |
self.build_tree(files, line_endings='binary', |
|
1982.1.4
by Alexander Belchenko
tree_implementations tests: build_tree with binary (LF) line-endings |
106 |
transport=tree.bzrdir.root_transport) |
|
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
107 |
tree.set_root_id('root-id') |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
108 |
tree.add(files, ['a-id', 'b-id', 'c-id']) |
109 |
||
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
110 |
def get_tree_no_parents_abc_content(self, tree, converter=None): |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
111 |
"""return a test tree with a, b/, b/c contents.""" |
112 |
self._make_abc_tree(tree) |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
113 |
return self._convert_tree(tree, converter) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
114 |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
115 |
def get_tree_no_parents_abc_content_2(self, tree, converter=None): |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
116 |
"""return a test tree with a, b/, b/c contents. |
117 |
|
|
118 |
This variation changes the content of 'a' to foobar\n.
|
|
119 |
"""
|
|
120 |
self._make_abc_tree(tree) |
|
121 |
f = open(tree.basedir + '/a', 'wb') |
|
122 |
try: |
|
123 |
f.write('foobar\n') |
|
124 |
finally: |
|
125 |
f.close() |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
126 |
return self._convert_tree(tree, converter) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
127 |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
128 |
def get_tree_no_parents_abc_content_3(self, tree, converter=None): |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
129 |
"""return a test tree with a, b/, b/c contents. |
130 |
|
|
131 |
This variation changes the executable flag of b/c to True.
|
|
132 |
"""
|
|
133 |
self._make_abc_tree(tree) |
|
134 |
tt = transform.TreeTransform(tree) |
|
135 |
trans_id = tt.trans_id_tree_path('b/c') |
|
136 |
tt.set_executability(True, trans_id) |
|
137 |
tt.apply() |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
138 |
return self._convert_tree(tree, converter) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
139 |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
140 |
def get_tree_no_parents_abc_content_4(self, tree, converter=None): |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
141 |
"""return a test tree with d, b/, b/c contents. |
142 |
|
|
143 |
This variation renames a to d.
|
|
144 |
"""
|
|
145 |
self._make_abc_tree(tree) |
|
146 |
tree.rename_one('a', 'd') |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
147 |
return self._convert_tree(tree, converter) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
148 |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
149 |
def get_tree_no_parents_abc_content_5(self, tree, converter=None): |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
150 |
"""return a test tree with d, b/, b/c contents. |
151 |
|
|
152 |
This variation renames a to d and alters its content to 'bar\n'.
|
|
153 |
"""
|
|
154 |
self._make_abc_tree(tree) |
|
155 |
tree.rename_one('a', 'd') |
|
156 |
f = open(tree.basedir + '/d', 'wb') |
|
157 |
try: |
|
158 |
f.write('bar\n') |
|
159 |
finally: |
|
160 |
f.close() |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
161 |
return self._convert_tree(tree, converter) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
162 |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
163 |
def get_tree_no_parents_abc_content_6(self, tree, converter=None): |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
164 |
"""return a test tree with a, b/, e contents. |
165 |
|
|
166 |
This variation renames b/c to e, and makes it executable.
|
|
167 |
"""
|
|
168 |
self._make_abc_tree(tree) |
|
169 |
tt = transform.TreeTransform(tree) |
|
170 |
trans_id = tt.trans_id_tree_path('b/c') |
|
171 |
parent_trans_id = tt.trans_id_tree_path('') |
|
172 |
tt.adjust_path('e', parent_trans_id, trans_id) |
|
173 |
tt.set_executability(True, trans_id) |
|
174 |
tt.apply() |
|
|
1852.8.7
by Robert Collins
Update tree_implementation test tree factories to be intertree ready. |
175 |
return self._convert_tree(tree, converter) |
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
176 |
|
|
1852.15.1
by Robert Collins
Add a complex test tree for use with Tree.walkdirs. |
177 |
def get_tree_with_subdirs_and_all_content_types(self): |
178 |
"""Return a test tree with subdirs and all content types. |
|
179 |
||
180 |
The returned tree has the following inventory:
|
|
181 |
[('', inventory.ROOT_ID),
|
|
182 |
('0file', '2file'),
|
|
183 |
('1top-dir', '1top-dir'),
|
|
184 |
(u'2utf\u1234file', u'0utf\u1234file'),
|
|
185 |
('symlink', 'symlink'),
|
|
186 |
('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
|
|
187 |
('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
|
|
188 |
where each component has the type of its name - i.e. '1file..' is afile.
|
|
189 |
||
190 |
note that the order of the paths and fileids is deliberately
|
|
191 |
mismatched to ensure that the result order is path based.
|
|
192 |
"""
|
|
193 |
tree = self.make_branch_and_tree('.') |
|
194 |
paths = ['0file', |
|
195 |
'1top-dir/', |
|
196 |
u'2utf\u1234file', |
|
197 |
'1top-dir/0file-in-1topdir', |
|
198 |
'1top-dir/1dir-in-1topdir/'
|
|
199 |
]
|
|
200 |
ids = [ |
|
201 |
'2file', |
|
202 |
'1top-dir', |
|
|
2255.2.107
by John Arbash Meinel
(working), fix dirstate to use utf8 file ids. |
203 |
u'0utf\u1234file'.encode('utf8'), |
|
1852.15.1
by Robert Collins
Add a complex test tree for use with Tree.walkdirs. |
204 |
'1file-in-1topdir', |
205 |
'0dir-in-1topdir'
|
|
206 |
]
|
|
207 |
self.build_tree(paths) |
|
208 |
tree.add(paths, ids) |
|
209 |
tt = transform.TreeTransform(tree) |
|
210 |
root_transaction_id = tt.trans_id_tree_path('') |
|
211 |
tt.new_symlink('symlink', |
|
212 |
root_transaction_id, 'link-target', 'symlink') |
|
213 |
tt.apply() |
|
214 |
return self.workingtree_to_test_tree(tree) |
|
215 |
||
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
216 |
def get_tree_with_utf8(self, tree): |
217 |
"""Generate a tree with a utf8 revision and unicode paths.""" |
|
|
2294.1.2
by John Arbash Meinel
Track down and add tests that all tree.commit() can handle |
218 |
self._create_tree_with_utf8(tree) |
219 |
return self.workingtree_to_test_tree(tree) |
|
220 |
||
221 |
def _create_tree_with_utf8(self, tree): |
|
222 |
"""Generate a tree with a utf8 revision and unicode paths.""" |
|
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
223 |
paths = [u'', |
224 |
u'f\xf6', |
|
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
225 |
u'b\xe5r/', |
226 |
u'b\xe5r/b\xe1z', |
|
227 |
]
|
|
228 |
# bzr itself does not create unicode file ids, but we want them for
|
|
229 |
# testing.
|
|
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
230 |
file_ids = [u'TREE_ROOT', |
|
2255.2.107
by John Arbash Meinel
(working), fix dirstate to use utf8 file ids. |
231 |
u'f\xf6-id'.encode('utf8'), |
232 |
u'b\xe5r-id'.encode('utf8'), |
|
233 |
u'b\xe1z-id'.encode('utf8'), |
|
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
234 |
]
|
235 |
try: |
|
|
2294.1.3
by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed. |
236 |
self.build_tree(paths[1:]) |
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
237 |
except UnicodeError: |
238 |
raise tests.TestSkipped('filesystem does not support unicode.') |
|
|
2255.2.107
by John Arbash Meinel
(working), fix dirstate to use utf8 file ids. |
239 |
if tree.path2id('') is None: |
240 |
# Some trees do not have a root yet.
|
|
241 |
tree.add(paths, file_ids) |
|
242 |
else: |
|
243 |
# Some trees will already have a root
|
|
244 |
tree.set_root_id(file_ids[0]) |
|
245 |
tree.add(paths[1:], file_ids[1:]) |
|
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
246 |
try: |
247 |
tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8')) |
|
248 |
except errors.NonAsciiRevisionId: |
|
249 |
raise tests.TestSkipped('non-ascii revision ids not supported') |
|
|
2294.1.2
by John Arbash Meinel
Track down and add tests that all tree.commit() can handle |
250 |
|
251 |
def get_tree_with_merged_utf8(self, tree): |
|
252 |
"""Generate a tree with utf8 ancestors.""" |
|
253 |
self._create_tree_with_utf8(tree) |
|
254 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
255 |
self.build_tree([u'tree2/b\xe5r/z\xf7z']) |
|
|
2255.2.107
by John Arbash Meinel
(working), fix dirstate to use utf8 file ids. |
256 |
tree2.add([u'b\xe5r/z\xf7z'], [u'z\xf7z-id'.encode('utf8')]) |
|
2294.1.2
by John Arbash Meinel
Track down and add tests that all tree.commit() can handle |
257 |
tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8')) |
258 |
||
259 |
tree.merge_from_branch(tree2.branch) |
|
260 |
tree.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8')) |
|
|
2294.1.1
by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic. |
261 |
return self.workingtree_to_test_tree(tree) |
262 |
||
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
263 |
|
264 |
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter): |
|
265 |
"""Generate test suites for each Tree implementation in bzrlib. |
|
266 |
||
267 |
Currently this covers all working tree formats, and RevisionTree by
|
|
268 |
committing a working tree to create the revision tree.
|
|
269 |
"""
|
|
270 |
||
271 |
def adapt(self, test): |
|
272 |
result = super(TreeTestProviderAdapter, self).adapt(test) |
|
273 |
for adapted_test in result: |
|
274 |
# for working tree adapted tests, preserve the tree
|
|
275 |
adapted_test.workingtree_to_test_tree = return_parameter |
|
276 |
default_format = WorkingTreeFormat.get_default_format() |
|
277 |
revision_tree_test = self._clone_test( |
|
278 |
test, |
|
279 |
default_format._matchingbzrdir, |
|
280 |
default_format, |
|
281 |
RevisionTree.__name__) |
|
282 |
revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree |
|
283 |
result.addTest(revision_tree_test) |
|
|
2255.2.64
by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations' |
284 |
dirstate_format = WorkingTreeFormat4() |
285 |
dirstate_revision_tree_test = self._clone_test( |
|
286 |
test, |
|
287 |
dirstate_format._matchingbzrdir, |
|
288 |
dirstate_format, |
|
289 |
DirStateRevisionTree.__name__) |
|
290 |
dirstate_revision_tree_test.workingtree_to_test_tree = _dirstate_tree_from_workingtree |
|
291 |
result.addTest(dirstate_revision_tree_test) |
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
292 |
return result |
293 |
||
294 |
||
295 |
def test_suite(): |
|
296 |
result = TestSuite() |
|
297 |
test_tree_implementations = [ |
|
|
2255.2.134
by John Arbash Meinel
Add a tree-test for get_symlink_target |
298 |
'bzrlib.tests.tree_implementations.test_get_symlink_target', |
|
2255.2.71
by John Arbash Meinel
Add a test for list_files, and implement it for DirStateRevisionTree |
299 |
'bzrlib.tests.tree_implementations.test_list_files', |
|
1908.11.5
by John Arbash Meinel
[merge] bzr.dev 2240 |
300 |
'bzrlib.tests.tree_implementations.test_revision_tree', |
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
301 |
'bzrlib.tests.tree_implementations.test_test_trees', |
|
1551.9.16
by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree |
302 |
'bzrlib.tests.tree_implementations.test_tree', |
|
1852.15.3
by Robert Collins
Add a first-cut Tree.walkdirs method. |
303 |
'bzrlib.tests.tree_implementations.test_walkdirs', |
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
304 |
]
|
305 |
adapter = TreeTestProviderAdapter( |
|
306 |
default_transport, |
|
307 |
# None here will cause a readonly decorator to be created
|
|
308 |
# by the TestCaseWithTransport.get_readonly_transport method.
|
|
309 |
None, |
|
310 |
[(format, format._matchingbzrdir) for format in |
|
311 |
WorkingTreeFormat._formats.values() + _legacy_formats]) |
|
312 |
loader = TestLoader() |
|
313 |
adapt_modules(test_tree_implementations, adapter, loader, result) |
|
314 |
result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations'])) |
|
315 |
return result |