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
34 changes: 15 additions & 19 deletions django-stubs/core/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from collections.abc import Iterator, Mapping
from typing import Any, TypeAlias
from collections.abc import Iterator
from typing import Any, Literal

from django.utils.functional import _StrOrPromise

class FieldDoesNotExist(Exception): ...
class AppRegistryNotReady(Exception): ...

class ObjectDoesNotExist(Exception):
silent_variable_failure: bool = ...
silent_variable_failure: bool

class ObjectNotUpdated(Exception): ...
class MultipleObjectsReturned(Exception): ...
class SuspiciousOperation(Exception): ...
class SuspiciousMultipartForm(SuspiciousOperation): ...
Expand All @@ -26,32 +27,27 @@ class MiddlewareNotUsed(Exception): ...
class ImproperlyConfigured(Exception): ...
class FieldError(Exception): ...

NON_FIELD_ERRORS: str

ValidationErrorMessageArg: TypeAlias = (
_StrOrPromise | ValidationError | dict[str, ValidationErrorMessageArg] | list[ValidationErrorMessageArg]
)
NON_FIELD_ERRORS: Literal["__all__"]

class ValidationError(Exception):
error_dict: dict[str, list[ValidationError]] | None
error_list: list[ValidationError] | None
message: _StrOrPromise | None
error_dict: dict[str, list[ValidationError]]
error_list: list[ValidationError]
message: _StrOrPromise
code: str | None
params: Mapping[str, Any] | None
params: dict[str, Any] | None
def __init__(
self,
message: ValidationErrorMessageArg,
code: str | None = ...,
params: Mapping[str, Any] | None = ...,
# Accepts arbitrarily nested data structure, mypy doesn't allow describing it accurately.
message: _StrOrPromise | ValidationError | dict[str, Any] | list[Any],
code: str | None = None,
params: dict[str, Any] | None = None,
) -> None: ...
@property
def message_dict(self) -> dict[str, list[str]]: ...
@property
def messages(self) -> list[str]: ...
def update_error_dict(
self, error_dict: Mapping[str, list[ValidationError]]
) -> Mapping[str, list[ValidationError]]: ...
def __iter__(self) -> Iterator[tuple[str, list[ValidationError]] | str]: ...
def update_error_dict(self, error_dict: dict[str, list[ValidationError]]) -> dict[str, list[ValidationError]]: ...
def __iter__(self) -> Iterator[tuple[str, list[str]] | str]: ...

class EmptyResultSet(Exception): ...
class FullResultSet(Exception): ...
Expand Down
230 changes: 148 additions & 82 deletions django-stubs/test/runner.pyi
Original file line number Diff line number Diff line change
@@ -1,101 +1,152 @@
import logging
import sys
from argparse import ArgumentParser
from collections.abc import Sequence
from io import StringIO
from typing import Any
from unittest import TestCase as _TestCase
from unittest import TestSuite, TextTestResult
from collections.abc import Callable, Iterable, Iterator, Sequence
from contextlib import AbstractContextManager
from typing import Any, Literal
from unittest import TestCase, TestLoader, TestResult, TestSuite, TextTestResult, TextTestRunner

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

class QueryFormatter(logging.Formatter): ...

class DebugSQLTextTestResult(TextTestResult):
buffer: bool
descriptions: bool
dots: bool
expectedFailures: list[Any]
failfast: bool
shouldStop: bool
showAll: bool
skipped: list[Any]
tb_locals: bool
testsRun: int
unexpectedSuccesses: list[Any]
logger: logging.Logger = ...
logger: logging.Logger
def __init__(self, stream: Any, descriptions: bool, verbosity: int) -> None: ...
debug_sql_stream: StringIO = ...
handler: logging.FileHandler = ...
def startTest(self, test: _TestCase) -> None: ...
def stopTest(self, test: _TestCase) -> None: ...
handler: logging.StreamHandler[Any]
@override
def startTest(self, test: TestCase) -> None: ...
@override
def stopTest(self, test: TestCase) -> None: ...
@override
def addError(self, test: Any, err: Any) -> None: ...
@override
def addFailure(self, test: Any, err: Any) -> None: ...

class RemoteTestResult:
events: list[Any] = ...
failfast: bool = ...
shouldStop: bool = ...
testsRun: int = ...
def __init__(self) -> None: ...
class PDBDebugResult(TextTestResult):
def debug(self, error: tuple[type[BaseException], BaseException, Any]) -> None: ...

