diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 1efc2103b..f3f9aaee3 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -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- diff --git a/stdlib/unittest/_log.pyi b/stdlib/unittest/_log.pyi new file mode 100644 index 000000000..f9e406199 --- /dev/null +++ b/stdlib/unittest/_log.pyi @@ -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: ... diff --git a/stdlib/unittest/case.pyi b/stdlib/unittest/case.pyi index 9bcd2c05a..f60f8d6dc 100644 --- a/stdlib/unittest/case.pyi +++ b/stdlib/unittest/case.pyi @@ -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: ... diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index f10811e38..bde1defc1 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -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 diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index cc23ab809..5d52641ad 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -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 diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index c39e36660..384e21329 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -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