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

@@ -260,6 +260,7 @@ typing: 3.5-
typing_extensions: 2.7-
unicodedata: 2.7-
unittest: 2.7-
unittest._log: 3.9-
urllib: 2.7-
uu: 2.7-
uuid: 2.7-

27
stdlib/unittest/_log.pyi Normal file
View File

@@ -0,0 +1,27 @@
import logging
import sys
from types import TracebackType
from typing import ClassVar, Generic, NamedTuple, Type, TypeVar
from unittest.case import TestCase
_L = TypeVar("_L", None, _LoggingWatcher)
class _LoggingWatcher(NamedTuple):
records: list[logging.LogRecord]
output: list[str]
class _AssertLogsContext(Generic[_L]):
LOGGING_FORMAT: ClassVar[str]
test_case: TestCase
logger_name: str
level: int
msg: None
if sys.version_info >= (3, 10):
def __init__(self, test_case: TestCase, logger_name: str, level: int, no_logs: bool) -> None: ...
no_logs: bool
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: ...

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: ...

View File

@@ -60,6 +60,7 @@ typing.NamedTuple._make
typing.NamedTuple._replace
typing.Sequence.index
typing.runtime_checkable
unittest._log # New in Python 3.9
unittest.async_case # Added in Python 3.8
uuid.UUID.int
xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modules, fixed in bpo-39495

View File

@@ -53,6 +53,7 @@ typing.NamedTuple._replace
typing._SpecialForm.__init__
typing._SpecialForm.__new__
typing.runtime_checkable
unittest._log # New in Python 3.9
unittest.async_case # Added in Python 3.8
uuid.UUID.int
uuid.UUID.is_safe

View File

@@ -73,6 +73,7 @@ typing.SupportsInt.__init__
typing.SupportsRound.__init__
typing._SpecialForm.__init__
typing._SpecialForm.__new__
unittest._log # New in Python 3.9
uuid.getnode # undocumented, unused parameter getters that was later removed
weakref.WeakValueDictionary.update
xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modules, fixed in bpo-39495