[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,5 +1,6 @@
"""Exception classes and constants handling test outcomes as well as
functions creating them."""
from __future__ import annotations
import sys
from typing import Any
@ -16,11 +17,11 @@ class OutcomeException(BaseException):
"""OutcomeException and its subclass instances indicate and contain info
about test and collection outcomes."""
def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None:
def __init__(self, msg: str | None = None, pytrace: bool = True) -> None:
if msg is not None and not isinstance(msg, str):
error_msg = ( # type: ignore[unreachable]
"{} expected string as 'msg' parameter, got '{}' instead.\n"
"Perhaps you meant to use a mark?"
'Perhaps you meant to use a mark?'
)
raise TypeError(error_msg.format(type(self).__name__, type(msg).__name__))
super().__init__(msg)
@ -30,7 +31,7 @@ class OutcomeException(BaseException):
def __repr__(self) -> str:
if self.msg is not None:
return self.msg
return f"<{self.__class__.__name__} instance>"
return f'<{self.__class__.__name__} instance>'
__str__ = __repr__
@ -41,11 +42,11 @@ TEST_OUTCOME = (OutcomeException, Exception)
class Skipped(OutcomeException):
# XXX hackish: on 3k we fake to live in the builtins
# in order to have Skipped exception printing shorter/nicer
__module__ = "builtins"
__module__ = 'builtins'
def __init__(
self,
msg: Optional[str] = None,
msg: str | None = None,
pytrace: bool = True,
allow_module_level: bool = False,
*,
@ -61,14 +62,14 @@ class Skipped(OutcomeException):
class Failed(OutcomeException):
"""Raised from an explicit call to pytest.fail()."""
__module__ = "builtins"
__module__ = 'builtins'
class Exit(Exception):
"""Raised for immediate program exits (no tracebacks/summaries)."""
def __init__(
self, msg: str = "unknown reason", returncode: Optional[int] = None
self, msg: str = 'unknown reason', returncode: int | None = None,
) -> None:
self.msg = msg
self.returncode = returncode
@ -78,8 +79,8 @@ class Exit(Exception):
# Elaborate hack to work around https://github.com/python/mypy/issues/2087.
# Ideally would just be `exit.Exception = Exit` etc.
_F = TypeVar("_F", bound=Callable[..., object])
_ET = TypeVar("_ET", bound=Type[BaseException])
_F = TypeVar('_F', bound=Callable[..., object])
_ET = TypeVar('_ET', bound=Type[BaseException])
class _WithException(Protocol[_F, _ET]):
@ -101,8 +102,8 @@ def _with_exception(exception_type: _ET) -> Callable[[_F], _WithException[_F, _E
@_with_exception(Exit)
def exit(
reason: str = "",
returncode: Optional[int] = None,
reason: str = '',
returncode: int | None = None,
) -> NoReturn:
"""Exit testing process.
@ -119,7 +120,7 @@ def exit(
@_with_exception(Skipped)
def skip(
reason: str = "",
reason: str = '',
*,
allow_module_level: bool = False,
) -> NoReturn:
@ -152,7 +153,7 @@ def skip(
@_with_exception(Failed)
def fail(reason: str = "", pytrace: bool = True) -> NoReturn:
def fail(reason: str = '', pytrace: bool = True) -> NoReturn:
"""Explicitly fail an executing test with the given message.
:param reason:
@ -171,7 +172,7 @@ class XFailed(Failed):
@_with_exception(XFailed)
def xfail(reason: str = "") -> NoReturn:
def xfail(reason: str = '') -> NoReturn:
"""Imperatively xfail an executing test or setup function with the given reason.
This function should be called only during testing (setup, call or teardown).
@ -192,7 +193,7 @@ def xfail(reason: str = "") -> NoReturn:
def importorskip(
modname: str, minversion: Optional[str] = None, reason: Optional[str] = None
modname: str, minversion: str | None = None, reason: str | None = None,
) -> Any:
"""Import and return the requested module ``modname``, or skip the
current test if the module cannot be imported.
@ -216,30 +217,30 @@ def importorskip(
import warnings
__tracebackhide__ = True
compile(modname, "", "eval") # to catch syntaxerrors
compile(modname, '', 'eval') # to catch syntaxerrors
with warnings.catch_warnings():
# Make sure to ignore ImportWarnings that might happen because
# of existing directories with the same name we're trying to
# import but without a __init__.py file.
warnings.simplefilter("ignore")
warnings.simplefilter('ignore')
try:
__import__(modname)
except ImportError as exc:
if reason is None:
reason = f"could not import {modname!r}: {exc}"
reason = f'could not import {modname!r}: {exc}'
raise Skipped(reason, allow_module_level=True) from None
mod = sys.modules[modname]
if minversion is None:
return mod
verattr = getattr(mod, "__version__", None)
verattr = getattr(mod, '__version__', None)
if minversion is not None:
# Imported lazily to improve start-up time.
from packaging.version import Version
if verattr is None or Version(verattr) < Version(minversion):
raise Skipped(
f"module {modname!r} has __version__ {verattr!r}, required is: {minversion!r}",
f'module {modname!r} has __version__ {verattr!r}, required is: {minversion!r}',
allow_module_level=True,
)
return mod