MCPcopy Create free account
hub / github.com/python/cpython / _extract_mock_name

Method _extract_mock_name

Lib/unittest/mock.py:740–765  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

738
739
740 def _extract_mock_name(self):
741 _name_list = [self._mock_new_name]
742 _parent = self._mock_new_parent
743 last = self
744
745 dot = '.'
746 if _name_list == ['()']:
747 dot = ''
748
749 while _parent is not None:
750 last = _parent
751
752 _name_list.append(_parent._mock_new_name + dot)
753 dot = '.'
754 if _parent._mock_new_name == '()':
755 dot = ''
756
757 _parent = _parent._mock_new_parent
758
759 _name_list = list(reversed(_name_list))
760 _first = last._mock_name or 'mock'
761 if len(_name_list) > 1:
762 if _name_list[1] not in ('()', '().'):
763 _first += '.'
764 _name_list[0] = _first
765 return ''.join(_name_list)
766
767 def __repr__(self):
768 name = self._extract_mock_name()

Callers 5

__repr__Method · 0.95
__setattr__Method · 0.95
_get_child_mockMethod · 0.95
mock.pyFile · 0.80

Calls 3

listClass · 0.85
appendMethod · 0.45
joinMethod · 0.45

Tested by 1