@@ -977,46 +977,51 @@ def _mock_call(_mock_self, *args, **kwargs):
977977 self = _mock_self
978978 self .called = True
979979 self .call_count += 1
980- _new_name = self ._mock_new_name
981- _new_parent = self ._mock_new_parent
982980
981+ # handle call_args
983982 _call = _Call ((args , kwargs ), two = True )
984983 self .call_args = _call
985984 self .call_args_list .append (_call )
986- self .mock_calls .append (_Call (('' , args , kwargs )))
987985
988986 seen = set ()
989- skip_next_dot = _new_name == '()'
987+
988+ # initial stuff for method_calls:
990989 do_method_calls = self ._mock_parent is not None
991- name = self ._mock_name
992- while _new_parent is not None :
993- this_mock_call = _Call ((_new_name , args , kwargs ))
994- if _new_parent ._mock_new_name :
995- dot = '.'
996- if skip_next_dot :
997- dot = ''
990+ method_call_name = self ._mock_name
998991
999- skip_next_dot = False
1000- if _new_parent ._mock_new_name == '()' :
1001- skip_next_dot = True
992+ # initial stuff for mock_calls:
993+ mock_call_name = self ._mock_new_name
994+ is_a_call = mock_call_name == '()'
995+ self .mock_calls .append (_Call (('' , args , kwargs )))
1002996
1003- _new_name = _new_parent ._mock_new_name + dot + _new_name
997+ # follow up the chain of mocks:
998+ _new_parent = self ._mock_new_parent
999+ while _new_parent is not None :
10041000
1001+ # handle method_calls:
10051002 if do_method_calls :
1006- if _new_name == name :
1007- this_method_call = this_mock_call
1008- else :
1009- this_method_call = _Call ((name , args , kwargs ))
1010- _new_parent .method_calls .append (this_method_call )
1011-
1003+ _new_parent .method_calls .append (_Call ((method_call_name , args , kwargs )))
10121004 do_method_calls = _new_parent ._mock_parent is not None
10131005 if do_method_calls :
1014- name = _new_parent ._mock_name + '.' + name
1006+ method_call_name = _new_parent ._mock_name + '.' + method_call_name
10151007
1008+ # handle mock_calls:
1009+ this_mock_call = _Call ((mock_call_name , args , kwargs ))
10161010 _new_parent .mock_calls .append (this_mock_call )
1011+
1012+ if _new_parent ._mock_new_name :
1013+ if is_a_call :
1014+ dot = ''
1015+ else :
1016+ dot = '.'
1017+ is_a_call = _new_parent ._mock_new_name == '()'
1018+ mock_call_name = _new_parent ._mock_new_name + dot + mock_call_name
1019+
1020+ # follow the parental chain:
10171021 _new_parent = _new_parent ._mock_new_parent
10181022
1019- # use ids here so as not to call __hash__ on the mocks
1023+ # check we're not in an infinite loop:
1024+ # ( use ids here so as not to call __hash__ on the mocks)
10201025 _new_parent_id = id (_new_parent )
10211026 if _new_parent_id in seen :
10221027 break
@@ -2054,6 +2059,10 @@ def __eq__(self, other):
20542059 else :
20552060 self_name , self_args , self_kwargs = self
20562061
2062+ if (getattr (self , 'parent' , None ) and getattr (other , 'parent' , None )
2063+ and self .parent != other .parent ):
2064+ return False
2065+
20572066 other_name = ''
20582067 if len_other == 0 :
20592068 other_args , other_kwargs = (), {}
0 commit comments