Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve types for DiscoverRunner #1106

Merged
merged 7 commits into from
Aug 26, 2022
Merged
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
37 changes: 29 additions & 8 deletions django-stubs/test/runner.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import logging
from argparse import ArgumentParser
from contextlib import contextmanager
from io import StringIO
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type
from unittest import TestCase, TestSuite, TextTestResult
from typing import Any, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union
from unittest import TestCase, TestLoader, TestSuite, TextTestResult, TextTestRunner

from django.db.backends.base.base import BaseDatabaseWrapper
from django.test.testcases import SimpleTestCase, TestCase
from django.test.utils import TimeKeeperProtocol
from django.utils.datastructures import OrderedSet
from typing_extensions import Literal

class DebugSQLTextTestResult(TextTestResult):
buffer: bool
Expand All @@ -33,6 +36,8 @@ class DebugSQLTextTestResult(TextTestResult):
def addError(self, test: Any, err: Any) -> None: ...
def addFailure(self, test: Any, err: Any) -> None: ...

class PDBDebugResult(TextTestResult): ...

class RemoteTestResult:
events: List[Any] = ...
failfast: bool = ...
Expand Down Expand Up @@ -77,11 +82,11 @@ class ParallelTestSuite(TestSuite):
def run(self, result: Any): ... # type: ignore[override]

class DiscoverRunner:
test_suite: Any = ...
parallel_test_suite: Any = ...
test_runner: Any = ...
test_loader: Any = ...
reorder_by: Any = ...
test_suite: Type[TestSuite] = ...
parallel_test_suite: Type[ParallelTestSuite] = ...
test_runner: Type[TextTestRunner] = ...
test_loader: TestLoader = ...
reorder_by: Tuple[SimpleTestCase, ...] = ...
pattern: Optional[str] = ...
top_level: Optional[str] = ...
verbosity: int = ...
Expand All @@ -94,6 +99,12 @@ class DiscoverRunner:
parallel: int = ...
tags: Set[str] = ...
exclude_tags: Set[str] = ...
pdb: bool = ...
buffer: bool = ...
test_name_patterns: Optional[Set[str]] = ...
time_keeper: TimeKeeperProtocol = ...
shuffle: Union[int, Literal[False]] = ...
logger: Optional[logging.Logger] = ...
def __init__(
self,
pattern: Optional[str] = ...,
Expand All @@ -113,22 +124,32 @@ class DiscoverRunner:
buffer: bool = ...,
enable_faulthandler: bool = ...,
timing: bool = ...,
shuffle: Union[int, Literal[False]] = ...,
logger: Optional[logging.Logger] = ...,
**kwargs: Any
) -> None: ...
@classmethod
def add_arguments(cls, parser: ArgumentParser) -> None: ...
@property
def shuffle_seed(self) -> Optional[int]: ...
def log(self, msg: str, level: Optional[int]) -> None: ...
def setup_test_environment(self, **kwargs: Any) -> None: ...
def setup_shuffler(self) -> None: ...
@contextmanager
def load_with_patterns(self) -> Iterator[None]: ...
def load_tests_for_label(self, label: str, discover_kwargs: Dict[str, str]) -> TestSuite: ...
def build_suite(
self, test_labels: Sequence[str] = ..., extra_tests: Optional[List[Any]] = ..., **kwargs: Any
) -> TestSuite: ...
def setup_databases(self, **kwargs: Any) -> List[Tuple[BaseDatabaseWrapper, str, bool]]: ...
def get_resultclass(self) -> Optional[Type[TextTestResult]]: ...
def get_test_runner_kwargs(self) -> Dict[str, Optional[int]]: ...
def get_test_runner_kwargs(self) -> Dict[str, Any]: ...
def run_checks(self, databases: Set[str]) -> None: ...
def run_suite(self, suite: TestSuite, **kwargs: Any) -> TextTestResult: ...
def teardown_databases(self, old_config: List[Tuple[BaseDatabaseWrapper, str, bool]], **kwargs: Any) -> None: ...
def teardown_test_environment(self, **kwargs: Any) -> None: ...
def suite_result(self, suite: TestSuite, result: TextTestResult, **kwargs: Any) -> int: ...
def _get_databases(self, suite: TestSuite) -> Set[str]: ...
def get_databases(self, suite: TestSuite) -> Set[str]: ...
def run_tests(self, test_labels: List[str], extra_tests: Optional[List[Any]] = ..., **kwargs: Any) -> int: ...

Expand Down