1
# Copyright (C) 2006 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""InterVersioned implementation tests for bzr.
21
These test the conformance of all the interversionedfile variations to the
22
expected API including generally applicable corner cases.
23
Specific tests for individual cases are in the tests/test_versionedfile.py file
24
rather than in tests/interversionedfile_implementations/*.py.
27
from bzrlib.tests import (
34
class InterVersionedFileTestProviderAdapter(TestScenarioApplier):
35
"""A tool to generate a suite testing multiple inter versioned-file classes.
37
This is done by copying the test once for each InterVersionedFile provider
38
and injecting the transport_server, transport_readonly_server,
39
versionedfile_factory and versionedfile_factory_to classes into each copy.
40
Each copy is also given a new id() to make it easy to identify.
43
def __init__(self, transport_server, transport_readonly_server, formats):
44
self._transport_server = transport_server
45
self._transport_readonly_server = transport_readonly_server
46
self.scenarios = self.formats_to_scenarios(formats)
48
def formats_to_scenarios(self, formats):
49
"""Transform the input formats to a list of scenarios.
51
:param formats: A list of tuples:
52
(interversionedfile_class, versionedfile_factory,
53
versionedfile_factory_to).
56
for (interversionedfile_class,
57
versionedfile_factory,
58
versionedfile_factory_to) in formats:
59
scenario = (interversionedfile_class.__name__, {
60
"transport_server":self._transport_server,
61
"transport_readonly_server":self._transport_readonly_server,
62
"interversionedfile_class":interversionedfile_class,
63
"versionedfile_factory":versionedfile_factory,
64
"versionedfile_factory_to":versionedfile_factory_to,
66
result.append(scenario)
70
def default_test_list():
71
"""Generate the default list of interversionedfile permutations to test."""
72
from bzrlib.versionedfile import InterVersionedFile
73
from bzrlib.weave import WeaveFile
74
from bzrlib.knit import make_file_knit
76
# test the fallback InterVersionedFile from annotated knits to weave
77
result.append((InterVersionedFile,
80
for optimiser in InterVersionedFile._optimisers:
81
result.append((optimiser,
82
optimiser._matching_file_from_factory,
83
optimiser._matching_file_to_factory
85
# if there are specific combinations we want to use, we can add them
90
def load_tests(basic_tests, module, loader):
91
result = loader.suiteClass()
92
# add the tests for this module
93
result.addTests(basic_tests)
95
test_interversionedfile_implementations = [
96
'bzrlib.tests.interversionedfile_implementations.test_join',
98
adapter = InterVersionedFileTestProviderAdapter(
100
# None here will cause a readonly decorator to be created
101
# by the TestCaseWithTransport.get_readonly_transport method.
103
InterVersionedFileTestProviderAdapter.default_test_list()
105
# add the tests for the sub modules
106
adapt_modules(test_interversionedfile_implementations,
107
adapter, loader, result)