MCPcopy Index your code
hub / github.com/python/cpython / _call_matcher

Method _call_matcher

Lib/unittest/mock.py:912–937  ·  view source on GitHub ↗

Given a call (or simply an (args, kwargs) tuple), return a comparison key suitable for matching with other calls. This is a best effort method which relies on the spec's signature, if available, or falls back on the arguments themselves.

(self, _call)

Source from the content-addressed store, hash-verified

910
911
912 def _call_matcher(self, _call):
913 """
914 Given a call (or simply an (args, kwargs) tuple), return a
915 comparison key suitable for matching with other calls.
916 This is a best effort method which relies on the spec's signature,
917 if available, or falls back on the arguments themselves.
918 """
919
920 if isinstance(_call, tuple) and len(_call) > 2:
921 sig = self._get_call_signature_from_name(_call[0])
922 else:
923 sig = self._spec_signature
924
925 if sig is not None:
926 if len(_call) == 2:
927 name = ''
928 args, kwargs = _call
929 else:
930 name, args, kwargs = _call
931 try:
932 bound_call = sig.bind(*args, **kwargs)
933 return call(name, bound_call.args, bound_call.kwargs)
934 except TypeError as e:
935 return e.with_traceback(None)
936 else:
937 return _call
938
939 def assert_not_called(self):
940 """assert that the mock was never called.

Callers 6

assert_called_withMethod · 0.95
assert_has_callsMethod · 0.95
assert_any_callMethod · 0.95
assert_awaited_withMethod · 0.80
assert_any_awaitMethod · 0.80
assert_has_awaitsMethod · 0.80

Calls 3

callFunction · 0.50
bindMethod · 0.45

Tested by

no test coverage detected