~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2006-07-20 13:00:31 UTC
  • mto: (1852.9.1 Tree.compare().)
  • mto: This revision was merged to the branch mainline in revision 1890.
  • Revision ID: robertc@robertcollins.net-20060720130031-d26103a427ea10f3
StartĀ treeĀ implementationĀ tests.

Show diffs side-by-side

added added

removed removed

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