1
# Copyright (C) 2006 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
# -*- coding: utf-8 -*-
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.
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.
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
20
"""Tree implementation tests for bzr.
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:
25
- tests/test_revision.py
26
- tests/test_workingtree.py
27
- tests/workingtree_implementations/*.py.
30
import bzrlib.errors as errors
31
from bzrlib.transport import get_transport
32
from bzrlib.tests import (
35
TestCaseWithTransport,
39
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
40
from bzrlib.tree import RevisionTree
41
from bzrlib.workingtree import (WorkingTreeFormat,
42
WorkingTreeTestProviderAdapter,
47
def return_parameter(something):
48
"""A trivial thunk to return its input."""
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)
58
class TestTreeImplementationSupport(TestCaseWithTransport):
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)
66
class TestCaseWithTree(TestCaseWithBzrDir):
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)
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)
81
class TreeTestProviderAdapter(WorkingTreeTestProviderAdapter):
82
"""Generate test suites for each Tree implementation in bzrlib.
84
Currently this covers all working tree formats, and RevisionTree by
85
committing a working tree to create the revision tree.
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(
96
default_format._matchingbzrdir,
98
RevisionTree.__name__)
99
revision_tree_test.workingtree_to_test_tree = revision_tree_from_workingtree
100
result.addTest(revision_tree_test)
106
test_tree_implementations = [
107
'bzrlib.tests.tree_implementations.test_test_trees',
109
adapter = TreeTestProviderAdapter(
111
# None here will cause a readonly decorator to be created
112
# by the TestCaseWithTransport.get_readonly_transport method.
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']))