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>
6
7
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
7
8
# license at the users choice. A copy of both licenses are available in the
88
def load_tests_apply_scenarios(*params):
89
"""Adapter test runner load hooks to call generate_scenarios.
91
If this is referenced by the `load_tests` attribute of a module, then
92
testloaders that implement this protocol will automatically arrange for
93
the scenarios to be expanded. This can be used instead of using
96
Two different calling conventions for load_tests have been used, and this
97
function should support both. Python 2.7 passes (loader, standard_tests,
98
pattern), and bzr used (standard_tests, module, loader).
100
:param loader: A TestLoader.
101
:param standard_test: The test objects found in this module before
104
if getattr(params[0], 'suiteClass', None) is not None:
105
loader, standard_tests, pattern = params
107
standard_tests, module, loader = params
108
result = loader.suiteClass()
109
result.addTests(generate_scenarios(standard_tests))
113
def multiply_scenarios(*scenarios):
114
"""Multiply two or more iterables of scenarios.
116
It is safe to pass scenario generators or iterators.
118
:returns: A list of compound scenarios: the cross-product of all
119
scenarios, with the names concatenated and the parameters
123
scenario_lists = map(list, scenarios)
124
for combination in product(*scenario_lists):
125
names, parameters = zip(*combination)
126
scenario_name = ','.join(names)
127
scenario_parameters = {}
128
for parameter in parameters:
129
scenario_parameters.update(parameter)
130
result.append((scenario_name, scenario_parameters))