/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
3
# -*- coding: utf-8 -*-
4
4
#
24
24
rather than in tests/branch_implementations/*.py.
25
25
"""
26
26
 
27
 
from bzrlib.bzrdir import BzrDirTestProviderAdapter, BzrDirFormat
 
27
from bzrlib.bzrdir import BzrDirFormat
28
28
from bzrlib.tests import (
29
29
                          adapt_modules,
30
30
                          default_transport,
31
 
                          TestLoader,
32
 
                          TestSuite,
 
31
                          TestCaseWithTransport,
 
32
                          TestScenarioApplier,
33
33
                          )
34
 
 
35
 
 
36
 
def test_suite():
37
 
    result = TestSuite()
 
34
from bzrlib.transport.memory import MemoryServer
 
35
 
 
36
 
 
37
class BzrDirTestProviderAdapter(TestScenarioApplier):
 
38
    """A tool to generate a suite testing multiple bzrdir formats at once.
 
39
 
 
40
    This is done by copying the test once for each transport and injecting
 
41
    the transport_server, transport_readonly_server, and bzrdir_format
 
42
    classes into each copy. Each copy is also given a new id() to make it
 
43
    easy to identify.
 
44
    """
 
45
 
 
46
    def __init__(self, vfs_factory, transport_server, transport_readonly_server,
 
47
        formats, name_suffix=''):
 
48
        """Create an object to adapt tests.
 
49
 
 
50
        :param vfs_server: A factory to create a Transport Server which has
 
51
            all the VFS methods working, and is writable.
 
52
        """
 
53
        self._vfs_factory = vfs_factory
 
54
        self._transport_server = transport_server
 
55
        self._transport_readonly_server = transport_readonly_server
 
56
        self._name_suffix = name_suffix
 
57
        self.scenarios = self.formats_to_scenarios(formats)
 
58
    
 
59
    def formats_to_scenarios(self, formats):
 
60
        """Transform the input formats to a list of scenarios.
 
61
 
 
62
        :param formats: A list of bzrdir_format objects.
 
63
        """
 
64
        result = []
 
65
        for format in formats:
 
66
            scenario_name = format.__class__.__name__
 
67
            scenario_name += self._name_suffix
 
68
            scenario = (scenario_name, {
 
69
                "vfs_transport_factory":self._vfs_factory,
 
70
                "transport_server":self._transport_server,
 
71
                "transport_readonly_server":self._transport_readonly_server,
 
72
                "bzrdir_format":format,
 
73
                })
 
74
            result.append(scenario)
 
75
        return result
 
76
 
 
77
 
 
78
class TestCaseWithBzrDir(TestCaseWithTransport):
 
79
 
 
80
    def setUp(self):
 
81
        super(TestCaseWithBzrDir, self).setUp()
 
82
        self.bzrdir = None
 
83
 
 
84
    def get_bzrdir(self):
 
85
        if self.bzrdir is None:
 
86
            self.bzrdir = self.make_bzrdir(None)
 
87
        return self.bzrdir
 
88
 
 
89
    def make_bzrdir(self, relpath, format=None):
 
90
        if format is None:
 
91
            format = self.bzrdir_format
 
92
        return super(TestCaseWithBzrDir, self).make_bzrdir(
 
93
            relpath, format=format)
 
94
 
 
95
 
 
96
def load_tests(basic_tests, module, loader):
 
97
    result = loader.suiteClass()
 
98
    # add the tests for this module
 
99
    result.addTests(basic_tests)
 
100
 
38
101
    test_bzrdir_implementations = [
39
102
        'bzrlib.tests.bzrdir_implementations.test_bzrdir',
40
103
        ]
41
104
    formats = BzrDirFormat.known_formats()
42
105
    adapter = BzrDirTestProviderAdapter(
43
106
        default_transport,
 
107
        None,
44
108
        # None here will cause a readonly decorator to be created
45
109
        # by the TestCaseWithTransport.get_readonly_transport method.
46
110
        None,
47
111
        formats)
48
 
    loader = TestLoader()
 
112
    # add the tests for the sub modules
49
113
    adapt_modules(test_bzrdir_implementations, adapter, loader, result)
 
114
 
 
115
    # This will always add the tests for smart server transport, regardless of
 
116
    # the --transport option the user specified to 'bzr selftest'.
 
117
    from bzrlib.smart.server import (
 
118
        ReadonlySmartTCPServer_for_testing,
 
119
        ReadonlySmartTCPServer_for_testing_v2_only,
 
120
        SmartTCPServer_for_testing,
 
121
        SmartTCPServer_for_testing_v2_only,
 
122
        )
 
123
    from bzrlib.remote import RemoteBzrDirFormat
 
124
 
 
125
    # test the remote server behaviour using a MemoryTransport
 
126
    smart_server_suite = loader.suiteClass()
 
127
    adapt_to_smart_server = BzrDirTestProviderAdapter(
 
128
        MemoryServer,
 
129
        SmartTCPServer_for_testing,
 
130
        ReadonlySmartTCPServer_for_testing,
 
131
        [(RemoteBzrDirFormat())],
 
132
        name_suffix='-default')
 
133
    adapt_modules(test_bzrdir_implementations,
 
134
                  adapt_to_smart_server,
 
135
                  loader,
 
136
                  smart_server_suite)
 
137
    adapt_to_smart_server = BzrDirTestProviderAdapter(
 
138
        MemoryServer,
 
139
        SmartTCPServer_for_testing_v2_only,
 
140
        ReadonlySmartTCPServer_for_testing_v2_only,
 
141
        [(RemoteBzrDirFormat())],
 
142
        name_suffix='-v2')
 
143
    adapt_modules(test_bzrdir_implementations,
 
144
                  adapt_to_smart_server,
 
145
                  loader,
 
146
                  smart_server_suite)
 
147
    result.addTests(smart_server_suite)
 
148
 
50
149
    return result