3
3
#
4
4
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
5
5
# Copyright (c) 2010, 2011 Martin Pool <mbp@sourcefrog.net>
6
- #
6
+ #
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
9
9
# project source as Apache-2.0 and BSD. You may not use this file except in
10
10
# compliance with one of these two licences.
11
- #
11
+ #
12
12
# Unless required by applicable law or agreed to in writing, software
13
13
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
14
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
15
# license you chose for the specific language governing permissions and
16
16
# limitations under that license.
17
17
18
18
__all__ = [
19
- ' apply_scenario' ,
20
- ' apply_scenarios' ,
21
- ' generate_scenarios' ,
22
- ' load_tests_apply_scenarios' ,
23
- ' multiply_scenarios' ,
24
- ]
19
+ " apply_scenario" ,
20
+ " apply_scenarios" ,
21
+ " generate_scenarios" ,
22
+ " load_tests_apply_scenarios" ,
23
+ " multiply_scenarios" ,
24
+ ]
25
25
26
26
from itertools import (
27
27
product ,
28
- )
28
+ )
29
29
import sys
30
30
31
31
from testtools .testcase import clone_test_with_new_id
@@ -42,13 +42,12 @@ def apply_scenario(scenario, test):
42
42
:return: A new test cloned from test, with the scenario applied.
43
43
"""
44
44
name , parameters = scenario
45
- scenario_suffix = '(' + name + ')'
46
- newtest = clone_test_with_new_id (test ,
47
- test .id () + scenario_suffix )
45
+ scenario_suffix = "(" + name + ")"
46
+ newtest = clone_test_with_new_id (test , test .id () + scenario_suffix )
48
47
test_desc = test .shortDescription ()
49
48
if test_desc is not None :
50
49
newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars ()
51
- newtest .shortDescription = ( lambda : newtest_desc )
50
+ newtest .shortDescription = lambda : newtest_desc
52
51
for key , value in parameters .items ():
53
52
setattr (newtest , key , value )
54
53
return newtest
@@ -76,7 +75,7 @@ def generate_scenarios(test_or_suite):
76
75
:return: A generator of tests - objects satisfying the TestCase protocol.
77
76
"""
78
77
for test in iterate_tests (test_or_suite ):
79
- scenarios = getattr (test , ' scenarios' , None )
78
+ scenarios = getattr (test , " scenarios" , None )
80
79
if scenarios :
81
80
for newtest in apply_scenarios (scenarios , test ):
82
81
newtest .scenarios = None
@@ -98,10 +97,10 @@ def load_tests_apply_scenarios(*params):
98
97
pattern), and bzr used (standard_tests, module, loader).
99
98
100
99
:param loader: A TestLoader.
101
- :param standard_test: The test objects found in this module before
100
+ :param standard_test: The test objects found in this module before
102
101
multiplication.
103
102
"""
104
- if getattr (params [0 ], ' suiteClass' , None ) is not None :
103
+ if getattr (params [0 ], " suiteClass" , None ) is not None :
105
104
loader , standard_tests , pattern = params
106
105
else :
107
106
standard_tests , module , loader = params
@@ -115,15 +114,15 @@ def multiply_scenarios(*scenarios):
115
114
116
115
It is safe to pass scenario generators or iterators.
117
116
118
- :returns: A list of compound scenarios: the cross-product of all
117
+ :returns: A list of compound scenarios: the cross-product of all
119
118
scenarios, with the names concatenated and the parameters
120
119
merged together.
121
120
"""
122
121
result = []
123
122
scenario_lists = map (list , scenarios )
124
123
for combination in product (* scenario_lists ):
125
124
names , parameters = zip (* combination )
126
- scenario_name = ',' .join (names )
125
+ scenario_name = "," .join (names )
127
126
scenario_parameters = {}
128
127
for parameter in parameters :
129
128
scenario_parameters .update (parameter )
@@ -145,21 +144,19 @@ def per_module_scenarios(attribute_name, modules):
145
144
yet.
146
145
147
146
:param attribute_name: A name to be set in the scenario parameter
148
- dictionary (and thence onto the test instance) pointing to the
147
+ dictionary (and thence onto the test instance) pointing to the
149
148
implementation module (or import exception) for this scenario.
150
149
151
- :param modules: An iterable of (short_name, module_name), where
150
+ :param modules: An iterable of (short_name, module_name), where
152
151
the short name is something like 'python' to put in the
153
152
scenario name, and the long name is a fully-qualified Python module
154
153
name.
155
154
"""
156
155
scenarios = []
157
156
for short_name , module_name in modules :
158
157
try :
159
- mod = __import__ (module_name , {}, {}, ['' ])
158
+ mod = __import__ (module_name , {}, {}, ["" ])
160
159
except BaseException :
161
160
mod = sys .exc_info ()
162
- scenarios .append ((
163
- short_name ,
164
- {attribute_name : mod }))
161
+ scenarios .append ((short_name , {attribute_name : mod }))
165
162
return scenarios
0 commit comments