163
181
return self._convert_tree(tree, converter)
183
def get_tree_with_subdirs_and_all_content_types(self):
184
"""Return a test tree with subdirs and all content types.
185
See get_tree_with_subdirs_and_all_supported_content_types for details.
187
return self.get_tree_with_subdirs_and_all_supported_content_types(True)
189
def get_tree_with_subdirs_and_all_supported_content_types(self, symlinks):
190
"""Return a test tree with subdirs and all supported content types.
191
Some content types may not be created on some platforms
192
(like symlinks on native win32)
194
:param symlinks: control is symlink should be created in the tree.
195
Note: if you wish to automatically set this
196
parameters depending on underlying system,
197
please use value returned
198
by bzrlib.osutils.has_symlinks() function.
200
The returned tree has the following inventory:
201
[('', inventory.ROOT_ID),
203
('1top-dir', '1top-dir'),
204
(u'2utf\u1234file', u'0utf\u1234file'),
205
('symlink', 'symlink'), # only if symlinks arg is True
206
('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
207
('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
208
where each component has the type of its name -
209
i.e. '1file..' is afile.
211
note that the order of the paths and fileids is deliberately
212
mismatched to ensure that the result order is path based.
214
tree = self.make_branch_and_tree('.')
218
'1top-dir/0file-in-1topdir',
219
'1top-dir/1dir-in-1topdir/'
224
u'0utf\u1234file'.encode('utf8'),
229
self.build_tree(paths)
232
'This platform does not support unicode file paths.')
234
tt = transform.TreeTransform(tree)
236
root_transaction_id = tt.trans_id_tree_path('')
237
tt.new_symlink('symlink',
238
root_transaction_id, 'link-target', 'symlink')
240
return self.workingtree_to_test_tree(tree)
242
def get_tree_with_utf8(self, tree):
243
"""Generate a tree with a utf8 revision and unicode paths."""
244
self._create_tree_with_utf8(tree)
245
return self.workingtree_to_test_tree(tree)
247
def _create_tree_with_utf8(self, tree):
248
"""Generate a tree with a utf8 revision and unicode paths."""
254
# bzr itself does not create unicode file ids, but we want them for
256
file_ids = ['TREE_ROOT',
262
self.build_tree(paths[1:])
264
raise tests.TestSkipped('filesystem does not support unicode.')
265
if tree.path2id('') is None:
266
# Some trees do not have a root yet.
267
tree.add(paths, file_ids)
269
# Some trees will already have a root
270
tree.set_root_id(file_ids[0])
271
tree.add(paths[1:], file_ids[1:])
273
tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
274
except errors.NonAsciiRevisionId:
275
raise tests.TestSkipped('non-ascii revision ids not supported')
277
def get_tree_with_merged_utf8(self, tree):
278
"""Generate a tree with utf8 ancestors."""
279
self._create_tree_with_utf8(tree)
280
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
281
self.build_tree([u'tree2/b\xe5r/z\xf7z'])
282
self.callDeprecated([osutils._file_id_warning],
283
tree2.add, [u'b\xe5r/z\xf7z'], [u'z\xf7z-id'])
284
tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
286
tree.merge_from_branch(tree2.branch)
287
tree.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
288
return self.workingtree_to_test_tree(tree)
166
291
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
167
292
"""Generate test suites for each Tree implementation in bzrlib.
169
Currently this covers all working tree formats, and RevisionTree by
170
committing a working tree to create the revision tree.
294
Currently this covers all working tree formats, and RevisionTree and
295
DirStateRevisionTree by committing a working tree to create the revision
173
def adapt(self, test):
174
result = super(TreeTestProviderAdapter, self).adapt(test)
175
for adapted_test in result:
299
def __init__(self, transport_server, transport_readonly_server, formats):
300
super(TreeTestProviderAdapter, self).__init__(transport_server,
301
transport_readonly_server, formats)
302
# now adjust the scenarios and add the non-working-tree tree scenarios.
303
for scenario in self.scenarios:
176
304
# for working tree adapted tests, preserve the tree
177
adapted_test.workingtree_to_test_tree = return_parameter
178
default_format = WorkingTreeFormat.get_default_format()
179
revision_tree_test = self._clone_test(
181
default_format._matchingbzrdir,
183
RevisionTree.__name__)
184
revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
185
result.addTest(revision_tree_test)
305
scenario[1]["workingtree_to_test_tree"] = return_parameter
306
# add RevisionTree scenario
307
# this is the 'default format' in that it's used to test the generic InterTree
309
default_format = WorkingTreeFormat3()
310
self.scenarios.append(self.formats_to_scenarios([
311
(default_format, default_format._matchingbzrdir)])[0])
312
self.scenarios[-1] = (RevisionTree.__name__, self.scenarios[-1][1])
313
self.scenarios[-1][1]["workingtree_to_test_tree"] = revision_tree_from_workingtree
315
# also test WorkingTree4's RevisionTree implementation which is specialised.
316
dirstate_format = WorkingTreeFormat4()
317
self.scenarios.append(self.formats_to_scenarios([
318
(dirstate_format, dirstate_format._matchingbzrdir)])[0])
319
self.scenarios[-1] = (DirStateRevisionTree.__name__, self.scenarios[-1][1])
320
self.scenarios[-1][1]["workingtree_to_test_tree"] = _dirstate_tree_from_workingtree
189
323
def test_suite():
190
324
result = TestSuite()
191
325
test_tree_implementations = [
326
'bzrlib.tests.tree_implementations.test_get_file_mtime',
327
'bzrlib.tests.tree_implementations.test_get_symlink_target',
328
'bzrlib.tests.tree_implementations.test_inv',
329
'bzrlib.tests.tree_implementations.test_list_files',
330
'bzrlib.tests.tree_implementations.test_revision_tree',
192
331
'bzrlib.tests.tree_implementations.test_test_trees',
332
'bzrlib.tests.tree_implementations.test_tree',
333
'bzrlib.tests.tree_implementations.test_walkdirs',
194
335
adapter = TreeTestProviderAdapter(
195
336
default_transport,