Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, target, method, original_callable, exception):
super(_RaiseRunner, self).__init__(target, method, original_callable)
self.exception = exception
def to_raise(self, ex):
"""
Raises given exception class or exception instance.
"""
if isinstance(ex, BaseException):
self._add_runner(
_RaiseRunner(
self._original_target, self._method, self._original_callable, ex
)
)
elif isinstance(ex(), BaseException):
self._add_runner(
_RaiseRunner(
self._original_target, self._method, self._original_callable, ex()
)
)
else:
raise ValueError(
"{} is not subclass or instance of BaseException".format(ex)
)
return self
def to_raise(self, ex):
"""
Raises given exception class or exception instance.
"""
if isinstance(ex, BaseException):
self._add_runner(
_RaiseRunner(
self._original_target, self._method, self._original_callable, ex
)
)
elif isinstance(ex(), BaseException):
self._add_runner(
_RaiseRunner(
self._original_target, self._method, self._original_callable, ex()
)
)
else:
raise ValueError(
"{} is not subclass or instance of BaseException".format(ex)
)
return self