Modernize mock stubs (#5949)

* Import from `collections.abc`, instead of `typing`.
* Replace `Text` with `str`.
* Remove version checks.
* Convert mock into a package
This commit is contained in:
Sebastian Rittau
2021-08-23 20:53:03 +02:00
committed by GitHub
parent 28f2953b49
commit db0f37ccdf
3 changed files with 22 additions and 36 deletions

View File

@@ -1,7 +1,4 @@
mock.NonCallableMock.__new__
mock.NonCallableMock.assert_called
mock.NonCallableMock.assert_called_once
mock.NonCallableMock.assert_called_once_with
mock.NonCallableMock.assert_called_with
mock.NonCallableMock.assert_not_called
mock.patch
mock.mock.NonCallableMock.__new__
mock.mock.patch

View File

@@ -0,0 +1,5 @@
from typing import Tuple
from .mock import *
version_info: Tuple[int, int, int]

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, Callable, Generic, List, Mapping, Sequence, Text, Tuple, Type, TypeVar, overload
from collections.abc import Callable, Mapping, Sequence
from typing import Any, Generic, List, Tuple, Type, TypeVar, overload
_F = TypeVar("_F", bound=Callable[..., Any])
_T = TypeVar("_T")
@@ -90,30 +90,15 @@ class NonCallableMock(Base, Any): # type: ignore
**kwargs: Any,
) -> None: ...
def __getattr__(self, name: str) -> Any: ...
if sys.version_info >= (3, 8):
def _calls_repr(self, prefix: str = ...) -> str: ...
def assert_called_with(self, *args: Any, **kwargs: Any) -> None: ...
def assert_not_called(self) -> None: ...
def assert_called_once_with(self, *args: Any, **kwargs: Any) -> None: ...
def _format_mock_failure_message(self, args: Any, kwargs: Any, action: str = ...) -> str: ...
elif sys.version_info >= (3, 5):
def assert_called_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
def assert_not_called(_mock_self) -> None: ...
def assert_called_once_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
def _format_mock_failure_message(self, args: Any, kwargs: Any) -> str: ...
if sys.version_info >= (3, 8):
def assert_called(self) -> None: ...
def assert_called_once(self) -> None: ...
elif sys.version_info >= (3, 6):
def assert_called(_mock_self) -> None: ...
def assert_called_once(_mock_self) -> None: ...
if sys.version_info >= (3, 6):
def reset_mock(self, visited: Any = ..., *, return_value: bool = ..., side_effect: bool = ...) -> None: ...
elif sys.version_info >= (3, 5):
def reset_mock(self, visited: Any = ...) -> None: ...
if sys.version_info >= (3, 7):
def _extract_mock_name(self) -> str: ...
def _get_call_signature_from_name(self, name: str) -> Any: ...
def _calls_repr(self, prefix: str = ...) -> str: ...
def assert_called_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
def assert_not_called(_mock_self) -> None: ...
def assert_called_once_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
def _format_mock_failure_message(self, args: Any, kwargs: Any, action: str = ...) -> str: ...
def assert_called(_mock_self) -> None: ...
def assert_called_once(_mock_self) -> None: ...
def reset_mock(self, visited: Any = ..., *, return_value: bool = ..., side_effect: bool = ...) -> None: ...
def _extract_mock_name(self) -> str: ...
def assert_any_call(self, *args: Any, **kwargs: Any) -> None: ...
def assert_has_calls(self, calls: Sequence[_Call], any_order: bool = ...) -> None: ...
def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
@@ -197,7 +182,7 @@ class _patch(Generic[_T]):
def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
def decorate_class(self, klass: _TT) -> _TT: ...
def decorate_callable(self, func: _F) -> _F: ...
def get_original(self) -> Tuple[Any, bool]: ...
def get_original(self) -> tuple[Any, bool]: ...
target: Any
temp_original: Any
is_local: bool
@@ -252,7 +237,7 @@ class _patcher:
def object( # type: ignore
self,
target: Any,
attribute: Text,
attribute: str,
*,
spec: Any | None = ...,
create: bool = ...,
@@ -265,7 +250,7 @@ class _patcher:
def object(
self,
target: Any,
attribute: Text,
attribute: str,
new: _T = ...,
spec: Any | None = ...,
create: bool = ...,
@@ -356,5 +341,4 @@ def mock_open(mock: Any | None = ..., read_data: Any = ...) -> Any: ...
PropertyMock = Any
if sys.version_info >= (3, 7):
def seal(mock: Any) -> None: ...
def seal(mock: Any) -> None: ...