diff options
author | Michael Foord <michael@voidspace.org.uk> | 2011-08-08 23:35:30 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2011-08-08 23:35:30 +0100 |
commit | eade628eb88f6038ed7702dc8cb12535487ac376 (patch) | |
tree | 4a9e0bd4a7b604a74fe952af2652ea6e17cb0138 /mock.py | |
parent | a9aab81ad36a9bfeafd68982ce2374e96f03a15d (diff) | |
download | mock-eade628eb88f6038ed7702dc8cb12535487ac376.tar.gz |
Mock uses new name for repr
Diffstat (limited to 'mock.py')
-rw-r--r-- | mock.py | 50 |
1 files changed, 33 insertions, 17 deletions
@@ -688,31 +688,47 @@ class NonCallableMock(Base): def __repr__(self): - if self._mock_name is None and self._spec_class is None: - return object.__repr__(self) + _name_list = [self._mock_new_name] + _parent = self._mock_new_parent + last = self + + dot = '.' + if _name_list == ['()']: + dot = '' + while _parent is not None: + last = _parent + + _name_list.append(_parent._mock_new_name + dot) + dot = '.' + if _parent._mock_new_name == '()': + dot = '' + + _parent = _parent._mock_new_parent + + _name_list = list(reversed(_name_list)) + _first = last._mock_name or 'mock' + if len(_name_list) > 1: + if _name_list[1] not in ('()', '().'): + _first += '.' + _name_list[0] = _first + name = ''.join(_name_list) name_string = '' - spec_string = '' - if self._mock_name is not None: - def get_name(name): - if name is None: - return 'mock' - return name - parent = self._mock_parent - name = self._mock_name - while parent is not None: - name = get_name(parent._mock_name) + '.' + name - parent = parent._mock_parent + if name not in ('mock', 'mock.'): name_string = ' name=%r' % name + + spec_string = '' if self._spec_class is not None: spec_string = ' spec=%r' if self._spec_set: spec_string = ' spec_set=%r' spec_string = spec_string % self._spec_class.__name__ - return "<%s%s%s id='%s'>" % (type(self).__name__, - name_string, - spec_string, - id(self)) + return "<%s%s%s id='%s'>" % ( + type(self).__name__, + name_string, + spec_string, + id(self) + ) def __dir__(self): |