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

Function _check_and_set_parent

Lib/unittest/mock.py:394–418  ·  view source on GitHub ↗
(parent, value, name, new_name)

Source from the content-addressed store, hash-verified

392
393
394def _check_and_set_parent(parent, value, name, new_name):
395 value = _extract_mock(value)
396
397 if not _is_instance_mock(value):
398 return False
399 if ((value._mock_name or value._mock_new_name) or
400 (value._mock_parent is not None) or
401 (value._mock_new_parent is not None)):
402 return False
403
404 _parent = parent
405 while _parent is not None:
406 # setting a mock (value) as a child or return value of itself
407 # should not modify the mock
408 if _parent is value:
409 return False
410 _parent = _parent._mock_new_parent
411
412 if new_name:
413 value._mock_new_parent = parent
414 value._mock_new_name = new_name
415 if name:
416 value._mock_parent = parent
417 value._mock_name = name
418 return True
419
420# Internal class to identify if we wrapped an iterator object or not.
421class _MockIter(object):

Callers 2

__set_return_valueMethod · 0.85
__setattr__Method · 0.85

Calls 2

_extract_mockFunction · 0.85
_is_instance_mockFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…