@@ -943,46 +943,51 @@ def _mock_call(_mock_self, *args, **kwargs):
943943 self = _mock_self
944944 self .called = True
945945 self .call_count += 1
946- _new_name = self ._mock_new_name
947- _new_parent = self ._mock_new_parent
948946
947+ # handle call_args
949948 _call = _Call ((args , kwargs ), two = True )
950949 self .call_args = _call
951950 self .call_args_list .append (_call )
952- self .mock_calls .append (_Call (('' , args , kwargs )))
953951
954952 seen = set ()
955- skip_next_dot = _new_name == '()'
953+
954+ # initial stuff for method_calls:
956955 do_method_calls = self ._mock_parent is not None
957- name = self ._mock_name
958- while _new_parent is not None :
959- this_mock_call = _Call ((_new_name , args , kwargs ))
960- if _new_parent ._mock_new_name :
961- dot = '.'
962- if skip_next_dot :
963- dot = ''
956+ method_call_name = self ._mock_name
964957
965- skip_next_dot = False
966- if _new_parent ._mock_new_name == '()' :
967- skip_next_dot = True
958+ # initial stuff for mock_calls:
959+ mock_call_name = self ._mock_new_name
960+ is_a_call = mock_call_name == '()'
961+ self .mock_calls .append (_Call (('' , args , kwargs )))
968962
969- _new_name = _new_parent ._mock_new_name + dot + _new_name
963+ # follow up the chain of mocks:
964+ _new_parent = self ._mock_new_parent
965+ while _new_parent is not None :
970966
967+ # handle method_calls:
971968 if do_method_calls :
972- if _new_name == name :
973- this_method_call = this_mock_call
974- else :
975- this_method_call = _Call ((name , args , kwargs ))
976- _new_parent .method_calls .append (this_method_call )
977-
969+ _new_parent .method_calls .append (_Call ((method_call_name , args , kwargs )))
978970 do_method_calls = _new_parent ._mock_parent is not None
979971 if do_method_calls :
980- name = _new_parent ._mock_name + '.' + name
972+ method_call_name = _new_parent ._mock_name + '.' + method_call_name
981973
974+ # handle mock_calls:
975+ this_mock_call = _Call ((mock_call_name , args , kwargs ))
982976 _new_parent .mock_calls .append (this_mock_call )
977+
978+ if _new_parent ._mock_new_name :
979+ if is_a_call :
980+ dot = ''
981+ else :
982+ dot = '.'
983+ is_a_call = _new_parent ._mock_new_name == '()'
984+ mock_call_name = _new_parent ._mock_new_name + dot + mock_call_name
985+
986+ # follow the parental chain:
983987 _new_parent = _new_parent ._mock_new_parent
984988
985- # use ids here so as not to call __hash__ on the mocks
989+ # check we're not in an infinite loop:
990+ # ( use ids here so as not to call __hash__ on the mocks)
986991 _new_parent_id = id (_new_parent )
987992 if _new_parent_id in seen :
988993 break
@@ -2018,6 +2023,10 @@ def __eq__(self, other):
20182023 else :
20192024 self_name , self_args , self_kwargs = self
20202025
2026+ if (getattr (self , 'parent' , None ) and getattr (other , 'parent' , None )
2027+ and self .parent != other .parent ):
2028+ return False
2029+
20212030 other_name = ''
20222031 if len_other == 0 :
20232032 other_args , other_kwargs = (), {}
0 commit comments