mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-15 00:07:09 +08:00
Improve types for DiscoverRunner (#1106)
* Improve types for DiscoverRunner * add types for class-level attrs * Add extra methods * Add PDBDebugResult class * black * Update django-stubs/test/runner.pyi * fix load_with_patterns return Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
import logging
|
import logging
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from contextlib import contextmanager
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type
|
from typing import Any, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union
|
||||||
from unittest import TestCase, TestSuite, TextTestResult
|
from unittest import TestCase, TestLoader, TestSuite, TextTestResult, TextTestRunner
|
||||||
|
|
||||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||||
from django.test.testcases import SimpleTestCase, TestCase
|
from django.test.testcases import SimpleTestCase, TestCase
|
||||||
|
from django.test.utils import TimeKeeperProtocol
|
||||||
from django.utils.datastructures import OrderedSet
|
from django.utils.datastructures import OrderedSet
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
class DebugSQLTextTestResult(TextTestResult):
|
class DebugSQLTextTestResult(TextTestResult):
|
||||||
buffer: bool
|
buffer: bool
|
||||||
@@ -33,6 +36,8 @@ class DebugSQLTextTestResult(TextTestResult):
|
|||||||
def addError(self, test: Any, err: Any) -> None: ...
|
def addError(self, test: Any, err: Any) -> None: ...
|
||||||
def addFailure(self, test: Any, err: Any) -> None: ...
|
def addFailure(self, test: Any, err: Any) -> None: ...
|
||||||
|
|
||||||
|
class PDBDebugResult(TextTestResult): ...
|
||||||
|
|
||||||
class RemoteTestResult:
|
class RemoteTestResult:
|
||||||
events: List[Any] = ...
|
events: List[Any] = ...
|
||||||
failfast: bool = ...
|
failfast: bool = ...
|
||||||
@@ -77,11 +82,11 @@ class ParallelTestSuite(TestSuite):
|
|||||||
def run(self, result: Any): ... # type: ignore[override]
|
def run(self, result: Any): ... # type: ignore[override]
|
||||||
|
|
||||||
class DiscoverRunner:
|
class DiscoverRunner:
|
||||||
test_suite: Any = ...
|
test_suite: Type[TestSuite] = ...
|
||||||
parallel_test_suite: Any = ...
|
parallel_test_suite: Type[ParallelTestSuite] = ...
|
||||||
test_runner: Any = ...
|
test_runner: Type[TextTestRunner] = ...
|
||||||
test_loader: Any = ...
|
test_loader: TestLoader = ...
|
||||||
reorder_by: Any = ...
|
reorder_by: Tuple[SimpleTestCase, ...] = ...
|
||||||
pattern: Optional[str] = ...
|
pattern: Optional[str] = ...
|
||||||
top_level: Optional[str] = ...
|
top_level: Optional[str] = ...
|
||||||
verbosity: int = ...
|
verbosity: int = ...
|
||||||
@@ -94,6 +99,12 @@ class DiscoverRunner:
|
|||||||
parallel: int = ...
|
parallel: int = ...
|
||||||
tags: Set[str] = ...
|
tags: Set[str] = ...
|
||||||
exclude_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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
pattern: Optional[str] = ...,
|
pattern: Optional[str] = ...,
|
||||||
@@ -113,22 +124,32 @@ class DiscoverRunner:
|
|||||||
buffer: bool = ...,
|
buffer: bool = ...,
|
||||||
enable_faulthandler: bool = ...,
|
enable_faulthandler: bool = ...,
|
||||||
timing: bool = ...,
|
timing: bool = ...,
|
||||||
|
shuffle: Union[int, Literal[False]] = ...,
|
||||||
|
logger: Optional[logging.Logger] = ...,
|
||||||
**kwargs: Any
|
**kwargs: Any
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_arguments(cls, parser: ArgumentParser) -> None: ...
|
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_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(
|
def build_suite(
|
||||||
self, test_labels: Sequence[str] = ..., extra_tests: Optional[List[Any]] = ..., **kwargs: Any
|
self, test_labels: Sequence[str] = ..., extra_tests: Optional[List[Any]] = ..., **kwargs: Any
|
||||||
) -> TestSuite: ...
|
) -> TestSuite: ...
|
||||||
def setup_databases(self, **kwargs: Any) -> List[Tuple[BaseDatabaseWrapper, str, bool]]: ...
|
def setup_databases(self, **kwargs: Any) -> List[Tuple[BaseDatabaseWrapper, str, bool]]: ...
|
||||||
def get_resultclass(self) -> Optional[Type[TextTestResult]]: ...
|
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_checks(self, databases: Set[str]) -> None: ...
|
||||||
def run_suite(self, suite: TestSuite, **kwargs: Any) -> TextTestResult: ...
|
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_databases(self, old_config: List[Tuple[BaseDatabaseWrapper, str, bool]], **kwargs: Any) -> None: ...
|
||||||
def teardown_test_environment(self, **kwargs: Any) -> None: ...
|
def teardown_test_environment(self, **kwargs: Any) -> None: ...
|
||||||
def suite_result(self, suite: TestSuite, result: TextTestResult, **kwargs: Any) -> int: ...
|
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 get_databases(self, suite: TestSuite) -> Set[str]: ...
|
||||||
def run_tests(self, test_labels: List[str], extra_tests: Optional[List[Any]] = ..., **kwargs: Any) -> int: ...
|
def run_tests(self, test_labels: List[str], extra_tests: Optional[List[Any]] = ..., **kwargs: Any) -> int: ...
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user