~ubuntu-branches/ubuntu/maverick/bzr/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-07-21 11:25:12 UTC
  • mfrom: (1.4.1 upstream) (8.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090721112512-dzfg8hfhqddf1dwj
* New upstream release.
 + Fixes compatibility with Python 2.4. Closes: #537708

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
 
 
19
 
 
20
 
"""BzrDir implementation tests for bzr.
21
 
 
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.
25
 
"""
26
 
 
27
 
from bzrlib.bzrdir import BzrDirFormat
28
 
from bzrlib.tests import (
29
 
                          default_transport,
30
 
                          multiply_tests,
31
 
                          TestCaseWithTransport,
32
 
                          )
33
 
from bzrlib.transport.memory import MemoryServer
34
 
 
35
 
 
36
 
def make_scenarios(vfs_factory, transport_server, transport_readonly_server,
37
 
    formats, name_suffix=''):
38
 
    """Transform the input to a list of scenarios.
39
 
 
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.
43
 
    """
44
 
    result = []
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,
53
 
            })
54
 
        result.append(scenario)
55
 
    return result
56
 
 
57
 
 
58
 
class TestCaseWithBzrDir(TestCaseWithTransport):
59
 
 
60
 
    def setUp(self):
61
 
        super(TestCaseWithBzrDir, self).setUp()
62
 
        self.bzrdir = None
63
 
 
64
 
    def get_bzrdir(self):
65
 
        if self.bzrdir is None:
66
 
            self.bzrdir = self.make_bzrdir(None)
67
 
        return self.bzrdir
68
 
 
69
 
    def make_bzrdir(self, relpath, format=None):
70
 
        if format is None:
71
 
            format = self.bzrdir_format
72
 
        return super(TestCaseWithBzrDir, self).make_bzrdir(
73
 
            relpath, format=format)
74
 
 
75
 
 
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',
80
 
        ]
81
 
    submod_tests = loader.loadTestsFromModuleNames(test_bzrdir_implementations)
82
 
    formats = BzrDirFormat.known_formats()
83
 
    scenarios = make_scenarios(
84
 
        default_transport,
85
 
        None,
86
 
        # None here will cause a readonly decorator to be created
87
 
        # by the TestCaseWithTransport.get_readonly_transport method.
88
 
        None,
89
 
        formats)
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,
96
 
        )
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(
101
 
        MemoryServer,
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(
108
 
        MemoryServer,
109
 
        SmartTCPServer_for_testing_v2_only,
110
 
        ReadonlySmartTCPServer_for_testing_v2_only,
111
 
        [(RemoteBzrDirFormat())],
112
 
        name_suffix='-v2'))
113
 
    # add the tests for the sub modules
114
 
    return multiply_tests(submod_tests, scenarios, standard_tests)