Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if expectation.return_values:
raised, instance = sys.exc_info()[:2]
message = '%s' % instance
expected = expectation.return_values[0].raises
if not expected:
raise
args = expectation.return_values[0].value
expected_instance = expected(*args['kargs'], **args['kwargs'])
expected_message = '%s' % expected_instance
if inspect.isclass(expected):
if expected is not raised and expected not in raised.__bases__:
raise (InvalidExceptionClass('expected %s, raised %s' %
(expected, raised)))
if args['kargs'] and '_sre.SRE_Pattern' in str(args['kargs'][0]):
if not args['kargs'][0].search(message):
raise (InvalidExceptionMessage('expected /%s/, raised "%s"' %
(args['kargs'][0].pattern, message)))
elif expected_message and expected_message != message:
raise (InvalidExceptionMessage('expected "%s", raised "%s"' %
(expected_message, message)))
elif expected is not raised:
raise (InvalidExceptionClass('expected "%s", raised "%s"' %
(expected, raised)))
expected = expectation.return_values[0].raises
if not expected:
raise
args = expectation.return_values[0].value
expected_instance = expected(*args['kargs'], **args['kwargs'])
expected_message = '%s' % expected_instance
if inspect.isclass(expected):
if expected is not raised and expected not in raised.__bases__:
raise (InvalidExceptionClass('expected %s, raised %s' %
(expected, raised)))
if args['kargs'] and '_sre.SRE_Pattern' in str(args['kargs'][0]):
if not args['kargs'][0].search(message):
raise (InvalidExceptionMessage('expected /%s/, raised "%s"' %
(args['kargs'][0].pattern, message)))
elif expected_message and expected_message != message:
raise (InvalidExceptionMessage('expected "%s", raised "%s"' %
(expected_message, message)))
elif expected is not raised:
raise (InvalidExceptionClass('expected "%s", raised "%s"' %
(expected, raised)))