Create unittest._log stub and improve _AssertLogsContext (#6428)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Akuli
2021-12-01 07:39:14 +02:00
committed by GitHub
parent 6246e7856c
commit b3e8073bac
6 changed files with 32 additions and 19 deletions

View File

@@ -14,7 +14,6 @@ from typing import (
Generic,
Iterable,
Mapping,
NamedTuple,
NoReturn,
Pattern,
Sequence,
@@ -23,6 +22,7 @@ from typing import (
TypeVar,
overload,
)
from unittest._log import _AssertLogsContext, _LoggingWatcher
from warnings import WarningMessage
if sys.version_info >= (3, 9):
@@ -30,7 +30,6 @@ if sys.version_info >= (3, 9):
_E = TypeVar("_E", bound=BaseException)
_FT = TypeVar("_FT", bound=Callable[..., Any])
_L = TypeVar("_L", None, _LoggingWatcher)
if sys.version_info >= (3, 8):
def addModuleCleanup(__function: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ...
@@ -251,10 +250,6 @@ class FunctionTestCase(TestCase):
) -> None: ...
def runTest(self) -> None: ...
class _LoggingWatcher(NamedTuple):
records: list[logging.LogRecord]
output: list[str]
class _AssertRaisesContext(Generic[_E]):
exception: _E
def __enter__(self: Self) -> Self: ...
@@ -273,16 +268,3 @@ class _AssertWarnsContext:
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
class _AssertLogsContext(Generic[_L]):
LOGGING_FORMAT: str
records: list[logging.LogRecord]
output: list[str]
if sys.version_info >= (3, 10):
def __init__(self, test_case: TestCase, logger_name: str, level: int, no_logs: bool) -> None: ...
else:
def __init__(self, test_case: TestCase, logger_name: str, level: int) -> None: ...
def __enter__(self) -> _L: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...