MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _setup_async_mock

Function _setup_async_mock

tools/python-3.11.9-amd64/Lib/unittest/mock.py:257–281  ·  view source on GitHub ↗
(mock)

Source from the content-addressed store, hash-verified

255
256
257def _setup_async_mock(mock):
258 mock._is_coroutine = asyncio.coroutines._is_coroutine
259 mock.await_count = 0
260 mock.await_args = None
261 mock.await_args_list = _CallList()
262
263 # Mock is not configured yet so the attributes are set
264 # to a function and then the corresponding mock helper function
265 # is called when the helper is accessed similar to _setup_func.
266 def wrapper(attr, /, *args, **kwargs):
267 return getattr(mock.mock, attr)(*args, **kwargs)
268
269 for attribute in ('assert_awaited',
270 'assert_awaited_once',
271 'assert_awaited_with',
272 'assert_awaited_once_with',
273 'assert_any_await',
274 'assert_has_awaits',
275 'assert_not_awaited'):
276
277 # setattr(mock, attribute, wrapper) causes late binding
278 # hence attribute will always be the last value in the loop
279 # Use partial(wrapper, attribute) to ensure the attribute is bound
280 # correctly.
281 setattr(mock, attribute, partial(wrapper, attribute))
282
283
284def _is_magic(name):

Callers 1

create_autospecFunction · 0.85

Calls 2

partialClass · 0.90
_CallListClass · 0.85

Tested by

no test coverage detected