From a705d59479deb3786ce25002385303c70cfa5e50 Mon Sep 17 00:00:00 2001 From: Jan Verbeek <55185397+janverb@users.noreply.github.com> Date: Thu, 19 Dec 2019 18:17:14 +0100 Subject: [PATCH] Add undocumented methods and make types more specific in 2/unittest (#3550) --- stdlib/2/unittest.pyi | 35 ++++++++++++++++++++++------------- stdlib/3/unittest/result.pyi | 9 +++++---- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/stdlib/2/unittest.pyi b/stdlib/2/unittest.pyi index 366a37352..4eb84617d 100644 --- a/stdlib/2/unittest.pyi +++ b/stdlib/2/unittest.pyi @@ -15,6 +15,11 @@ _FT = TypeVar('_FT') _ExceptionType = Union[Type[BaseException], Tuple[Type[BaseException], ...]] _Regexp = Union[Text, Pattern[Text]] +_SysExcInfoType = Union[ + Tuple[Type[BaseException], BaseException, types.TracebackType], + Tuple[None, None, None], +] + class Testable(metaclass=ABCMeta): @abstractmethod def run(self, result: TestResult) -> None: ... @@ -26,11 +31,11 @@ class Testable(metaclass=ABCMeta): # TODO ABC for test runners? class TestResult: - errors: List[Tuple[Testable, str]] - failures: List[Tuple[Testable, str]] - skipped: List[Tuple[Testable, str]] - expectedFailures: List[Tuple[Testable, str]] - unexpectedSuccesses: List[Testable] + errors: List[Tuple[TestCase, str]] + failures: List[Tuple[TestCase, str]] + skipped: List[Tuple[TestCase, str]] + expectedFailures: List[Tuple[TestCase, str]] + unexpectedSuccesses: List[TestCase] shouldStop: bool testsRun: int buffer: bool @@ -38,16 +43,16 @@ class TestResult: def wasSuccessful(self) -> bool: ... def stop(self) -> None: ... - def startTest(self, test: Testable) -> None: ... - def stopTest(self, test: Testable) -> None: ... + def startTest(self, test: TestCase) -> None: ... + def stopTest(self, test: TestCase) -> None: ... def startTestRun(self) -> None: ... def stopTestRun(self) -> None: ... - def addError(self, test: Testable, err: Tuple[type, Any, Any]) -> None: ... # TODO - def addFailure(self, test: Testable, err: Tuple[type, Any, Any]) -> None: ... # TODO - def addSuccess(self, test: Testable) -> None: ... - def addSkip(self, test: Testable, reason: str) -> None: ... - def addExpectedFailure(self, test: Testable, err: str) -> None: ... - def addUnexpectedSuccess(self, test: Testable) -> None: ... + def addError(self, test: TestCase, err: _SysExcInfoType) -> None: ... + def addFailure(self, test: TestCase, err: _SysExcInfoType) -> None: ... + def addSuccess(self, test: TestCase) -> None: ... + def addSkip(self, test: TestCase, reason: str) -> None: ... + def addExpectedFailure(self, test: TestCase, err: str) -> None: ... + def addUnexpectedSuccess(self, test: TestCase) -> None: ... class _AssertRaisesBaseContext: expected: Any @@ -240,12 +245,16 @@ defaultTestLoader: TestLoader class TextTestResult(TestResult): def __init__(self, stream: TextIO, descriptions: bool, verbosity: int) -> None: ... + def getDescription(self, test: TestCase) -> str: ... # undocumented + def printErrors(self) -> None: ... # undocumented + def printErrorList(self, flavour: str, errors: List[Tuple[TestCase, str]]) -> None: ... # undocumented class TextTestRunner: def __init__(self, stream: Optional[TextIO] = ..., descriptions: bool = ..., verbosity: int = ..., failfast: bool = ..., buffer: bool = ..., resultclass: Optional[Type[TestResult]] = ...) -> None: ... def _makeResult(self) -> TestResult: ... + def run(self, test: Testable) -> TestResult: ... # undocumented class SkipTest(Exception): ... diff --git a/stdlib/3/unittest/result.pyi b/stdlib/3/unittest/result.pyi index 6ce685a29..337b93b7d 100644 --- a/stdlib/3/unittest/result.pyi +++ b/stdlib/3/unittest/result.pyi @@ -1,11 +1,12 @@ -from typing import List, Optional, Tuple, Type +from typing import List, Optional, Tuple, Type, Union from types import TracebackType import unittest.case -_SysExcInfoType = Tuple[Optional[Type[BaseException]], - Optional[BaseException], - Optional[TracebackType]] +_SysExcInfoType = Union[ + Tuple[Type[BaseException], BaseException, TracebackType], + Tuple[None, None, None], +] class TestResult: