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

Method _mock_add_spec

Lib/unittest/mock.py:533–570  ·  view source on GitHub ↗
(self, spec, spec_set, _spec_as_instance=False,
                       _eat_self=False)

Source from the content-addressed store, hash-verified

531
532
533 def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
534 _eat_self=False):
535 if _is_instance_mock(spec):
536 raise InvalidSpecError(f'Cannot spec a Mock object. [object={spec!r}]')
537
538 _spec_class = None
539 _spec_signature = None
540 _spec_asyncs = []
541
542 if spec is not None and not _is_list(spec):
543 if isinstance(spec, type):
544 _spec_class = spec
545 else:
546 _spec_class = type(spec)
547 res = _get_signature_object(spec,
548 _spec_as_instance, _eat_self)
549 _spec_signature = res and res[1]
550
551 spec_list = dir(spec)
552
553 for attr in spec_list:
554 static_attr = inspect.getattr_static(spec, attr, None)
555 unwrapped_attr = static_attr
556 try:
557 unwrapped_attr = inspect.unwrap(unwrapped_attr)
558 except ValueError:
559 pass
560 if iscoroutinefunction(unwrapped_attr):
561 _spec_asyncs.append(attr)
562
563 spec = spec_list
564
565 __dict__ = self.__dict__
566 __dict__['_spec_class'] = _spec_class
567 __dict__['_spec_set'] = spec_set
568 __dict__['_spec_signature'] = _spec_signature
569 __dict__['_mock_methods'] = spec
570 __dict__['_spec_asyncs'] = _spec_asyncs
571
572 def _mock_extend_spec_methods(self, spec_methods):
573 methods = self.__dict__.get('_mock_methods') or []

Callers 4

__init__Method · 0.95
mock_add_specMethod · 0.95
mock_add_specMethod · 0.80
mock_add_specMethod · 0.80

Calls 9

iscoroutinefunctionFunction · 0.90
_is_instance_mockFunction · 0.85
InvalidSpecErrorClass · 0.85
_is_listFunction · 0.85
isinstanceFunction · 0.85
_get_signature_objectFunction · 0.85
dirFunction · 0.85
unwrapMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected