/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2008-06-05 16:27:16 UTC
  • mfrom: (3475 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3476.
  • Revision ID: john@arbash-meinel.com-20080605162716-a3hn238tnctbfd8j
merge bzr.dev, resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
36
36
                          adapt_modules,
37
37
                          default_transport,
38
38
                          TestCaseWithTransport,
39
 
                          TestLoader,
40
39
                          TestSkipped,
41
 
                          TestSuite,
42
40
                          )
43
41
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
44
42
from bzrlib.tests.workingtree_implementations import (
45
43
    WorkingTreeTestProviderAdapter,
46
44
    )
47
45
from bzrlib.revisiontree import RevisionTree
 
46
from bzrlib.transform import TransformPreview
48
47
from bzrlib.workingtree import (
49
48
    WorkingTreeFormat,
50
49
    WorkingTreeFormat3,
56
55
    )
57
56
 
58
57
 
59
 
def return_parameter(something):
 
58
def return_parameter(testcase, something):
60
59
    """A trivial thunk to return its input."""
61
60
    return something
62
61
 
63
62
 
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)
68
67
 
69
68
 
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()
73
72
 
74
73
 
 
74
def preview_tree_pre(testcase, tree):
 
75
    tt = TransformPreview(tree)
 
76
    testcase.addCleanup(tt.finalize)
 
77
    return tt.get_preview_tree()
 
78
 
 
79
 
75
80
class TestTreeImplementationSupport(TestCaseWithTransport):
76
81
 
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)
81
86
 
82
87
 
89
94
        made_control.create_branch()
90
95
        return self.workingtree_format.initialize(made_control)
91
96
 
 
97
    def workingtree_to_test_tree(self, tree):
 
98
        return self._workingtree_to_test_tree(self, tree)
 
99
 
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
307
 
        # code.
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
313
 
 
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
320
 
 
321
 
 
322
 
def test_suite():
323
 
    result = TestSuite()
 
314
        self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
 
315
                              revision_tree_from_workingtree,))
 
316
 
 
317
        # also test WorkingTree4's RevisionTree implementation which is
 
318
        # specialised.
 
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',
 
323
            preview_tree_pre))
 
324
 
 
325
    def create_tree_scenario(self, name, converter, workingtree_format=None):
 
326
        """Create a scenario for the specified converter
 
327
 
 
328
        :param name: The name to append to tests using this converter
 
329
        :param converter: A function that converts a workingtree into the
 
330
            desired format.
 
331
        :param workingtree_format: The particular workingtree format to
 
332
            convert from.
 
333
        :return: a (name, options) tuple, where options is a dict of values
 
334
            to be used as members of the TestCase.
 
335
        """
 
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
 
342
 
 
343
 
 
344
def load_tests(basic_tests, module, loader):
 
345
    result = loader.suiteClass()
 
346
    # add the tests for this module
 
347
    result.addTests(basic_tests)
 
348
 
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',
335
361
        ]
 
362
 
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.
340
367
        None,
341
 
        [(format, format._matchingbzrdir) for format in 
 
368
        [(format, format._matchingbzrdir) for format in
342
369
         WorkingTreeFormat._formats.values() + _legacy_formats])
343
 
    loader = TestLoader()
 
370
 
 
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']))
346
373
    return result