mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 12:14:27 +08:00
fixes for unittest.runner (#13205)
This commit is contained in:
@@ -6,21 +6,22 @@ from _typeshed import SupportsFlush, SupportsWrite
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import Any, Generic, Protocol, TypeVar
|
||||
from typing_extensions import Never, TypeAlias
|
||||
from warnings import _ActionKind
|
||||
|
||||
_ResultClassType: TypeAlias = Callable[[_TextTestStream, bool, int], TextTestResult]
|
||||
_ResultClassType: TypeAlias = Callable[[_TextTestStream, bool, int], TextTestResult[Any]]
|
||||
|
||||
class _SupportsWriteAndFlush(SupportsWrite[str], SupportsFlush, Protocol): ...
|
||||
|
||||
# All methods used by unittest.runner.TextTestResult's stream
|
||||
class _TextTestStream(_SupportsWriteAndFlush, Protocol):
|
||||
def writeln(self, arg: str | None = None, /) -> str: ...
|
||||
def writeln(self, arg: str | None = None, /) -> None: ...
|
||||
|
||||
# _WritelnDecorator should have all the same attrs as its stream param.
|
||||
# But that's not feasible to do Generically
|
||||
# We can expand the attributes if requested
|
||||
class _WritelnDecorator:
|
||||
def __init__(self, stream: _TextTestStream) -> None: ...
|
||||
def writeln(self, arg: str | None = None) -> str: ...
|
||||
def __init__(self, stream: _SupportsWriteAndFlush) -> None: ...
|
||||
def writeln(self, arg: str | None = None) -> None: ...
|
||||
def __getattr__(self, attr: str) -> Any: ... # Any attribute from the stream type passed to __init__
|
||||
# These attributes are prevented by __getattr__
|
||||
stream: Never
|
||||
@@ -39,10 +40,8 @@ class TextTestResult(unittest.result.TestResult, Generic[_StreamT]):
|
||||
showAll: bool # undocumented
|
||||
stream: _StreamT # undocumented
|
||||
if sys.version_info >= (3, 12):
|
||||
durations: unittest.result._DurationsType | None
|
||||
def __init__(
|
||||
self, stream: _StreamT, descriptions: bool, verbosity: int, *, durations: unittest.result._DurationsType | None = None
|
||||
) -> None: ...
|
||||
durations: int | None
|
||||
def __init__(self, stream: _StreamT, descriptions: bool, verbosity: int, *, durations: int | None = None) -> None: ...
|
||||
else:
|
||||
def __init__(self, stream: _StreamT, descriptions: bool, verbosity: int) -> None: ...
|
||||
|
||||
@@ -56,11 +55,11 @@ class TextTestRunner:
|
||||
verbosity: int
|
||||
failfast: bool
|
||||
buffer: bool
|
||||
warnings: str | None
|
||||
warnings: _ActionKind | None
|
||||
tb_locals: bool
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
durations: unittest.result._DurationsType | None
|
||||
durations: int | None
|
||||
def __init__(
|
||||
self,
|
||||
stream: _SupportsWriteAndFlush | None = None,
|
||||
@@ -69,10 +68,10 @@ class TextTestRunner:
|
||||
failfast: bool = False,
|
||||
buffer: bool = False,
|
||||
resultclass: _ResultClassType | None = None,
|
||||
warnings: str | None = None,
|
||||
warnings: _ActionKind | None = None,
|
||||
*,
|
||||
tb_locals: bool = False,
|
||||
durations: unittest.result._DurationsType | None = None,
|
||||
durations: int | None = None,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
|
||||
Reference in New Issue
Block a user