/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

  • Committer: Martin Pool
  • Date: 2009-03-10 01:22:57 UTC
  • mfrom: (4099 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4101.
  • Revision ID: mbp@sourcefrog.net-20090310012257-rvtds5ic7ard4iza
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
from bzrlib.bzrdir import BzrDirFormat
28
28
from bzrlib.tests import (
29
 
                          adapt_modules,
30
29
                          default_transport,
 
30
                          multiply_tests,
31
31
                          TestCaseWithTransport,
32
 
                          TestScenarioApplier,
33
32
                          )
34
33
from bzrlib.transport.memory import MemoryServer
35
34
 
36
35
 
37
 
class BzrDirTestProviderAdapter(TestScenarioApplier):
38
 
    """A tool to generate a suite testing multiple bzrdir formats at once.
 
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
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.
 
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.
44
43
    """
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
 
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
76
56
 
77
57
 
78
58
class TestCaseWithBzrDir(TestCaseWithTransport):
93
73
            relpath, format=format)
94
74
 
95
75
 
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
 
 
 
76
def load_tests(standard_tests, module, loader):
101
77
    test_bzrdir_implementations = [
102
78
        'bzrlib.tests.bzrdir_implementations.test_bzrdir',
103
79
        ]
 
80
    submod_tests = loader.loadTestsFromModuleNames(test_bzrdir_implementations)
104
81
    formats = BzrDirFormat.known_formats()
105
 
    adapter = BzrDirTestProviderAdapter(
 
82
    scenarios = make_scenarios(
106
83
        default_transport,
107
84
        None,
108
85
        # None here will cause a readonly decorator to be created
109
86
        # by the TestCaseWithTransport.get_readonly_transport method.
110
87
        None,
111
88
        formats)
112
 
    # add the tests for the sub modules
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'.
 
89
    # This will always add scenarios using the smart server.
117
90
    from bzrlib.smart.server import (
118
91
        ReadonlySmartTCPServer_for_testing,
119
92
        ReadonlySmartTCPServer_for_testing_v2_only,
121
94
        SmartTCPServer_for_testing_v2_only,
122
95
        )
123
96
    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(
 
97
    # test the remote server behaviour when backed with a MemoryTransport
 
98
    # Once for the current version
 
99
    scenarios.extend(make_scenarios(
128
100
        MemoryServer,
129
101
        SmartTCPServer_for_testing,
130
102
        ReadonlySmartTCPServer_for_testing,
131
103
        [(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(
 
104
        name_suffix='-default'))
 
105
    # And once with < 1.6 - the 'v2' protocol.
 
106
    scenarios.extend(make_scenarios(
138
107
        MemoryServer,
139
108
        SmartTCPServer_for_testing_v2_only,
140
109
        ReadonlySmartTCPServer_for_testing_v2_only,
141
110
        [(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
 
 
149
 
    return result
 
111
        name_suffix='-v2'))
 
112
    # add the tests for the sub modules
 
113
    return multiply_tests(submod_tests, scenarios, standard_tests)