/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

Merge from bzr.dev.

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
45
45
    WorkingTreeTestProviderAdapter,
46
46
    )
47
47
from bzrlib.revisiontree import RevisionTree
 
48
from bzrlib.transform import TransformPreview
48
49
from bzrlib.workingtree import (
49
50
    WorkingTreeFormat,
50
51
    WorkingTreeFormat3,
56
57
    )
57
58
 
58
59
 
59
 
def return_parameter(something):
 
60
def return_parameter(testcase, something):
60
61
    """A trivial thunk to return its input."""
61
62
    return something
62
63
 
63
64
 
64
 
def revision_tree_from_workingtree(tree):
 
65
def revision_tree_from_workingtree(testcase, tree):
65
66
    """Create a revision tree from a working tree."""
66
67
    revid = tree.commit('save tree', allow_pointless=True, recursive=None)
67
68
    return tree.branch.repository.revision_tree(revid)
68
69
 
69
70
 
70
 
def _dirstate_tree_from_workingtree(tree):
 
71
def _dirstate_tree_from_workingtree(testcase, tree):
71
72
    revid = tree.commit('save tree', allow_pointless=True)
72
73
    return tree.basis_tree()
73
74
 
74
75
 
 
76
def preview_tree_pre(testcase, tree):
 
77
    tt = TransformPreview(tree)
 
78
    testcase.addCleanup(tt.finalize)
 
79
    return tt.get_preview_tree()
 
80
 
 
81
 
75
82
class TestTreeImplementationSupport(TestCaseWithTransport):
76
83
 
77
84
    def test_revision_tree_from_workingtree(self):
78
85
        tree = self.make_branch_and_tree('.')
79
 
        tree = revision_tree_from_workingtree(tree)
 
86
        tree = revision_tree_from_workingtree(self, tree)
80
87
        self.assertIsInstance(tree, RevisionTree)
81
88
 
82
89
 
89
96
        made_control.create_branch()
90
97
        return self.workingtree_format.initialize(made_control)
91
98
 
 
99
    def workingtree_to_test_tree(self, tree):
 
100
        return self._workingtree_to_test_tree(self, tree)
 
101
 
92
102
    def _convert_tree(self, tree, converter=None):
93
103
        """helper to convert using the converter or a supplied one."""
94
104
        # convert that to the final shape
301
311
        # now adjust the scenarios and add the non-working-tree tree scenarios.
302
312
        for scenario in self.scenarios:
303
313
            # for working tree adapted tests, preserve the tree
304
 
            scenario[1]["workingtree_to_test_tree"] = return_parameter
 
314
            scenario[1]["_workingtree_to_test_tree"] = return_parameter
305
315
        # 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
 
316
        self.scenarios.append(self.create_tree_scenario(RevisionTree.__name__,
 
317
                              revision_tree_from_workingtree,))
 
318
 
 
319
        # also test WorkingTree4's RevisionTree implementation which is
 
320
        # specialised.
 
321
        self.scenarios.append(self.create_tree_scenario(
 
322
            DirStateRevisionTree.__name__, _dirstate_tree_from_workingtree,
 
323
            WorkingTreeFormat4()))
 
324
        self.scenarios.append(self.create_tree_scenario('PreviewTree',
 
325
            preview_tree_pre))
 
326
 
 
327
    def create_tree_scenario(self, name, converter, workingtree_format=None):
 
328
        """Create a scenario for the specified converter
 
329
 
 
330
        :param name: The name to append to tests using this converter
 
331
        :param converter: A function that converts a workingtree into the
 
332
            desired format.
 
333
        :param workingtree_format: The particular workingtree format to
 
334
            convert from.
 
335
        :return: a (name, options) tuple, where options is a dict of values
 
336
            to be used as members of the TestCase.
 
337
        """
 
338
        if workingtree_format is None:
 
339
            workingtree_format = WorkingTreeFormat3()
 
340
        scenario_options = WorkingTreeTestProviderAdapter.create_scenario(self,
 
341
            workingtree_format, workingtree_format._matchingbzrdir)[1]
 
342
        scenario_options["_workingtree_to_test_tree"] = converter
 
343
        return name, scenario_options
320
344
 
321
345
 
322
346
def test_suite():