1
# Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
"""BzrDir implementation tests for bzr.
22
These test the conformance of all the bzrdir variations to the expected API.
23
Specific tests for individual formats are in the tests/test_bzrdir.py file
24
rather than in tests/branch_implementations/*.py.
27
from bzrlib.bzrdir import BzrDirFormat
28
from bzrlib.tests import (
31
TestCaseWithTransport,
33
from bzrlib.transport.memory import MemoryServer
36
def make_scenarios(vfs_factory, transport_server, transport_readonly_server,
37
formats, name_suffix=''):
38
"""Transform the input to a list of scenarios.
40
:param formats: A list of bzrdir_format objects.
41
:param vfs_server: A factory to create a Transport Server which has
42
all the VFS methods working, and is writable.
45
for format in formats:
46
scenario_name = format.__class__.__name__
47
scenario_name += name_suffix
48
scenario = (scenario_name, {
49
"vfs_transport_factory": vfs_factory,
50
"transport_server": transport_server,
51
"transport_readonly_server": transport_readonly_server,
52
"bzrdir_format": format,
54
result.append(scenario)
58
class TestCaseWithBzrDir(TestCaseWithTransport):
61
super(TestCaseWithBzrDir, self).setUp()
65
if self.bzrdir is None:
66
self.bzrdir = self.make_bzrdir(None)
69
def make_bzrdir(self, relpath, format=None):
71
format = self.bzrdir_format
72
return super(TestCaseWithBzrDir, self).make_bzrdir(
73
relpath, format=format)
76
def load_tests(standard_tests, module, loader):
77
test_bzrdir_implementations = [
78
'bzrlib.tests.bzrdir_implementations.test_bzrdir',
79
'bzrlib.tests.bzrdir_implementations.test_push',
81
submod_tests = loader.loadTestsFromModuleNames(test_bzrdir_implementations)
82
formats = BzrDirFormat.known_formats()
83
scenarios = make_scenarios(
86
# None here will cause a readonly decorator to be created
87
# by the TestCaseWithTransport.get_readonly_transport method.
90
# This will always add scenarios using the smart server.
91
from bzrlib.smart.server import (
92
ReadonlySmartTCPServer_for_testing,
93
ReadonlySmartTCPServer_for_testing_v2_only,
94
SmartTCPServer_for_testing,
95
SmartTCPServer_for_testing_v2_only,
97
from bzrlib.remote import RemoteBzrDirFormat
98
# test the remote server behaviour when backed with a MemoryTransport
99
# Once for the current version
100
scenarios.extend(make_scenarios(
102
SmartTCPServer_for_testing,
103
ReadonlySmartTCPServer_for_testing,
104
[(RemoteBzrDirFormat())],
105
name_suffix='-default'))
106
# And once with < 1.6 - the 'v2' protocol.
107
scenarios.extend(make_scenarios(
109
SmartTCPServer_for_testing_v2_only,
110
ReadonlySmartTCPServer_for_testing_v2_only,
111
[(RemoteBzrDirFormat())],
113
# add the tests for the sub modules
114
return multiply_tests(submod_tests, scenarios, standard_tests)