class DummyList:
__slots__ = ()
def append(self, item: Any) -> None: ...

class RemoteTestResult(TestResult):
events: list[Any]
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
@property
def test_index(self) -> Any: ...
def check_picklable(self, test: Any, err: Any) -> None: ...
def test_index(self) -> int: ...
def _confirm_picklable(self, obj: Any) -> None: ...
def check_picklable(self, test: Any, err: Any) -> None: ...
def check_subtest_picklable(self, test: Any, subtest: Any) -> None: ...
def stop_if_failfast(self) -> None: ...
def stop(self) -> None: ...
@override
def startTestRun(self) -> None: ...
@override
def stopTestRun(self) -> None: ...
@override
def startTest(self, test: Any) -> None: ...
@override
def stopTest(self, test: Any) -> None: ...
if sys.version_info >= (3, 12):
@override
def addDuration(self, test: Any, elapsed: Any) -> None: ...
else:
def addDuration(self, test: Any, elapsed: Any) -> None: ...
@override
def addError(self, test: Any, err: Any) -> None: ...
@override
def addFailure(self, test: Any, err: Any) -> None: ...
@override
def addSubTest(self, test: Any, subtest: Any, err: Any) -> None: ...
@override
def addSuccess(self, test: Any) -> None: ...
@override
def addSkip(self, test: Any, reason: Any) -> None: ...
@override
def addExpectedFailure(self, test: Any, err: Any) -> None: ...
@override
def addUnexpectedSuccess(self, test: Any) -> None: ...
@override
def wasSuccessful(self) -> bool: ...

class RemoteTestRunner:
resultclass: Any = ...
failfast: Any = ...
def __init__(self, failfast: bool = ..., resultclass: Any | None = ...) -> None: ...
resultclass: Any
failfast: bool
buffer: bool
def __init__(self, failfast: bool = ..., resultclass: Any | None = ..., buffer: bool = ...) -> None: ...
def run(self, test: Any) -> Any: ...

def default_test_processes() -> int: ...
def get_max_test_processes() -> int: ...
def parallel_type(value: str) -> int | Literal["auto"]: ...

class ParallelTestSuite(TestSuite):
init_worker: Any = ...
run_subsuite: Any = ...
runner_class: Any = ...
subsuites: Any = ...
processes: Any = ...
failfast: Any = ...
def __init__(self, suite: Any, processes: Any, failfast: bool = ...) -> None: ...
init_worker: Callable[..., Any]
process_setup: Callable[..., Any]
process_setup_args: tuple[Any, ...]
run_subsuite: Callable[..., Any]
runner_class: type[RemoteTestRunner]
subsuites: list[TestSuite]
processes: int
failfast: bool
debug_mode: bool
buffer: bool
initial_settings: dict[str, dict[str, Any]] | None
serialized_contents: dict[str, str] | None
used_aliases: set[str] | None
def __init__(
self,
subsuites: list[TestSuite],
processes: int,
failfast: bool = ...,
debug_mode: bool = ...,
buffer: bool = ...,
) -> None: ...
@override
def run(self, result: Any) -> Any: ... # type: ignore[override]
def handle_event(self, result: Any, tests: list[TestSuite], event: Sequence[Any]) -> None: ...
def initialize_suite(self) -> None: ...

class Shuffler:
hash_algorithm: str
seed: int
seed_source: str
def __init__(self, seed: int | None = ...) -> None: ...
@property
def seed_display(self) -> str: ...
def shuffle(self, items: Iterable[Any], key: Callable[[Any], str]) -> list[Any]: ...

