MCPcopy Index your code
hub / github.com/RustPython/RustPython / assert_has_awaits

Method assert_has_awaits

Lib/unittest/mock.py:2413–2455  ·  view source on GitHub ↗

Assert the mock has been awaited with the specified calls. The :attr:`await_args_list` list is checked for the awaits. If `any_order` is False (the default) then the awaits must be sequential. There can be extra calls before or after the specified awaits.

(self, calls, any_order=False)

Source from the content-addressed store, hash-verified

2411 ) from cause
2412
2413 def assert_has_awaits(self, calls, any_order=False):
2414 """
2415 Assert the mock has been awaited with the specified calls.
2416 The :attr:`await_args_list` list is checked for the awaits.
2417
2418 If `any_order` is False (the default) then the awaits must be
2419 sequential. There can be extra calls before or after the
2420 specified awaits.
2421
2422 If `any_order` is True then the awaits can be in any order, but
2423 they must all appear in :attr:`await_args_list`.
2424 """
2425 expected = [self._call_matcher(c) for c in calls]
2426 cause = next((e for e in expected if isinstance(e, Exception)), None)
2427 all_awaits = _CallList(self._call_matcher(c) for c in self.await_args_list)
2428 if not any_order:
2429 if expected not in all_awaits:
2430 if cause is None:
2431 problem = 'Awaits not found.'
2432 else:
2433 problem = ('Error processing expected awaits.\n'
2434 'Errors: {}').format(
2435 [e if isinstance(e, Exception) else None
2436 for e in expected])
2437 raise AssertionError(
2438 f'{problem}\n'
2439 f'Expected: {_CallList(calls)}\n'
2440 f'Actual: {self.await_args_list}'
2441 ) from cause
2442 return
2443
2444 all_awaits = list(all_awaits)
2445
2446 not_found = []
2447 for kall in expected:
2448 try:
2449 all_awaits.remove(kall)
2450 except ValueError:
2451 not_found.append(kall)
2452 if not_found:
2453 raise AssertionError(
2454 '%r not all found in await list' % (tuple(not_found),)
2455 ) from cause
2456
2457 def assert_not_awaited(self):
2458 """

Calls 8

nextFunction · 0.85
isinstanceFunction · 0.85
_CallListClass · 0.85
listClass · 0.85
_call_matcherMethod · 0.80
formatMethod · 0.45
removeMethod · 0.45
appendMethod · 0.45