/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1852.6.1 by Robert Collins
Start tree implementation tests.
1
# Copyright (C) 2006 by Canonical Ltd
1852.6.7 by Robert Collins
Fix up new tree_implementations __init__.py header.
2
#
1852.6.1 by Robert Collins
Start tree implementation tests.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1852.6.7 by Robert Collins
Fix up new tree_implementations __init__.py header.
7
#
1852.6.1 by Robert Collins
Start tree implementation tests.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1852.6.7 by Robert Collins
Fix up new tree_implementations __init__.py header.
12
#
1852.6.1 by Robert Collins
Start tree implementation tests.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
"""Tree implementation tests for bzr.
19
20
These test the conformance of all the tree variations to the expected API.
21
Specific tests for individual variations are in other places such as:
22
 - tests/test_tree.py
23
 - tests/test_revision.py
24
 - tests/test_workingtree.py
25
 - tests/workingtree_implementations/*.py.
26
"""
27
28
import bzrlib.errors as errors
29
from bzrlib.transport import get_transport
30
from bzrlib.tests import (
31
                          adapt_modules,
32
                          default_transport,
33
                          TestCaseWithTransport,
34
                          TestLoader,
35
                          TestSuite,
36
                          )
37
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
38
from bzrlib.tree import RevisionTree
39
from bzrlib.workingtree import (WorkingTreeFormat,
40
                                WorkingTreeTestProviderAdapter,
41
                                _legacy_formats,
42
                                )
43
44
45
def return_parameter(something):
46
    """A trivial thunk to return its input."""
47
    return something
48
49
50
def revision_tree_from_workingtree(tree):
51
    """Create a revision tree from a working tree."""
52
    revid = tree.commit('save tree', allow_pointless=True)
53
    return tree.branch.repository.revision_tree(revid)
54
55
56
class TestTreeImplementationSupport(TestCaseWithTransport):
57
58
    def test_revision_tree_from_workingtree(self):
59
        tree = self.make_branch_and_tree('.')
60
        tree = revision_tree_from_workingtree(tree)
61
        self.assertIsInstance(tree, RevisionTree)
62
63
64
class TestCaseWithTree(TestCaseWithBzrDir):
65
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
66
    def make_branch_and_tree(self, relpath):
67
        made_control = self.make_bzrdir(relpath, format=
68
            self.workingtree_format._matchingbzrdir)
1852.6.1 by Robert Collins
Start tree implementation tests.
69
        made_control.create_repository()
70
        made_control.create_branch()
71
        return self.workingtree_format.initialize(made_control)
72
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
73
    def get_tree_no_parents_no_content(self, empty_tree, converter=None):
74
        """Make a tree with no parents and no contents from empty_tree.
75
        
76
        :param empty_tree: A working tree with no content and no parents to
77
            modify.
78
        """
1852.6.1 by Robert Collins
Start tree implementation tests.
79
        # convert that to the final shape
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
80
        if converter is None:
81
            converter = self.workingtree_to_test_tree
82
        return converter(empty_tree)
1852.6.1 by Robert Collins
Start tree implementation tests.
83
84
85
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
86
    """Generate test suites for each Tree implementation in bzrlib.
87
88
    Currently this covers all working tree formats, and RevisionTree by 
89
    committing a working tree to create the revision tree.
90
    """
91
92
    def adapt(self, test):
93
        result = super(TreeTestProviderAdapter, self).adapt(test)
94
        for adapted_test in result:
95
            # for working tree adapted tests, preserve the tree
96
            adapted_test.workingtree_to_test_tree = return_parameter
97
        default_format = WorkingTreeFormat.get_default_format()
98
        revision_tree_test = self._clone_test(
99
            test,
100
            default_format._matchingbzrdir, 
101
            default_format,
102
            RevisionTree.__name__)
103
        revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
104
        result.addTest(revision_tree_test)
105
        return result
106
107
108
def test_suite():
109
    result = TestSuite()
110
    test_tree_implementations = [
111
        'bzrlib.tests.tree_implementations.test_test_trees',
112
        ]
113
    adapter = TreeTestProviderAdapter(
114
        default_transport,
115
        # None here will cause a readonly decorator to be created
116
        # by the TestCaseWithTransport.get_readonly_transport method.
117
        None,
118
        [(format, format._matchingbzrdir) for format in 
119
         WorkingTreeFormat._formats.values() + _legacy_formats])
120
    loader = TestLoader()
121
    adapt_modules(test_tree_implementations, adapter, loader, result)
122
    result.addTests(loader.loadTestsFromModuleNames(['bzrlib.tests.tree_implementations']))
123
    return result