2 from typing import Any, Callable, Generic, Iterable, List, Mapping, Sequence, Tuple, Type, TypeVar, overload
5 _TT = TypeVar("_TT", bound=Type[Any])
20 "NonCallableMagicMock",
31 class _SentinelObject:
33 def __init__(self, name: Any) -> None: ...
36 def __init__(self) -> None: ...
37 def __getattr__(self, name: str) -> Any: ...
42 class _Call(Tuple[Any, ...]):
44 cls, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
50 self, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ...
52 def __eq__(self, other: Any) -> bool: ...
54 def __call__(self, *args: Any, **kwargs: Any) -> _Call: ...
55 def __getattr__(self, attr: Any) -> Any: ...
56 def count(self, *args: Any, **kwargs: Any) -> Any: ...
57 def index(self, *args: Any, **kwargs: Any) -> Any: ...
58 def call_list(self) -> Any: ...
62 class _CallList(List[_Call]):
63 def __contains__(self, value: Any) -> bool: ...
67 def __init__(self, obj: Any) -> None: ...
68 def __iter__(self) -> Any: ...
69 def __next__(self) -> Any: ...
72 def __init__(self, *args: Any, **kwargs: Any) -> None: ...
74 class NonCallableMock(Base, Any): # type: ignore
75 def __new__(__cls, *args: Any, **kw: Any) -> NonCallableMock: ...
78 spec: list[str] | object | Type[object] | None = ...,
79 wraps: Any | None = ...,
80 name: str | None = ...,
81 spec_set: list[str] | object | Type[object] | None = ...,
82 parent: NonCallableMock | None = ...,
83 _spec_state: Any | None = ...,
85 _new_parent: NonCallableMock | None = ...,
86 _spec_as_instance: bool = ...,
87 _eat_self: bool | None = ...,
91 def __getattr__(self, name: str) -> Any: ...
92 if sys.version_info >= (3, 8):
93 def _calls_repr(self, prefix: str = ...) -> str: ...
94 def assert_called_with(self, *args: Any, **kwargs: Any) -> None: ...
95 def assert_not_called(self) -> None: ...
96 def assert_called_once_with(self, *args: Any, **kwargs: Any) -> None: ...
97 def _format_mock_failure_message(self, args: Any, kwargs: Any, action: str = ...) -> str: ...
99 def assert_called_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
100 def assert_not_called(_mock_self) -> None: ...
101 def assert_called_once_with(_mock_self, *args: Any, **kwargs: Any) -> None: ...
102 def _format_mock_failure_message(self, args: Any, kwargs: Any) -> str: ...
103 if sys.version_info >= (3, 8):
104 def assert_called(self) -> None: ...
105 def assert_called_once(self) -> None: ...
107 def assert_called(_mock_self) -> None: ...
108 def assert_called_once(_mock_self) -> None: ...
109 def reset_mock(self, visited: Any = ..., *, return_value: bool = ..., side_effect: bool = ...) -> None: ...
110 if sys.version_info >= (3, 7):
111 def _extract_mock_name(self) -> str: ...
112 def _get_call_signature_from_name(self, name: str) -> Any: ...
113 def assert_any_call(self, *args: Any, **kwargs: Any) -> None: ...
114 def assert_has_calls(self, calls: Sequence[_Call], any_order: bool = ...) -> None: ...
115 def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
116 def _mock_add_spec(self, spec: Any, spec_set: bool, _spec_as_instance: bool = ..., _eat_self: bool = ...) -> None: ...
117 def attach_mock(self, mock: NonCallableMock, attribute: str) -> None: ...
118 def configure_mock(self, **kwargs: Any) -> None: ...
124 call_args_list: _CallList
125 mock_calls: _CallList
126 def _format_mock_call_signature(self, args: Any, kwargs: Any) -> str: ...
127 def _call_matcher(self, _call: Tuple[_Call, ...]) -> _Call: ...
128 def _get_child_mock(self, **kw: Any) -> NonCallableMock: ...
130 class CallableMixin(Base):
134 spec: Any | None = ...,
135 side_effect: Any | None = ...,
136 return_value: Any = ...,
137 wraps: Any | None = ...,
138 name: Any | None = ...,
139 spec_set: Any | None = ...,
140 parent: Any | None = ...,
141 _spec_state: Any | None = ...,
142 _new_name: Any = ...,
143 _new_parent: Any | None = ...,
146 def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ...
148 class Mock(CallableMixin, NonCallableMock): ...
150 class _patch(Generic[_T]):
152 getter: Callable[[], Any]
161 kwargs: Mapping[str, Any]
162 additional_patchers: Any
163 # If new==DEFAULT, self is _patch[Any]. Ideally we'd be able to add an overload for it so that self is _patch[MagicMock],
164 # but that's impossible with the current type system.
167 getter: Callable[[], Any],
172 spec_set: Any | None,
173 autospec: Any | None,
174 new_callable: Any | None,
175 kwargs: Mapping[str, Any],
177 def copy(self) -> _patch[_T]: ...
179 def __call__(self, func: _TT) -> _TT: ...
181 def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
182 def decorate_class(self, klass: _TT) -> _TT: ...
183 def decorate_callable(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
184 def get_original(self) -> tuple[Any, bool]: ...
188 def __enter__(self) -> _T: ...
189 def __exit__(self, *exc_info: Any) -> None: ...
190 def start(self) -> _T: ...
191 def stop(self) -> None: ...
197 def __init__(self, in_dict: Any, values: Any = ..., clear: Any = ..., **kwargs: Any) -> None: ...
198 def __call__(self, f: Any) -> Any: ...
199 def decorate_class(self, klass: Any) -> Any: ...
200 def __enter__(self) -> Any: ...
201 def __exit__(self, *args: Any) -> Any: ...
207 dict: Type[_patch_dict]
208 if sys.version_info >= (3, 8):
209 # This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
210 # Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
211 # but that's impossible with the current type system.
213 def __call__( # type: ignore
217 spec: Any | None = ...,
219 spec_set: Any | None = ...,
220 autospec: Any | None = ...,
221 new_callable: Any | None = ...,
225 def __call__( # type: ignore
229 spec: Any | None = ...,
231 spec_set: Any | None = ...,
232 autospec: Any | None = ...,
233 new_callable: Any | None = ...,
235 ) -> _patch[MagicMock | AsyncMock]: ...
238 def __call__( # type: ignore
242 spec: Any | None = ...,
244 spec_set: Any | None = ...,
245 autospec: Any | None = ...,
246 new_callable: Any | None = ...,
250 def __call__( # type: ignore
254 spec: Any | None = ...,
256 spec_set: Any | None = ...,
257 autospec: Any | None = ...,
258 new_callable: Any | None = ...,
260 ) -> _patch[MagicMock]: ...
261 if sys.version_info >= (3, 8):
263 def object( # type: ignore
268 spec: Any | None = ...,
270 spec_set: Any | None = ...,
271 autospec: Any | None = ...,
272 new_callable: Any | None = ...,
276 def object( # type: ignore
281 spec: Any | None = ...,
283 spec_set: Any | None = ...,
284 autospec: Any | None = ...,
285 new_callable: Any | None = ...,
287 ) -> _patch[MagicMock | AsyncMock]: ...
290 def object( # type: ignore
295 spec: Any | None = ...,
297 spec_set: Any | None = ...,
298 autospec: Any | None = ...,
299 new_callable: Any | None = ...,
303 def object( # type: ignore
308 spec: Any | None = ...,
310 spec_set: Any | None = ...,
311 autospec: Any | None = ...,
312 new_callable: Any | None = ...,
314 ) -> _patch[MagicMock]: ...
318 spec: Any | None = ...,
320 spec_set: Any | None = ...,
321 autospec: Any | None = ...,
322 new_callable: Any | None = ...,
324 ) -> _patch[Any]: ...
325 def stopall(self) -> None: ...
330 def __init__(self, *args: Any, **kw: Any) -> None: ...
332 class NonCallableMagicMock(MagicMixin, NonCallableMock):
333 def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
335 class MagicMock(MagicMixin, Mock):
336 def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...
338 if sys.version_info >= (3, 8):
339 class AsyncMockMixin(Base):
340 def __init__(self, *args: Any, **kwargs: Any) -> None: ...
341 async def _execute_mock_call(self, *args: Any, **kwargs: Any) -> Any: ...
342 def assert_awaited(self) -> None: ...
343 def assert_awaited_once(self) -> None: ...
344 def assert_awaited_with(self, *args: Any, **kwargs: Any) -> None: ...
345 def assert_awaited_once_with(self, *args: Any, **kwargs: Any) -> None: ...
346 def assert_any_await(self, *args: Any, **kwargs: Any) -> None: ...
347 def assert_has_awaits(self, calls: Iterable[_Call], any_order: bool = ...) -> None: ...
348 def assert_not_awaited(self) -> None: ...
349 def reset_mock(self, *args: Any, **kwargs: Any) -> None: ...
351 await_args: _Call | None
352 await_args_list: _CallList
353 class AsyncMagicMixin(MagicMixin):
354 def __init__(self, *args: Any, **kw: Any) -> None: ...
355 class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ...
360 def __init__(self, name: Any, parent: Any) -> None: ...
361 def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
362 def create_mock(self) -> Any: ...
363 def __get__(self, obj: Any, _type: Any | None = ...) -> Any: ...
366 def __eq__(self, other: Any) -> bool: ...
367 def __ne__(self, other: Any) -> bool: ...
372 spec: Any, spec_set: Any = ..., instance: Any = ..., _parent: Any | None = ..., _name: Any | None = ..., **kwargs: Any
386 parent: Any | None = ...,
387 name: Any | None = ...,
388 ids: Any | None = ...,
392 def mock_open(mock: Any | None = ..., read_data: Any = ...) -> Any: ...
396 if sys.version_info >= (3, 7):
397 def seal(mock: Any) -> None: ...