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

Method assert_has_calls

Lib/unittest/mock.py:1000–1042  ·  view source on GitHub ↗

assert the mock has been called with the specified calls. The `mock_calls` list is checked for the calls. If `any_order` is False (the default) then the calls must be sequential. There can be extra calls before or after the specified calls. If `any_order` is

(self, calls, any_order=False)

Source from the content-addressed store, hash-verified

998
999
1000 def assert_has_calls(self, calls, any_order=False):
1001 """assert the mock has been called with the specified calls.
1002 The `mock_calls` list is checked for the calls.
1003
1004 If `any_order` is False (the default) then the calls must be
1005 sequential. There can be extra calls before or after the
1006 specified calls.
1007
1008 If `any_order` is True then the calls can be in any order, but
1009 they must all appear in `mock_calls`."""
1010 expected = [self._call_matcher(c) for c in calls]
1011 cause = next((e for e in expected if isinstance(e, Exception)), None)
1012 all_calls = _CallList(self._call_matcher(c) for c in self.mock_calls)
1013 if not any_order:
1014 if expected not in all_calls:
1015 if cause is None:
1016 problem = 'Calls not found.'
1017 else:
1018 problem = ('Error processing expected calls.\n'
1019 'Errors: {}').format(
1020 [e if isinstance(e, Exception) else None
1021 for e in expected])
1022 raise AssertionError(
1023 f'{problem}\n'
1024 f'Expected: {_CallList(calls)}\n'
1025 f' Actual: {safe_repr(self.mock_calls)}'
1026 ) from cause
1027 return
1028
1029 all_calls = list(all_calls)
1030
1031 not_found = []
1032 for kall in expected:
1033 try:
1034 all_calls.remove(kall)
1035 except ValueError:
1036 not_found.append(kall)
1037 if not_found:
1038 raise AssertionError(
1039 '%r does not contain all of %r in its call list, '
1040 'found %r instead' % (self._mock_name or 'mock',
1041 tuple(not_found), all_calls)
1042 ) from cause
1043
1044
1045 def assert_any_call(self, /, *args, **kwargs):

Calls 9

_call_matcherMethod · 0.95
safe_reprFunction · 0.90
nextFunction · 0.85
isinstanceFunction · 0.85
_CallListClass · 0.85
listClass · 0.85
formatMethod · 0.45
removeMethod · 0.45
appendMethod · 0.45