33#
44# Copyright (c) 2009, Robert Collins <[email protected] > 55# Copyright (c) 2010, 2011 Martin Pool <[email protected] > 6- #
6+ #
77# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
88# license at the users choice. A copy of both licenses are available in the
99# project source as Apache-2.0 and BSD. You may not use this file except in
1010# compliance with one of these two licences.
11- #
11+ #
1212# Unless required by applicable law or agreed to in writing, software
1313# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1414# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1515# license you chose for the specific language governing permissions and
1616# limitations under that license.
1717
1818__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+ ]
2525
2626from itertools import (
2727 product ,
28- )
28+ )
2929import sys
3030
3131from testtools .testcase import clone_test_with_new_id
@@ -42,13 +42,12 @@ def apply_scenario(scenario, test):
4242 :return: A new test cloned from test, with the scenario applied.
4343 """
4444 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 )
4847 test_desc = test .shortDescription ()
4948 if test_desc is not None :
5049 newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars ()
51- newtest .shortDescription = ( lambda : newtest_desc )
50+ newtest .shortDescription = lambda : newtest_desc
5251 for key , value in parameters .items ():
5352 setattr (newtest , key , value )
5453 return newtest
@@ -76,7 +75,7 @@ def generate_scenarios(test_or_suite):
7675 :return: A generator of tests - objects satisfying the TestCase protocol.
7776 """
7877 for test in iterate_tests (test_or_suite ):
79- scenarios = getattr (test , ' scenarios' , None )
78+ scenarios = getattr (test , " scenarios" , None )
8079 if scenarios :
8180 for newtest in apply_scenarios (scenarios , test ):
8281 newtest .scenarios = None
@@ -98,10 +97,10 @@ def load_tests_apply_scenarios(*params):
9897 pattern), and bzr used (standard_tests, module, loader).
9998
10099 :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
102101 multiplication.
103102 """
104- if getattr (params [0 ], ' suiteClass' , None ) is not None :
103+ if getattr (params [0 ], " suiteClass" , None ) is not None :
105104 loader , standard_tests , pattern = params
106105 else :
107106 standard_tests , module , loader = params
@@ -115,15 +114,15 @@ def multiply_scenarios(*scenarios):
115114
116115 It is safe to pass scenario generators or iterators.
117116
118- :returns: A list of compound scenarios: the cross-product of all
117+ :returns: A list of compound scenarios: the cross-product of all
119118 scenarios, with the names concatenated and the parameters
120119 merged together.
121120 """
122121 result = []
123122 scenario_lists = map (list , scenarios )
124123 for combination in product (* scenario_lists ):
125124 names , parameters = zip (* combination )
126- scenario_name = ',' .join (names )
125+ scenario_name = "," .join (names )
127126 scenario_parameters = {}
128127 for parameter in parameters :
129128 scenario_parameters .update (parameter )
@@ -145,21 +144,19 @@ def per_module_scenarios(attribute_name, modules):
145144 yet.
146145
147146 :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
149148 implementation module (or import exception) for this scenario.
150149
151- :param modules: An iterable of (short_name, module_name), where
150+ :param modules: An iterable of (short_name, module_name), where
152151 the short name is something like 'python' to put in the
153152 scenario name, and the long name is a fully-qualified Python module
154153 name.
155154 """
156155 scenarios = []
157156 for short_name , module_name in modules :
158157 try :
159- mod = __import__ (module_name , {}, {}, ['' ])
158+ mod = __import__ (module_name , {}, {}, ["" ])
160159 except BaseException :
161160 mod = sys .exc_info ()
162- scenarios .append ((
163- short_name ,
164- {attribute_name : mod }))
161+ scenarios .append ((short_name , {attribute_name : mod }))
165162 return scenarios
0 commit comments