Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _handle_exception_matching(expectation):
return_values = _getattr(expectation, 'return_values')
if return_values:
raised, instance = sys.exc_info()[:2]
message = '%s' % instance
expected = return_values[0].raises
if not expected:
raise
args = return_values[0].value
expected_instance = expected(*args['kargs'], **args['kwargs'])
expected_message = '%s' % expected_instance
if _isclass(expected):
if expected is not raised and expected not in raised.__bases__:
raise (ExceptionClassError('expected %s, raised %s' %
(expected, raised)))
if args['kargs'] and type(RE_TYPE) is type(args['kargs'][0]):
if not args['kargs'][0].search(message):
raise (ExceptionMessageError('expected /%s/, raised "%s"' %
(args['kargs'][0].pattern, message)))
elif expected_message and expected_message != message:
raise (ExceptionMessageError('expected "%s", raised "%s"' %
(expected_message, message)))
elif expected is not raised:
raise (ExceptionClassError('expected "%s", raised "%s"' %
(expected, raised)))
else:
raise
args = return_values[0].value
expected_instance = expected(*args['kargs'], **args['kwargs'])
expected_message = '%s' % expected_instance
if _isclass(expected):
if expected is not raised and expected not in raised.__bases__:
raise (ExceptionClassError('expected %s, raised %s' %
(expected, raised)))
if args['kargs'] and type(RE_TYPE) is type(args['kargs'][0]):
if not args['kargs'][0].search(message):
raise (ExceptionMessageError('expected /%s/, raised "%s"' %
(args['kargs'][0].pattern, message)))
elif expected_message and expected_message != message:
raise (ExceptionMessageError('expected "%s", raised "%s"' %
(expected_message, message)))
elif expected is not raised:
raise (ExceptionClassError('expected "%s", raised "%s"' %
(expected, raised)))
else:
raise