Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _testsFromGenerator(self, event, name, generator, testCaseClass):
try:
for index, (func, args) in self.unpack(generator):
method_name = util.name_from_args(name, index, args)
setattr(testCaseClass, method_name, None)
instance = testCaseClass(method_name)
delattr(testCaseClass, method_name)
def method(func=func, args=args):
return func(*args)
method = functools.update_wrapper(method, func)
setattr(instance, method_name, method)
yield instance
except Exception as e:
test_name = '%s.%s.%s' % (testCaseClass.__module__,
testCaseClass.__name__,
name)
yield event.loader.failedLoadTests(test_name, e)
def _generate(self, event, name, method, testCaseClass):
names = []
for index, argSet in enumerate_params(method.paramList):
method_name = util.name_from_args(name, index, argSet)
if not hasattr(testCaseClass, method_name):
# not already generated
def _method(self, method=method, argSet=argSet):
return method(self, *argSet)
_method = functools.update_wrapper(_method, method)
delattr(_method, 'paramList')
setattr(testCaseClass, method_name, _method)
names.append(method_name)
return names
def _generateFuncTests(self, obj):
args = {}
setUp = getattr(obj, 'setUp', None)
tearDown = getattr(obj, 'tearDown', None)
if setUp is not None:
args['setUp'] = setUp
if tearDown is not None:
args['tearDown'] = tearDown
for index, argSet in enumerate_params(obj.paramList):
def func(argSet=argSet, obj=obj):
return obj(*argSet)
func = functools.update_wrapper(func, obj)
delattr(func, 'paramList')
name = '%s.%s' % (obj.__module__, obj.__name__)
func_name = util.name_from_args(name, index, argSet)
yield util.transplant_class(
ParamsFunctionCase, obj.__module__)(func_name, func, **args)