13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""Tree implementation tests for bzr.
20
20
These test the conformance of all the tree variations to the expected API.
21
21
Specific tests for individual variations are in other places such as:
22
- tests/per_workingtree/*.py.
23
22
- tests/test_tree.py
24
23
- tests/test_revision.py
25
24
- tests/test_workingtree.py
25
- tests/workingtree_implementations/*.py.
28
28
from bzrlib import (
34
from bzrlib.tests.per_controldir.test_controldir import TestCaseWithControlDir
35
from bzrlib.tests.per_workingtree import (
36
make_scenarios as wt_make_scenarios,
37
make_scenario as wt_make_scenario,
35
from bzrlib.transport import get_transport
36
from bzrlib.tests import (
39
TestCaseWithTransport,
42
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
43
from bzrlib.tests.workingtree_implementations import (
44
WorkingTreeTestProviderAdapter,
46
from bzrlib.revision import NULL_REVISION
39
47
from bzrlib.revisiontree import RevisionTree
40
48
from bzrlib.transform import TransformPreview
41
from bzrlib.tests import (
44
49
from bzrlib.workingtree import (
47
54
from bzrlib.workingtree_4 import (
48
55
DirStateRevisionTree,
49
56
WorkingTreeFormat4,
97
103
self.assertIsInstance(tree, RevisionTree)
100
class TestCaseWithTree(TestCaseWithControlDir):
106
class TestCaseWithTree(TestCaseWithBzrDir):
102
108
def make_branch_and_tree(self, relpath):
103
bzrdir_format = self.workingtree_format.get_controldir_for_branch()
104
made_control = self.make_bzrdir(relpath, format=bzrdir_format)
109
made_control = self.make_bzrdir(relpath, format=
110
self.workingtree_format._matchingbzrdir)
105
111
made_control.create_repository()
106
b = made_control.create_branch()
107
if getattr(self, 'repo_is_remote', False):
108
# If the repo is remote, then we just create a local lightweight
110
# XXX: This duplicates a lot of Branch.create_checkout, but we know
111
# we want a) lightweight, and b) a specific WT format. We also
112
# know that nothing should already exist, etc.
113
t = transport.get_transport(relpath)
115
wt_dir = bzrdir_format.initialize_on_transport(t)
116
branch_ref = wt_dir.set_branch_reference(b)
117
wt = wt_dir.create_workingtree(None, from_branch=branch_ref)
119
wt = self.workingtree_format.initialize(made_control)
112
made_control.create_branch()
113
return self.workingtree_format.initialize(made_control)
122
115
def workingtree_to_test_tree(self, tree):
123
116
return self._workingtree_to_test_tree(self, tree)
335
313
return self.workingtree_to_test_tree(tree)
338
def make_scenarios(transport_server, transport_readonly_server, formats):
316
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
339
317
"""Generate test suites for each Tree implementation in bzrlib.
341
319
Currently this covers all working tree formats, and RevisionTree and
342
320
DirStateRevisionTree by committing a working tree to create the revision
345
scenarios = wt_make_scenarios(transport_server, transport_readonly_server,
347
# now adjust the scenarios and add the non-working-tree tree scenarios.
348
for scenario in scenarios:
349
# for working tree format tests, preserve the tree
350
scenario[1]["_workingtree_to_test_tree"] = return_parameter
351
# add RevisionTree scenario
352
workingtree_format = format_registry.get_default()
353
scenarios.append((RevisionTree.__name__,
354
create_tree_scenario(transport_server, transport_readonly_server,
355
workingtree_format, revision_tree_from_workingtree,)))
357
# also test WorkingTree4/5's RevisionTree implementation which is
359
# XXX: Ask igc if WT5 revision tree actually is different.
360
scenarios.append((DirStateRevisionTree.__name__ + ",WT4",
361
create_tree_scenario(transport_server, transport_readonly_server,
362
WorkingTreeFormat4(), _dirstate_tree_from_workingtree)))
363
scenarios.append((DirStateRevisionTree.__name__ + ",WT5",
364
create_tree_scenario(transport_server, transport_readonly_server,
365
WorkingTreeFormat5(), _dirstate_tree_from_workingtree)))
366
scenarios.append(("PreviewTree", create_tree_scenario(transport_server,
367
transport_readonly_server, workingtree_format, preview_tree_pre)))
368
scenarios.append(("PreviewTreePost", create_tree_scenario(transport_server,
369
transport_readonly_server, workingtree_format, preview_tree_post)))
373
def create_tree_scenario(transport_server, transport_readonly_server,
374
workingtree_format, converter):
375
"""Create a scenario for the specified converter
377
:param converter: A function that converts a workingtree into the
379
:param workingtree_format: The particular workingtree format to
381
:return: a (name, options) tuple, where options is a dict of values
382
to be used as members of the TestCase.
384
scenario_options = wt_make_scenario(transport_server,
385
transport_readonly_server,
387
scenario_options["_workingtree_to_test_tree"] = converter
388
return scenario_options
391
def load_tests(standard_tests, module, loader):
392
per_tree_mod_names = [
396
'get_file_with_stat',
398
'get_symlink_target',
405
'path_content_summary',
324
def __init__(self, transport_server, transport_readonly_server, formats):
325
"""Create a TreeTestProviderAdapter.
327
:param formats: [workingtree_format]
329
super(TreeTestProviderAdapter, self).__init__(transport_server,
330
transport_readonly_server, formats)
331
# now adjust the scenarios and add the non-working-tree tree scenarios.
332
for scenario in self.scenarios:
333
# for working tree adapted tests, preserve the tree
334
scenario[1]["_workingtree_to_test_tree"] = return_parameter
335
# add RevisionTree scenario
336
self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
337
revision_tree_from_workingtree,))
339
# also test WorkingTree4's RevisionTree implementation which is
341
self.scenarios.append(self.create_tree_scenario(
342
DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
343
WorkingTreeFormat4()))
344
self.scenarios.append(self.create_tree_scenario('PreviewTree',
346
self.scenarios.append(self.create_tree_scenario('PreviewTreePost',
349
def create_tree_scenario(self, name, converter, workingtree_format=None):
350
"""Create a scenario for the specified converter
352
:param name: The name to append to tests using this converter
353
:param converter: A function that converts a workingtree into the
355
:param workingtree_format: The particular workingtree format to
357
:return: a (name, options) tuple, where options is a dict of values
358
to be used as members of the TestCase.
360
if workingtree_format is None:
361
workingtree_format = WorkingTreeFormat._default_format
362
scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
363
workingtree_format)[1]
364
scenario_options["_workingtree_to_test_tree"] = converter
365
return name, scenario_options
368
def load_tests(basic_tests, module, loader):
369
result = loader.suiteClass()
370
# add the tests for this module
371
result.addTests(basic_tests)
373
test_tree_implementations = [
374
'bzrlib.tests.tree_implementations.test_annotate_iter',
375
'bzrlib.tests.tree_implementations.test_get_file_mtime',
376
'bzrlib.tests.tree_implementations.test_get_root_id',
377
'bzrlib.tests.tree_implementations.test_get_symlink_target',
378
'bzrlib.tests.tree_implementations.test_inv',
379
'bzrlib.tests.tree_implementations.test_iter_search_rules',
380
'bzrlib.tests.tree_implementations.test_list_files',
381
'bzrlib.tests.tree_implementations.test_path_content_summary',
382
'bzrlib.tests.tree_implementations.test_revision_tree',
383
'bzrlib.tests.tree_implementations.test_test_trees',
384
'bzrlib.tests.tree_implementations.test_tree',
385
'bzrlib.tests.tree_implementations.test_walkdirs',
411
submod_tests = loader.loadTestsFromModuleNames(
412
['bzrlib.tests.per_tree.test_' + name
413
for name in per_tree_mod_names])
414
scenarios = make_scenarios(
415
tests.default_transport,
388
adapter = TreeTestProviderAdapter(
416
390
# None here will cause a readonly decorator to be created
417
391
# by the TestCaseWithTransport.get_readonly_transport method.
419
format_registry._get_all())
393
WorkingTreeFormat._formats.values() + _legacy_formats)
420
395
# add the tests for the sub modules
421
return tests.multiply_tests(submod_tests, scenarios, standard_tests)
396
adapt_modules(test_tree_implementations, adapter, loader, result)