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

Class NonCallableMock

Lib/unittest/mock.py:434–1109  ·  view source on GitHub ↗

A non-callable version of `Mock`

Source from the content-addressed store, hash-verified

432
433
434class NonCallableMock(Base):
435 """A non-callable version of `Mock`"""
436
437 # Store a mutex as a class attribute in order to protect concurrent access
438 # to mock attributes. Using a class attribute allows all NonCallableMock
439 # instances to share the mutex for simplicity.
440 #
441 # See https://github.com/python/cpython/issues/98624 for why this is
442 # necessary.
443 _lock = RLock()
444
445 def __new__(
446 cls, spec=None, wraps=None, name=None, spec_set=None,
447 parent=None, _spec_state=None, _new_name='', _new_parent=None,
448 _spec_as_instance=False, _eat_self=None, unsafe=False, **kwargs
449 ):
450 # every instance has its own class
451 # so we can create magic methods on the
452 # class without stomping on other mocks
453 bases = (cls,)
454 if not issubclass(cls, AsyncMockMixin):
455 # Check if spec is an async object or function
456 spec_arg = spec_set or spec
457 if spec_arg is not None and _is_async_obj(spec_arg):
458 bases = (AsyncMockMixin, cls)
459 new = type(cls.__name__, bases, {'__doc__': cls.__doc__})
460 instance = _safe_super(NonCallableMock, cls).__new__(new)
461 return instance
462
463
464 def __init__(
465 self, spec=None, wraps=None, name=None, spec_set=None,
466 parent=None, _spec_state=None, _new_name='', _new_parent=None,
467 _spec_as_instance=False, _eat_self=None, unsafe=False, **kwargs
468 ):
469 if _new_parent is None:
470 _new_parent = parent
471
472 __dict__ = self.__dict__
473 __dict__['_mock_parent'] = parent
474 __dict__['_mock_name'] = name
475 __dict__['_mock_new_name'] = _new_name
476 __dict__['_mock_new_parent'] = _new_parent
477 __dict__['_mock_sealed'] = False
478
479 if spec_set is not None:
480 spec = spec_set
481 spec_set = True
482 if _eat_self is None:
483 _eat_self = parent is not None
484
485 self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
486
487 __dict__['_mock_children'] = {}
488 __dict__['_mock_wraps'] = wraps
489 __dict__['_mock_delegate'] = None
490
491 __dict__['_mock_called'] = False

Calls 3

RLockFunction · 0.90
propertyClass · 0.85
_delegating_propertyFunction · 0.85