59
def return_parameter(something):
58
def return_parameter(testcase, something):
60
59
"""A trivial thunk to return its input."""
64
def revision_tree_from_workingtree(tree):
63
def revision_tree_from_workingtree(testcase, tree):
65
64
"""Create a revision tree from a working tree."""
66
65
revid = tree.commit('save tree', allow_pointless=True, recursive=None)
67
66
return tree.branch.repository.revision_tree(revid)
70
def _dirstate_tree_from_workingtree(tree):
69
def _dirstate_tree_from_workingtree(testcase, tree):
71
70
revid = tree.commit('save tree', allow_pointless=True)
72
71
return tree.basis_tree()
74
def preview_tree_pre(testcase, tree):
75
tt = TransformPreview(tree)
76
testcase.addCleanup(tt.finalize)
77
return tt.get_preview_tree()
75
80
class TestTreeImplementationSupport(TestCaseWithTransport):
77
82
def test_revision_tree_from_workingtree(self):
78
83
tree = self.make_branch_and_tree('.')
79
tree = revision_tree_from_workingtree(tree)
84
tree = revision_tree_from_workingtree(self, tree)
80
85
self.assertIsInstance(tree, RevisionTree)
89
94
made_control.create_branch()
90
95
return self.workingtree_format.initialize(made_control)
97
def workingtree_to_test_tree(self, tree):
98
return self._workingtree_to_test_tree(self, tree)
92
100
def _convert_tree(self, tree, converter=None):
93
101
"""helper to convert using the converter or a supplied one."""
94
102
# convert that to the final shape
301
309
# now adjust the scenarios and add the non-working-tree tree scenarios.
302
310
for scenario in self.scenarios:
303
311
# for working tree adapted tests, preserve the tree
304
scenario[1]["workingtree_to_test_tree"] = return_parameter
312
scenario[1]["_workingtree_to_test_tree"] = return_parameter
305
313
# add RevisionTree scenario
306
# this is the 'default format' in that it's used to test the generic InterTree
308
default_format = WorkingTreeFormat3()
309
self.scenarios.append(self.formats_to_scenarios([
310
(default_format, default_format._matchingbzrdir)])[0])
311
self.scenarios[-1] = (RevisionTree.__name__, self.scenarios[-1][1])
312
self.scenarios[-1][1]["workingtree_to_test_tree"] = revision_tree_from_workingtree
314
# also test WorkingTree4's RevisionTree implementation which is specialised.
315
dirstate_format = WorkingTreeFormat4()
316
self.scenarios.append(self.formats_to_scenarios([
317
(dirstate_format, dirstate_format._matchingbzrdir)])[0])
318
self.scenarios[-1] = (DirStateRevisionTree.__name__, self.scenarios[-1][1])
319
self.scenarios[-1][1]["workingtree_to_test_tree"] = _dirstate_tree_from_workingtree
314
self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
315
revision_tree_from_workingtree,))
317
# also test WorkingTree4's RevisionTree implementation which is
319
self.scenarios.append(self.create_tree_scenario(
320
DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
321
WorkingTreeFormat4()))
322
self.scenarios.append(self.create_tree_scenario('PreviewTree',
325
def create_tree_scenario(self, name, converter, workingtree_format=None):
326
"""Create a scenario for the specified converter
328
:param name: The name to append to tests using this converter
329
:param converter: A function that converts a workingtree into the
331
:param workingtree_format: The particular workingtree format to
333
:return: a (name, options) tuple, where options is a dict of values
334
to be used as members of the TestCase.
336
if workingtree_format is None:
337
workingtree_format = WorkingTreeFormat3()
338
scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
339
workingtree_format, workingtree_format._matchingbzrdir)[1]
340
scenario_options["_workingtree_to_test_tree"] = converter
341
return name, scenario_options
344
def load_tests(basic_tests, module, loader):
345
result = loader.suiteClass()
346
# add the tests for this module
347
result.addTests(basic_tests)
324
349
test_tree_implementations = [
350
'bzrlib.tests.tree_implementations.test_annotate_iter',
325
351
'bzrlib.tests.tree_implementations.test_get_file_mtime',
326
352
'bzrlib.tests.tree_implementations.test_get_root_id',
327
353
'bzrlib.tests.tree_implementations.test_get_symlink_target',
333
359
'bzrlib.tests.tree_implementations.test_tree',
334
360
'bzrlib.tests.tree_implementations.test_walkdirs',
336
363
adapter = TreeTestProviderAdapter(
337
364
default_transport,
338
365
# None here will cause a readonly decorator to be created
339
366
# by the TestCaseWithTransport.get_readonly_transport method.
341
[(format, format._matchingbzrdir) for format in
368
[(format, format._matchingbzrdir) for format in
342
369
WorkingTreeFormat._formats.values() + _legacy_formats])
343
loader = TestLoader()
371
# add the tests for the sub modules
344
372
adapt_modules(test_tree_implementations, adapter, loader, result)
345
result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations']))