36
38
TestCaseWithTransport,
40
41
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
41
from bzrlib.tree import RevisionTree
42
from bzrlib.workingtree import (WorkingTreeFormat,
43
WorkingTreeTestProviderAdapter,
48
def return_parameter(something):
42
from bzrlib.tests.workingtree_implementations import (
43
WorkingTreeTestProviderAdapter,
45
from bzrlib.revisiontree import RevisionTree
46
from bzrlib.transform import TransformPreview
47
from bzrlib.workingtree import (
52
from bzrlib.workingtree_4 import (
58
def return_parameter(testcase, something):
49
59
"""A trivial thunk to return its input."""
53
def revision_tree_from_workingtree(tree):
63
def revision_tree_from_workingtree(testcase, tree):
54
64
"""Create a revision tree from a working tree."""
55
revid = tree.commit('save tree', allow_pointless=True)
65
revid = tree.commit('save tree', allow_pointless=True, recursive=None)
56
66
return tree.branch.repository.revision_tree(revid)
69
def _dirstate_tree_from_workingtree(testcase, tree):
70
revid = tree.commit('save tree', allow_pointless=True, recursive=None)
71
return tree.basis_tree()
74
def preview_tree_pre(testcase, tree):
75
tt = TransformPreview(tree)
76
testcase.addCleanup(tt.finalize)
77
preview_tree = tt.get_preview_tree()
78
preview_tree.set_parent_ids(tree.get_parent_ids())
59
82
class TestTreeImplementationSupport(TestCaseWithTransport):
61
84
def test_revision_tree_from_workingtree(self):
62
85
tree = self.make_branch_and_tree('.')
63
tree = revision_tree_from_workingtree(tree)
86
tree = revision_tree_from_workingtree(self, tree)
64
87
self.assertIsInstance(tree, RevisionTree)
163
191
return self._convert_tree(tree, converter)
193
def get_tree_with_subdirs_and_all_content_types(self):
194
"""Return a test tree with subdirs and all content types.
195
See get_tree_with_subdirs_and_all_supported_content_types for details.
197
return self.get_tree_with_subdirs_and_all_supported_content_types(True)
199
def get_tree_with_subdirs_and_all_supported_content_types(self, symlinks):
200
"""Return a test tree with subdirs and all supported content types.
201
Some content types may not be created on some platforms
202
(like symlinks on native win32)
204
:param symlinks: control is symlink should be created in the tree.
205
Note: if you wish to automatically set this
206
parameters depending on underlying system,
207
please use value returned
208
by bzrlib.osutils.has_symlinks() function.
210
The returned tree has the following inventory:
211
[('', inventory.ROOT_ID),
213
('1top-dir', '1top-dir'),
214
(u'2utf\u1234file', u'0utf\u1234file'),
215
('symlink', 'symlink'), # only if symlinks arg is True
216
('1top-dir/0file-in-1topdir', '1file-in-1topdir'),
217
('1top-dir/1dir-in-1topdir', '0dir-in-1topdir')]
218
where each component has the type of its name -
219
i.e. '1file..' is afile.
221
note that the order of the paths and fileids is deliberately
222
mismatched to ensure that the result order is path based.
224
tree = self.make_branch_and_tree('.')
228
'1top-dir/0file-in-1topdir',
229
'1top-dir/1dir-in-1topdir/'
234
u'0utf\u1234file'.encode('utf8'),
239
self.build_tree(paths)
242
'This platform does not support unicode file paths.')
244
tt = transform.TreeTransform(tree)
246
root_transaction_id = tt.trans_id_tree_path('')
247
tt.new_symlink('symlink',
248
root_transaction_id, 'link-target', 'symlink')
250
return self.workingtree_to_test_tree(tree)
252
def get_tree_with_utf8(self, tree):
253
"""Generate a tree with a utf8 revision and unicode paths."""
254
self._create_tree_with_utf8(tree)
255
return self.workingtree_to_test_tree(tree)
257
def _create_tree_with_utf8(self, tree):
258
"""Generate a tree with a utf8 revision and unicode paths."""
264
# bzr itself does not create unicode file ids, but we want them for
266
file_ids = ['TREE_ROOT',
272
self.build_tree(paths[1:])
274
raise tests.TestSkipped('filesystem does not support unicode.')
275
if tree.get_root_id() is None:
276
# Some trees do not have a root yet.
277
tree.add(paths, file_ids)
279
# Some trees will already have a root
280
tree.set_root_id(file_ids[0])
281
tree.add(paths[1:], file_ids[1:])
283
tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
284
except errors.NonAsciiRevisionId:
285
raise tests.TestSkipped('non-ascii revision ids not supported')
287
def get_tree_with_merged_utf8(self, tree):
288
"""Generate a tree with utf8 ancestors."""
289
self._create_tree_with_utf8(tree)
290
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
291
self.build_tree([u'tree2/b\xe5r/z\xf7z'])
292
tree2.add([u'b\xe5r/z\xf7z'], [u'z\xf7z-id'.encode('utf-8')])
293
tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
295
tree.merge_from_branch(tree2.branch)
296
tree.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
297
return self.workingtree_to_test_tree(tree)
166
300
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
167
301
"""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.
303
Currently this covers all working tree formats, and RevisionTree and
304
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:
308
def __init__(self, transport_server, transport_readonly_server, formats):
309
"""Create a TreeTestProviderAdapter.
311
:param formats: [workingtree_format]
313
super(TreeTestProviderAdapter, self).__init__(transport_server,
314
transport_readonly_server, formats)
315
# now adjust the scenarios and add the non-working-tree tree scenarios.
316
for scenario in self.scenarios:
176
317
# 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)
318
scenario[1]["_workingtree_to_test_tree"] = return_parameter
319
# add RevisionTree scenario
320
self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
321
revision_tree_from_workingtree,))
323
# also test WorkingTree4's RevisionTree implementation which is
325
self.scenarios.append(self.create_tree_scenario(
326
DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
327
WorkingTreeFormat4()))
328
self.scenarios.append(self.create_tree_scenario('PreviewTree',
331
def create_tree_scenario(self, name, converter, workingtree_format=None):
332
"""Create a scenario for the specified converter
334
:param name: The name to append to tests using this converter
335
:param converter: A function that converts a workingtree into the
337
:param workingtree_format: The particular workingtree format to
339
:return: a (name, options) tuple, where options is a dict of values
340
to be used as members of the TestCase.
342
if workingtree_format is None:
343
workingtree_format = WorkingTreeFormat._default_format
344
scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
345
workingtree_format)[1]
346
scenario_options["_workingtree_to_test_tree"] = converter
347
return name, scenario_options
350
def load_tests(basic_tests, module, loader):
351
result = loader.suiteClass()
352
# add the tests for this module
353
result.addTests(basic_tests)
191
355
test_tree_implementations = [
356
'bzrlib.tests.tree_implementations.test_annotate_iter',
357
'bzrlib.tests.tree_implementations.test_get_file_mtime',
358
'bzrlib.tests.tree_implementations.test_get_root_id',
359
'bzrlib.tests.tree_implementations.test_get_symlink_target',
360
'bzrlib.tests.tree_implementations.test_inv',
361
'bzrlib.tests.tree_implementations.test_iter_search_rules',
362
'bzrlib.tests.tree_implementations.test_list_files',
363
'bzrlib.tests.tree_implementations.test_path_content_summary',
364
'bzrlib.tests.tree_implementations.test_revision_tree',
192
365
'bzrlib.tests.tree_implementations.test_test_trees',
366
'bzrlib.tests.tree_implementations.test_tree',
367
'bzrlib.tests.tree_implementations.test_walkdirs',
194
370
adapter = TreeTestProviderAdapter(
195
371
default_transport,
196
372
# None here will cause a readonly decorator to be created
197
373
# by the TestCaseWithTransport.get_readonly_transport method.
199
[(format, format._matchingbzrdir) for format in
200
WorkingTreeFormat._formats.values() + _legacy_formats])
201
loader = TestLoader()
375
WorkingTreeFormat._formats.values() + _legacy_formats)
377
# add the tests for the sub modules
202
378
adapt_modules(test_tree_implementations, adapter, loader, result)
203
result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations']))