class DiscoverRunner:
test_suite: Any = ...
parallel_test_suite: Any = ...
test_runner: Any = ...
test_loader: Any = ...
reorder_by: Any = ...
pattern: str | None = ...
top_level: None = ...
verbosity: int = ...
interactive: bool = ...
failfast: bool = ...
keepdb: bool = ...
reverse: bool = ...
debug_mode: bool = ...
debug_sql: bool = ...
parallel: int = ...
tags: set[str] = ...
exclude_tags: set[str] = ...
test_suite: type[TestSuite]
parallel_test_suite: type[ParallelTestSuite]
test_runner: type[TextTestRunner]
test_loader: TestLoader
reorder_by: tuple[type[DjangoTestCase], type[SimpleTestCase]]
pattern: str | None
top_level: str | None
verbosity: int
interactive: bool
failfast: bool
keepdb: bool
reverse: bool
debug_mode: bool
debug_sql: bool
parallel: int
tags: set[str]
exclude_tags: set[str]
pdb: bool
buffer: bool
test_name_patterns: set[str] | None
time_keeper: TimeKeeperProtocol
shuffle: int | Literal[False]
logger: logging.Logger | None
durations: int | None
def __init__(
self,
pattern: str | None = ...,
top_level: None = ...,
top_level: str | None = ...,
verbosity: int = ...,
interactive: bool = ...,
failfast: bool = ...,
Expand All @@ -106,35 +157,50 @@ class DiscoverRunner:
parallel: int = ...,
tags: list[str] | None = ...,
exclude_tags: list[str] | None = ...,
test_name_patterns: list[str] | None = ...,
pdb: bool = ...,
buffer: bool = ...,
enable_faulthandler: bool = ...,
timing: bool = ...,
shuffle: int | Literal[False] = ...,
logger: logging.Logger | None = ...,
durations: int | None = ...,
**kwargs: Any,
) -> None: ...
@classmethod
def add_arguments(cls, parser: ArgumentParser) -> None: ...
@property
def shuffle_seed(self) -> int | None: ...
def log(self, msg: str, level: int | None = ...) -> None: ...
def setup_test_environment(self, **kwargs: Any) -> None: ...
def build_suite(
self, test_labels: Sequence[str] = ..., extra_tests: list[Any] | None = ..., **kwargs: Any
) -> TestSuite: ...
def setup_shuffler(self) -> None: ...
def load_with_patterns(self) -> AbstractContextManager[None]: ...
def load_tests_for_label(self, label: str, discover_kwargs: dict[str, str]) -> TestSuite: ...
def build_suite(self, test_labels: Sequence[str] | None = ..., **kwargs: Any) -> TestSuite: ...
def setup_databases(self, **kwargs: Any) -> list[tuple[BaseDatabaseWrapper, str, bool]]: ...
def get_resultclass(self) -> type[DebugSQLTextTestResult] | None: ...
def get_test_runner_kwargs(self) -> dict[str, int | None]: ...
def run_checks(self) -> None: ...
def get_resultclass(self) -> type[TextTestResult] | None: ...
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 run_tests(self, test_labels: list[str], extra_tests: list[Any] = ..., **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], **kwargs: Any) -> int: ...

def is_discoverable(label: str) -> bool: ...
def reorder_suite(
suite: TestSuite,
classes: tuple[type[TestCase], type[SimpleTestCase]],
reverse: bool = ...,
) -> TestSuite: ...
def partition_suite_by_type(
suite: TestSuite,
classes: tuple[type[TestCase], type[SimpleTestCase]],
bins: list[OrderedSet[Any]],
def try_importing(label: str) -> tuple[bool, bool]: ...
def find_top_level(top_level: str) -> str: ...
def shuffle_tests(tests: Iterable[TestCase], shuffler: Shuffler) -> Iterator[TestCase]: ...
def reorder_test_bin(
tests: Sequence[TestCase], shuffler: Shuffler | None = ..., reverse: bool = ...
) -> Iterator[TestCase]: ...
def reorder_tests(
tests: Iterable[TestCase],
classes: Sequence[type[TestCase]],
reverse: bool = ...,
) -> None: ...
def partition_suite_by_case(suite: Any) -> Any: ...
def filter_tests_by_tags(suite: TestSuite, tags: set[str], exclude_tags: set[str]) -> TestSuite: ...
shuffler: Shuffler | None = ...,
) -> Iterator[TestCase]: ...
def partition_suite_by_case(suite: TestSuite) -> list[TestSuite]: ...
def test_match_tags(test: TestCase, tags: set[str], exclude_tags: set[str]) -> bool: ...
def filter_tests_by_tags(tests: Iterable[TestCase], tags: set[str], exclude_tags: set[str]) -> Iterator[TestCase]: ...
2 changes: 1 addition & 1 deletion django-stubs/test/testcases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _AssertTemplateUsedContext:
template_name: str = ...
rendered_templates: list[Template] = ...
rendered_template_names: list[str] = ...
context: ContextList[Any] = ...
context: ContextList = ...
def __init__(self, test_case: Any, template_name: Any) -> None: ...
def on_template_render(self, sender: Any, signal: Any, template: Any, context: Any, **kwargs: Any) -> None: ...
def test(self) -> Any: ...
Expand Down
Loading
Loading