Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions stdlib/2/unittest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this class? It does not exist in the implementation and I don't really know what purpose it serves in the stubs, especially now that you removed its uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It effectively means Union[TestCase, TestSuite]. I didn't remove all uses, just the ones that I noticed should be TestCase instead.

It shouldn't be a class, but changing that would take a lot more work.

@abstractmethod
def run(self, result: TestResult) -> None: ...
Expand All @@ -26,28 +31,28 @@ 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
failfast: bool

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
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the implementation, we can use Iterable instead of List here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation calls it with TestResult.errors (List) as an argument. Making it List allows implementations in subclasses to assume the argument is a list, which I think is more useful given that it's routinely called by printErrors and there's not much reason to call it from the outside.


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):
...
Expand Down
9 changes: 5 additions & 4 deletions stdlib/3/unittest/result.pyi
Original file line number Diff line number Diff line change
@@ -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:
Expand Down