2
2
# dependency injection ('scenarios') by tests.
4
4
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5
# Copyright (c) 2010 Martin Pool <mbp@sourcefrog.net>
5
# Copyright (c) 2010, 2011 Martin Pool <mbp@sourcefrog.net>
7
7
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
8
8
# license at the users choice. A copy of both licenses are available in the
129
129
scenario_parameters.update(parameter)
130
130
result.append((scenario_name, scenario_parameters))
134
def per_module_scenarios(attribute_name, modules):
135
"""Generate scenarios for available implementation modules.
137
This is typically used when there is a subsystem implemented, for
138
example, in both Python and C, and we want to apply the same tests to
139
both, but the C module may sometimes not be available.
141
Note: if the module can't be loaded, it's silently omitted from
144
:param attribute_name: A name to be set in the scenario parameter
145
dictionary (and thence onto the test instance) pointing to the
146
implementation module for this scenario.
148
:param modules: An iterable of (short_name, module_name), where
149
the short name is something like 'python' to put in the
150
scenario name, and the long name is a fully-qualified Python module
154
for short_name, module_name in modules:
156
mod = __import__(module_name, {}, {}, [''])
158
# TODO: optionally pass this back through a callback, so it can be
164
{attribute_name: mod}))