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

Class NonCallableMock

tools/python-3.11.9-amd64/Lib/unittest/mock.py:409–1063  ·  view source on GitHub ↗

A non-callable version of `Mock`

Source from the content-addressed store, hash-verified

407
408
409class NonCallableMock(Base):
410 """A non-callable version of `Mock`"""
411
412 # Store a mutex as a class attribute in order to protect concurrent access
413 # to mock attributes. Using a class attribute allows all NonCallableMock
414 # instances to share the mutex for simplicity.
415 #
416 # See https://github.com/python/cpython/issues/98624 for why this is
417 # necessary.
418 _lock = RLock()
419
420 def __new__(cls, /, *args, **kw):
421 # every instance has its own class
422 # so we can create magic methods on the
423 # class without stomping on other mocks
424 bases = (cls,)
425 if not issubclass(cls, AsyncMockMixin):
426 # Check if spec is an async object or function
427 bound_args = _MOCK_SIG.bind_partial(cls, *args, **kw).arguments
428 spec_arg = bound_args.get('spec_set', bound_args.get('spec'))
429 if spec_arg is not None and _is_async_obj(spec_arg):
430 bases = (AsyncMockMixin, cls)
431 new = type(cls.__name__, bases, {'__doc__': cls.__doc__})
432 instance = _safe_super(NonCallableMock, cls).__new__(new)
433 return instance
434
435
436 def __init__(
437 self, spec=None, wraps=None, name=None, spec_set=None,
438 parent=None, _spec_state=None, _new_name='', _new_parent=None,
439 _spec_as_instance=False, _eat_self=None, unsafe=False, **kwargs
440 ):
441 if _new_parent is None:
442 _new_parent = parent
443
444 __dict__ = self.__dict__
445 __dict__['_mock_parent'] = parent
446 __dict__['_mock_name'] = name
447 __dict__['_mock_new_name'] = _new_name
448 __dict__['_mock_new_parent'] = _new_parent
449 __dict__['_mock_sealed'] = False
450
451 if spec_set is not None:
452 spec = spec_set
453 spec_set = True
454 if _eat_self is None:
455 _eat_self = parent is not None
456
457 self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
458
459 __dict__['_mock_children'] = {}
460 __dict__['_mock_wraps'] = wraps
461 __dict__['_mock_delegate'] = None
462
463 __dict__['_mock_called'] = False
464 __dict__['_mock_call_args'] = None
465 __dict__['_mock_call_count'] = 0
466 __dict__['_mock_call_args_list'] = _CallList()

Calls 3

RLockFunction · 0.90
propertyClass · 0.85
_delegating_propertyFunction · 0.85