Use explanatory functions for gnarly exception handling logic.
This commit is contained in:
@@ -23,6 +23,14 @@ from ._impl import (
|
|||||||
_error_repr = BaseException.__repr__
|
_error_repr = BaseException.__repr__
|
||||||
|
|
||||||
|
|
||||||
|
def _is_exception(exc):
|
||||||
|
return isinstance(exc, BaseException)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_user_exception(exc):
|
||||||
|
return isinstance(exc, Exception)
|
||||||
|
|
||||||
|
|
||||||
class MatchesException(Matcher):
|
class MatchesException(Matcher):
|
||||||
"""Match an exc_info tuple against an exception instance or type."""
|
"""Match an exc_info tuple against an exception instance or type."""
|
||||||
|
|
||||||
@@ -104,10 +112,10 @@ class Raises(Matcher):
|
|||||||
else:
|
else:
|
||||||
mismatch = None
|
mismatch = None
|
||||||
# The exception did not match, or no explicit matching logic was
|
# The exception did not match, or no explicit matching logic was
|
||||||
# performed. If the exception is a non-user exception (that is, not
|
# performed. If the exception is a non-user exception then
|
||||||
# a subclass of Exception) then propagate it.
|
# propagate it.
|
||||||
if (isinstance(exc_info[1], BaseException)
|
exception = exc_info[1]
|
||||||
and not isinstance(exc_info[1], Exception)):
|
if _is_exception(exception) and not _is_user_exception(exception):
|
||||||
del exc_info
|
del exc_info
|
||||||
raise
|
raise
|
||||||
return mismatch
|
return mismatch
|
||||||
|
|||||||
Reference in New Issue
Block a user