1 from collections.abc import Callable, Mapping, Sequence
2 from typing import Any, Generic, List, Tuple, Type, TypeVar, overload
4 _F = TypeVar("_F", bound=Callable[..., Any])
6 _TT = TypeVar("_TT", bound=Type[Any])
21 "NonCallableMagicMock",
32 class _SentinelObject:
34 def __init__(self, name: Any) -> None: ...
37 def __init__(self) -> None: ...
38 def __getattr__(self, name: str) -> Any: ...
43 class _Call(Tuple[Any, ...]):
45 cls, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
51 self, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
53 def __eq__(self, other: Any) -> bool: ...
55 def __call__(self, *args: Any, **kwargs: Any) -> _Call: ...
56 def __getattr__(self, attr: Any) -> Any: ...
57 def count(self, *args: Any, **kwargs: Any) -> Any: ...
58 def index(self, *args: Any, **kwargs: Any) -> Any: ...
59 def call_list(self) -> Any: ...
63 class _CallList(List[_Call]):
64 def __contains__(self, value: Any) -> bool: ...
68 def __init__(self, obj: Any) -> None: ...
69 def __iter__(self) -> Any: ...
70 def __next__(self) -> Any: ...
73 def __init__(self, *args: Any, **kwargs: Any) -> None: ...
75 class NonCallableMock(Base, Any): # type: ignore
76 def __new__(__cls, *args: Any, **kw: Any) -> NonCallableMock: ...
79 spec: list[str] | object | Type[object] | None = ...,
80 wraps: Any | None = ...,
81 name: str | None = ...,
82 spec_set: list[str] | object | Type[object] | None = ...,
83 parent: NonCallableMock | None = ...,
84 _spec_state: Any | None = ...,
86 _new_parent: NonCallableMock | None = ...,
87 _spec_as_instance: bool = ...,
88 _eat_self: bool | None = ...,
92 def __getattr__(self, name: str) -> Any: ...
93 def _calls_repr(self, prefix: str = ...) -> str: ...
94 def assert_called_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
95 def assert_not_called(_mock_self) -> None: ...
96 def assert_called_once_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
97 def _format_mock_failure_message(self, args: Any, kwargs: Any, action: str = ...) -> str: ...
98 def assert_called(_mock_self) -> None: ...
99 def assert_called_once(_mock_self) -> None: ...
100 def reset_mock(self, visited: Any = ..., *, return_value: bool = ..., side_effect: bool = ...) -> None: ...
101 def _extract_mock_name(self) -> str: ...
102 def assert_any_call(self, *args: Any, **kwargs: Any) -> None: ...
103 def assert_has_calls(self, calls: Sequence[_Call], any_order: bool = ...) -> None: ...
104 def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
105 def _mock_add_spec(self, spec: Any, spec_set: bool, _spec_as_instance: bool = ..., _eat_self: bool = ...) -> None: ...
106 def attach_mock(self, mock: NonCallableMock, attribute: str) -> None: ...
107 def configure_mock(self, **kwargs: Any) -> None: ...
113 call_args_list: _CallList
114 mock_calls: _CallList
115 def _format_mock_call_signature(self, args: Any, kwargs: Any) -> str: ...
116 def _call_matcher(self, _call: Tuple[_Call, ...]) -> _Call: ...
117 def _get_child_mock(self, **kw: Any) -> NonCallableMock: ...
119 class CallableMixin(Base):
123 spec: Any | None = ...,
124 side_effect: Any | None = ...,
125 return_value: Any = ...,
126 wraps: Any | None = ...,
127 name: Any | None = ...,
128 spec_set: Any | None = ...,
129 parent: Any | None = ...,
130 _spec_state: Any | None = ...,
131 _new_name: Any = ...,
132 _new_parent: Any | None = ...,
135 def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ...
137 class Mock(CallableMixin, NonCallableMock): ...
139 class _patch(Generic[_T]):
141 getter: Callable[[], Any]
150 kwargs: Mapping[str, Any]
151 additional_patchers: Any
154 self: _patch[MagicMock | AsyncMock],
155 getter: Callable[[], Any],
160 spec_set: Any | None,
161 autospec: Any | None,
162 new_callable: Any | None,
163 kwargs: Mapping[str, Any],
165 # This overload also covers the case, where new==DEFAULT. In this case, self is _patch[Any].
166 # Ideally we'd be able to add an overload for it so that self is _patch[MagicMock],
167 # but that's impossible with the current type system.
171 getter: Callable[[], Any],
176 spec_set: Any | None,
177 autospec: Any | None,
178 new_callable: Any | None,
179 kwargs: Mapping[str, Any],
181 def copy(self) -> _patch[_T]: ...
182 def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
183 def decorate_class(self, klass: _TT) -> _TT: ...
184 def decorate_callable(self, func: _F) -> _F: ...
185 def get_original(self) -> tuple[Any, bool]: ...
189 def __enter__(self) -> _T: ...
190 def __exit__(self, *exc_info: Any) -> None: ...
191 def start(self) -> _T: ...
192 def stop(self) -> None: ...
198 def __init__(self, in_dict: Any, values: Any = ..., clear: Any = ..., **kwargs: Any) -> None: ...
199 def __call__(self, f: Any) -> Any: ...
200 def decorate_class(self, klass: Any) -> Any: ...
201 def __enter__(self) -> Any: ...
202 def __exit__(self, *args: Any) -> Any: ...
208 dict: Type[_patch_dict]
210 def __call__( # type: ignore
214 spec: Any | None = ...,
216 spec_set: Any | None = ...,
217 autospec: Any | None = ...,
218 new_callable: Any | None = ...,
220 ) -> _patch[MagicMock | AsyncMock]: ...
221 # This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
222 # Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
223 # but that's impossible with the current type system.
229 spec: Any | None = ...,
231 spec_set: Any | None = ...,
232 autospec: Any | None = ...,
233 new_callable: Any | None = ...,
237 def object( # type: ignore
242 spec: Any | None = ...,
244 spec_set: Any | None = ...,
245 autospec: Any | None = ...,
246 new_callable: Any | None = ...,
248 ) -> _patch[MagicMock | AsyncMock]: ...
255 spec: Any | None = ...,
257 spec_set: Any | None = ...,
258 autospec: Any | None = ...,
259 new_callable: Any | None = ...,
265 spec: Any | None = ...,
267 spec_set: Any | None = ...,
268 autospec: Any | None = ...,
269 new_callable: Any | None = ...,
272 def stopall(self) -> None: ...
277 def __init__(self, *args: Any, **kw: Any) -> None: ...
279 class NonCallableMagicMock(MagicMixin, NonCallableMock):
280 def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
282 class MagicMock(MagicMixin, Mock):
283 def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
285 class AsyncMockMixin(Base):
286 def __init__(self, *args: Any, **kwargs: Any) -> None: ...
287 async def _execute_mock_call(self, *args: Any, **kwargs: Any) -> Any: ...
288 def assert_awaited(self) -> None: ...
289 def assert_awaited_once(self) -> None: ...
290 def assert_awaited_with(self, *args: Any, **kwargs: Any) -> None: ...
291 def assert_awaited_once_with(self, *args: Any, **kwargs: Any) -> None: ...
292 def assert_any_await(self, *args: Any, **kwargs: Any) -> None: ...
293 def assert_has_awaits(self, calls: _CallList, any_order: bool = ...) -> None: ...
294 def assert_not_awaited(self) -> None: ...
295 def reset_mock(self, *args: Any, **kwargs: Any) -> None: ...
297 await_args: _Call | None
298 await_args_list: _CallList
300 class AsyncMagicMixin(MagicMixin):
301 def __init__(self, *args: Any, **kw: Any) -> None: ...
303 class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ...
308 def __init__(self, name: Any, parent: Any) -> None: ...
309 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
310 def create_mock(self) -> Any: ...
311 def __get__(self, obj: Any, _type: Any | None = ...) -> Any: ...
314 def __eq__(self, other: Any) -> bool: ...
315 def __ne__(self, other: Any) -> bool: ...
320 spec: Any, spec_set: Any = ..., instance: Any = ..., _parent: Any | None = ..., _name: Any | None = ..., **kwargs: Any
334 parent: Any | None = ...,
335 name: Any | None = ...,
336 ids: Any | None = ...,
340 def mock_open(mock: Any | None = ..., read_data: Any = ...) -> Any: ...
344 def seal(mock: Any) -> None: ...