@@ -955,46 +955,51 @@ def _mock_call(_mock_self, *args, **kwargs):
955955 self = _mock_self
956956 self .called = True
957957 self .call_count += 1
958- _new_name = self ._mock_new_name
959- _new_parent = self ._mock_new_parent
960958
959+ # handle call_args
961960 _call = _Call ((args , kwargs ), two = True )
962961 self .call_args = _call
963962 self .call_args_list .append (_call )
964- self .mock_calls .append (_Call (('' , args , kwargs )))
965963
966964 seen = set ()
967- skip_next_dot = _new_name == '()'
965+
966+ # initial stuff for method_calls:
968967 do_method_calls = self ._mock_parent is not None
969- name = self ._mock_name
970- while _new_parent is not None :
971- this_mock_call = _Call ((_new_name , args , kwargs ))
972- if _new_parent ._mock_new_name :
973- dot = '.'
974- if skip_next_dot :
975- dot = ''
968+ method_call_name = self ._mock_name
976969
977- skip_next_dot = False
978- if _new_parent ._mock_new_name == '()' :
979- skip_next_dot = True
970+ # initial stuff for mock_calls:
971+ mock_call_name = self ._mock_new_name
972+ is_a_call = mock_call_name == '()'
973+ self .mock_calls .append (_Call (('' , args , kwargs )))
980974
981- _new_name = _new_parent ._mock_new_name + dot + _new_name
975+ # follow up the chain of mocks:
976+ _new_parent = self ._mock_new_parent
977+ while _new_parent is not None :
982978
979+ # handle method_calls:
983980 if do_method_calls :
984- if _new_name == name :
985- this_method_call = this_mock_call
986- else :
987- this_method_call = _Call ((name , args , kwargs ))
988- _new_parent .method_calls .append (this_method_call )
989-
981+ _new_parent .method_calls .append (_Call ((method_call_name , args , kwargs )))
990982 do_method_calls = _new_parent ._mock_parent is not None
991983 if do_method_calls :
992- name = _new_parent ._mock_name + '.' + name
984+ method_call_name = _new_parent ._mock_name + '.' + method_call_name
993985
986+ # handle mock_calls:
987+ this_mock_call = _Call ((mock_call_name , args , kwargs ))
994988 _new_parent .mock_calls .append (this_mock_call )
989+
990+ if _new_parent ._mock_new_name :
991+ if is_a_call :
992+ dot = ''
993+ else :
994+ dot = '.'
995+ is_a_call = _new_parent ._mock_new_name == '()'
996+ mock_call_name = _new_parent ._mock_new_name + dot + mock_call_name
997+
998+ # follow the parental chain:
995999 _new_parent = _new_parent ._mock_new_parent
9961000
997- # use ids here so as not to call __hash__ on the mocks
1001+ # check we're not in an infinite loop:
1002+ # ( use ids here so as not to call __hash__ on the mocks)
9981003 _new_parent_id = id (_new_parent )
9991004 if _new_parent_id in seen :
10001005 break
@@ -2030,6 +2035,10 @@ def __eq__(self, other):
20302035 else :
20312036 self_name , self_args , self_kwargs = self
20322037
2038+ if (getattr (self , 'parent' , None ) and getattr (other , 'parent' , None )
2039+ and self .parent != other .parent ):
2040+ return False
2041+
20332042 other_name = ''
20342043 if len_other == 0 :
20352044 other_args , other_kwargs = (), {}
0 commit comments