U .cx @sddlZddlZddlZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZGdddeZGdddeZd d ZGd d d ejZed kredS)N) is_instancemock) callDEFAULTpatchsentinel MagicMockMockNonCallableMockNonCallableMagicMock AsyncMock_Call _CallListcreate_autospecc@s(eZdZddZddZddZeZdS)ItercCstddddg|_dS)Nthisisaniter)rthingselfrD/opt/alt/python38/lib64/python3.8/unittest/test/testmock/testmock.py__init__sz Iter.__init__cCs|SNrrrrr__iter__sz Iter.__iter__cCs t|jSr)nextrrrrrrsz Iter.nextN)__name__ __module__ __qualname__rrr__next__rrrrrsrc@s2eZdZdddZed ddZed ddZdS) SomethingNcCsdSrrrabcdrrrmethzSomething.methcCsdSrr)clsr%r&r'r(rrrcmeth!szSomething.cmethcCsdSrrr%r&r'r(rrrsmeth$szSomething.smeth)N)N)N)rr r!r) classmethodr, staticmethodr.rrrrr#s   r#cCsdSrrr%rrr something(r*r2c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPZ*dQdRZ+dSdTZ,dUdVZ-dWdXZ.dYdZZ/d[d\Z0d]d^Z1d_d`Z2dadbZ3dcddZ4dedfZ5dgdhZ6didjZ7dkdlZ8dmdnZ9dodpZ:dqdrZ;dsdtZdydzZ?d{d|Z@d}d~ZAddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbdd„ZcddĄZdddƄZeddȄZfddʄZgdd̄Zhdd΄ZiddЄZjdd҄ZkddԄZlddքZmdd؄ZnddڄZodd܄ZpddބZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddZddZddZddZdS(MockTestcCs tddS)Nzfrom unittest.mock import *)execrrrrtest_all-szMockTest.test_allcCst}||jd||jdd|t|jtd||jdd||j gd||j gd| d|j d | |jd | |jd ||jid dS) Nz called not initialised correctlyrz$call_count not initialised correctlyz&return_value not initialised correctlyz#call_args not initialised correctly(call_args_list not initialised correctlyz&method_calls not initialised correctly_itemsz/default mock should not have '_items' attributez parent not initialised correctlyz!methods not initialised correctlyz$children not initialised incorrectly)r assertFalsecalled assertEqual call_count assertTruer return_value call_argscall_args_list method_calls assertNotIn__dict__ assertIsNone _mock_parent _mock_methods_mock_childrenrrrrrtest_constructor4s:      zMockTest.test_constructorcCstdd}||jddS)Nr=z(return value in constructor not honoured)r rCr=rGrrr test_return_value_in_constructorPs z)MockTest.test_return_value_in_constructorcCs*dd}t|}d|j_||ddS)NcSsdSrrrrrrfWr*z9MockTest.test_change_return_value_via_delegate..f)rrr=r:rrKrrrr%test_change_return_value_via_delegateVsz.MockTest.test_change_return_value_via_delegatec Cs:dd}t|}t|j_|t |W5QRXdS)NcSsdSrrrrrrrK^r*z8MockTest.test_change_side_effect_via_delegate..f)r TypeErrorr side_effect assertRaisesrMrrr$test_change_side_effect_via_delegate]s   z-MockTest.test_change_side_effect_via_delegatecCstdd}|dt||dt|t|tdftdddfg}|D]\}}|d|t|j|d|t||d|t|j|d |t||d |t||d |t|jjjqNdS) Nfoonamez'%s'rbarz%s.barz%s.foo()z %s.foo().bingz%s()z%s()()z%s()().foo.bar.baz().bing)r assertInrepridrVrSZbingbaz)rrmocksrUrrr test_repres   zMockTest.test_reprcCsGdddt}t|d}|dt|t|d}|dt|t|d}|dt|t|d}|dt|t|dd}|dt||d t|tdd }|d t|t}|d t|tdgd}|d t|dS) Nc@s eZdZdS)z'MockTest.test_repr_with_spec..XNrr r!rrrrXvsr^specz spec='X' spec_setz spec_set='X' rS)r`rUz name='foo' rTr`)objectr rWrXrArr^rrrrtest_repr_with_specus$       zMockTest.test_repr_with_speccst}dd}||_|jt|dddd|jdddddddgfdd}||_||||gdddgdttjd }||jtjd d d }t|tjd }||tjdS)Nc_s tddS)NZkablooie) SystemError)argskwargsrrreffectsz)MockTest.test_side_effect..effectrLfishcsSrpoprZresultsrrriszside effect not used correctlyrPz#side effect in constructor not usedcSstSrrrrrrrPsz.MockTest.test_side_effect..side_effect)rPr=) r rPrQrfassert_called_withr:r SideEffectRETURN)rrrirPrrprtest_side_effects$    zMockTest.test_side_effectcsdddgfdd}dd}t|}dddg|_||||gdddgddddgt|}||_||||gdddgd dS) NrLrjrkcsSrrnrrprrrisz2MockTest.test_autospec_side_effect..effectcSsdSrrrrrrrKr*z-MockTest.test_autospec_side_effect..fz1side effect not used correctly in create_autospecz'callable side effect not used correctly)rrPr:)rrirKrrrprtest_autospec_side_effects    z"MockTest.test_autospec_side_effectcCs,dd}t|}td|_|td|dS)NcSsdSrrrrrrrKr*z7MockTest.test_autospec_side_effect_exception..fzBazinga!)r ValueErrorrPassertRaisesRegexrMrrr#test_autospec_side_effect_exceptions z,MockTest.test_autospec_side_effect_exceptioncCsRt}dg}td||d}|tjtjd|j}|tj|_|j}||| |j dd| |j |d| |j |d| |jd| |jd d | |jdd | |jgd | |jgd |jgf| |jg| |jtjd| |j|d| |jd| |jd|id| |j|d| |jjddS)Nr2child)rUparentr`r2zname incorrectly resetzparent incorrectly resetzmethods incorrectly resetzcalled not resetrzcall_count not resetzcall_args not resetzcall_args_list not resetz0method_calls not initialised correctly: %r != %rzside_effect incorrectly resetzreturn_value incorrectly resetzreturn value mock not resetzchildren reset incorrectlyzchildren incorrectly clearedzchild not reset)r rr#Z SomethingElser2rtrPr= reset_mockr: _mock_namerDrEr8r9r;r>r?r@ mock_callsrF)rr|r`rr2r=rrrtest_reset_mocksV       zMockTest.test_reset_mockcCst}||_|dSr)r r=r~rGrrrtest_reset_mock_recursionsz"MockTest.test_reset_mock_recursioncCst}|dSr)r mock_openr~rr%rrr(test_reset_mock_on_mock_open_issue_18622sz1MockTest.test_reset_mock_on_mock_open_issue_18622cCs>t}|t|jtd|}|||d||tj}||jd||j dd||j tjfifd||j j tjfd||j j id||j tjfifgdtj|_|tjtjd}||tjd ||j d d ||j tjfd tjifd||j tjfiftjfd tjifgd dS)Nz%Default return_value should be a Mockz'different result from consecutive callszcalled not setrLzcall_count incoreectzcall_args not setr6)keyzincorrect return valuerjzcall_count incorrectrzcall_args_list not set)r r<rr=r:r~rArgr9r;r>rgrhr?Z ReturnValueZKeyArg)rrresultZret_valrrr test_callsP     zMockTest.test_callc Cst}||tj|tjd|tjtjd||jdtjffdtjiftjfdtjifg||jtjfdtjif||jjtjf||jjdtji| |jdkdS)N)kwrrza long sequence) r rrZKwargr:r?r>rgrhr8rGrrrtest_call_args_comparison#s"   z"MockTest.test_call_args_comparisoncCst}|||k|||k||tk||tk||tjk||tjk|tj|k|tj|ktt}ttj}|||k|||k|||k|||kdSr)rr r<r8ANYr)rZmmZcall1Zcall2rrrtest_calls_equal_with_any9s z"MockTest.test_calls_equal_with_anycCsdt}|||t|jd||t|j|dddddd|jdddddddS)NrLrjrkrmZnothingr%r&)r rsrQAssertionErrorr~rGrrrtest_assert_called_withNsz MockTest.test_assert_called_withcCs t}|t|tjdSr)r rsrrrmrrrtest_assert_called_with_any]s z$MockTest.test_assert_called_with_anyc Csd dd}t|d}|dddd|ddd|jdddd|jt|jdddd|t}|jd d W5QRX||jjtdS) NcSsdSrrr-rrrrKdr*z9MockTest.test_assert_called_with_function_spec..fr_rLrjrkr&r'r%r&r'e)N)r rsrQrassertIsInstance exception __cause__rOrrKrcmrrr%test_assert_called_with_function_speccs    z.MockTest.test_assert_called_with_function_speccszfdd}ttjd}||ttjd}||ttjd}||ttjd}||ttjd}||dS)NcsF|dddd|ddd|jddddjt|jdddddS)NrLrjrkrr)rsrQrrrrr_checkts z._checkr_)r r#r)r,r.)rrrrrr#test_assert_called_with_method_specss   z,MockTest.test_assert_called_with_method_specc Cs\d}|t|dtW5QRX|t|dtddW5QRXdS)Nz"Expected '{0}' to have been calledrZ test_namerT)ryrformatr assert_called)rmsgrrr$test_assert_called_exception_messages z-MockTest.test_assert_called_exception_messagecst|tj|tjddddjdddddddd|tfdddS)NrSrVrjrZcsjddddS)NbobrVrjrassert_called_once_withrrrrr*z7MockTest.test_assert_called_once_with..)r rrQrr~rrrrtest_assert_called_once_withs z%MockTest.test_assert_called_once_withcs6tdd|ttdfdddS)NrLrjzCalls: [call(1), call(2)]cs dS)Nrjrrrrrrr*zAMockTest.test_assert_called_once_with_call_list..)r ryrreescaperrrr&test_assert_called_once_with_call_lists z/MockTest.test_assert_called_once_with_call_listc Csddd}t|d}|dddd|ddd|jdddd|jt|jdddd|t}|jd d W5QRX||jjt|d d d |t|jddd|t|jd d d dS)NcSsdSrrr-rrrrKr*z>MockTest.test_assert_called_once_with_function_spec..fr_rLrjrkrrrr)N)r rrQrrrrrOrrrr*test_assert_called_once_with_function_specs0       z3MockTest.test_assert_called_once_with_function_speccCsbt}|j}|t|td||j|dt}d|j_||dd||jjddS)Nzattribute isn't a mockz+different attributes returned for same namerkzmethod returned wrong valuez!method didn't record being called)r r2r<rr:r=r9rrr2rrr#test_attribute_access_returns_mockss  z,MockTest.test_attribute_access_returns_mockscCs0t}|j}||jdd||j|ddS)Nr2z attribute name not set correctlyz"attribute parent not set correctly)r r2r:rrDrrrr(test_attributes_have_name_and_parent_sets  z1MockTest.test_attributes_have_name_and_parent_setcCstt}|jddd|jjdtjd||jjdddtjifgd||jdd d difd ddtjifgddS) Nrkrlr)caker2)rrz#method calls not recorded correctly)rkrmzsomething_else.something)r r2something_elserZCaker:r@rGrrrtest_method_calls_recordeds  z#MockTest.test_method_calls_recordedcCst}|||jdg||jddifgt}|d||jdg||jddifgt}|jdd||jdd difg||jddd difgt}|jdd d ||jddd d ifgdS) Nr}r2r different)r2rrrLxrZmore)somer)r r2r:r@rGrrr test_method_calls_compare_easilys&    z)MockTest.test_method_calls_compare_easilyc CsDdgdfD]4}dD]*}tf||i}|j|tdt|dqq dS)Nr2r})r`rbz-Mock object has no attribute 'something_else'r)r r2ryAttributeErrorgetattr)rr`argrrrrtest_only_allowed_methods_existsz(MockTest.test_only_allowed_methods_existcs>Gdddt}fdd}|t|d|t|ddS)Nc@seZdZdZdZddZdS)z*MockTest.test_from_spec..SomethingrkNcSsdSrrrrrryr*z,MockTest.test_from_spec..Something.y)rr r!r __something__rrrrrr#sr#cs:|j|j|jtdt|dtdt|ddS)Nz Mock object has no attribute 'z'zz)Mock object has no attribute '__foobar__'Z __foobar__)rrrryrrrrrrtest_attributess"z0MockTest.test_from_spec..test_attributesr_)rcr )rr#rrrrtest_from_specs zMockTest.test_from_speccCsJt}t|d}|||||dddd|jdddddS)NwrapsrLrjrkrl)r r:r~rsrrealrrrrtest_wraps_calls.s  zMockTest.test_wraps_callscs8Gdddt}|}t|d|tfdddS)Nc@s eZdZdS)zFMockTest.test_wraps_prevents_automatic_creation_of_mocks..RealNr]rrrrReal;srrcsSr)Znew_attrrrrrrAr*zJMockTest.test_wraps_prevents_automatic_creation_of_mocks..)rcr rQr)rrrrrr/test_wraps_prevents_automatic_creation_of_mocks:s z8MockTest.test_wraps_prevents_automatic_creation_of_mockscCs4t}t|d}d|_||d||jdS)Nrrk)r r=r:r8r9rrrr,test_wraps_call_with_nondefault_return_valueDs  z5MockTest.test_wraps_call_with_nondefault_return_valuecsGdddt}|}t|d|||tfdd|j|jjjdddd }|jjjdddd |||jdS) Nc@seZdZeZdS)z,MockTest.test_wraps_attributes..RealN)rr r!r attributerrrrrOsrrcsjSrrlrrrrrVr*z0MockTest.test_wraps_attributes..rLrjrkrl) rcr r:rrQrassertNotEqualZfrogrs)rrrrrrrtest_wraps_attributesNs zMockTest.test_wraps_attributescCsdGdddt}|}t|d}tjtg|j_||tj||tj| t |jdS)Nc@seZdZddZdS)z[MockTest.test_customize_wrapped_object_with_side_effect_iterable_with_default..RealcSstjSr)rORIGINAL_VALUErrrrmethod`szbMockTest.test_customize_wrapped_object_with_side_effect_iterable_with_default..Real.methodNrr r!rrrrrr_srr) rcr rVALUE1rrrPr:rrQ StopIterationrrrrrrrDtest_customize_wrapped_object_with_side_effect_iterable_with_default^s zMMockTest.test_customize_wrapped_object_with_side_effect_iterable_with_defaultcCsfGdddt}|}t|d}tjtjg|j_||tj||tj|t |jdS)Nc@seZdZddZdS)zNMockTest.test_customize_wrapped_object_with_side_effect_iterable..RealcSsdSrrrrrrrnr*zUMockTest.test_customize_wrapped_object_with_side_effect_iterable..Real.methodNrrrrrrmsrr) rcr rrVALUE2rrPr:rQrrrrr7test_customize_wrapped_object_with_side_effect_iterablels z@MockTest.test_customize_wrapped_object_with_side_effect_iterablecCs:Gdddt}|}t|d}t|j_|t|jdS)Nc@seZdZddZdS)zOMockTest.test_customize_wrapped_object_with_side_effect_exception..RealcSsdSrrrrrrr{r*zVMockTest.test_customize_wrapped_object_with_side_effect_exception..Real.methodNrrrrrrzsrr)rcr RuntimeErrorrrPrQrrrr8test_customize_wrapped_object_with_side_effect_exceptionys  zAMockTest.test_customize_wrapped_object_with_side_effect_exceptioncCsFGdddt}dd}|}t|d}||j_||tjdS)Nc@seZdZddZdS)zNMockTest.test_customize_wrapped_object_with_side_effect_function..RealcSsdSrrrrrrrr*zUMockTest.test_customize_wrapped_object_with_side_effect_function..Real.methodNrrrrrrsrcSstjSr)rVALUErrrrrPszUMockTest.test_customize_wrapped_object_with_side_effect_function..side_effectr)rcr rrPr:rr)rrrPrrrrr7test_customize_wrapped_object_with_side_effect_functions  z@MockTest.test_customize_wrapped_object_with_side_effect_functioncCs@Gdddt}|}t|d}tj|j_||tjdS)Nc@seZdZddZdS)zFMockTest.test_customize_wrapped_object_with_return_value..RealcSsdSrrrrrrrr*zMMockTest.test_customize_wrapped_object_with_return_value..Real.methodNrrrrrrsrr)rcr rrrr=r:rrrr/test_customize_wrapped_object_with_return_values   z8MockTest.test_customize_wrapped_object_with_return_valuecCspGdddt}|}t|d}tjtjg|j_tj|j_| |tj| |tj| t |jdS)Nc@seZdZddZdS)zVMockTest.test_customize_wrapped_object_with_return_value_and_side_effect..RealcSsdSrrrrrrrr*z]MockTest.test_customize_wrapped_object_with_return_value_and_side_effect..Real.methodNrrrrrrsrr) rcr rrrrrPZ WRONG_VALUEr=r:rQrrrrr?test_customize_wrapped_object_with_return_value_and_side_effects  zHMockTest.test_customize_wrapped_object_with_return_value_and_side_effectcCsLGdddt}|}t|d}dd|j_tj|j_||tjdS)Nc@seZdZddZdS)zWMockTest.test_customize_wrapped_object_with_return_value_and_side_effect2..RealcSsdSrrrrrrrr*z^MockTest.test_customize_wrapped_object_with_return_value_and_side_effect2..Real.methodNrrrrrrsrrcSstSrrrrrrrrr*z[MockTest.test_customize_wrapped_object_with_return_value_and_side_effect2..)rcr rrPrrr=r:rrrr@test_customize_wrapped_object_with_return_value_and_side_effect2s    zIMockTest.test_customize_wrapped_object_with_return_value_and_side_effect2cCsnGdddt}|}t|d}tjtg|j_tj|j_| |tj| |tj| t |jdS)Nc@seZdZddZdS)z^MockTest.test_customize_wrapped_object_with_return_value_and_side_effect_default..RealcSsdSrrrrrrrr*zeMockTest.test_customize_wrapped_object_with_return_value_and_side_effect_default..Real.methodNrrrrrrsrr) rcr rrrrrPrur=r:rQrrrrrGtest_customize_wrapped_object_with_return_value_and_side_effect_defaults  zPMockTest.test_customize_wrapped_object_with_return_value_and_side_effect_defaultcCs4ttd}|t|ttdd}|t|dSNrqrS)r rrQrGrrrtest_exceptional_side_effects  z%MockTest.test_exceptional_side_effectcCs4ttd}|t|ttdd}|t|dSr)r KeyboardInterruptrQrGrrr test_baseexceptional_side_effects  z)MockTest.test_baseexceptional_side_effectcCst}|td|jdS)Nz not called)r ryrrsrGrrrtest_assert_called_with_messagesz(MockTest.test_assert_called_with_messagecCstdd}|td|jdS)NZgeoffreyrTz'Expected 'geoffrey' to be called once\.)r ryrrrGrrr$test_assert_called_once_with_messages  z-MockTest.test_assert_called_once_with_messagecs2t|tfddd_|jddS)NcsjSr)rrrrrrr*z'MockTest.test__name__..rS)r rQrrr:rrrr test__name__szMockTest.test__name__cCsJGdddt}t|dgd}|d|jd|tt|ddS)Nc@s eZdZdS)z-MockTest.test_spec_list_subclass..SubNr]rrrrSubsrrSr_rk)listr appendrsrQrr)rrrrrrtest_spec_list_subclasss   z MockTest.test_spec_list_subclasscCsGdddt}t|d}|||t|d}|||||j||tjjdt|d}|||t|d}|||dS)Nc@s eZdZdS)z#MockTest.test_spec_class..XNr]rrrrr^sr^r_r ra)rcr rassertIs __class__r:rrdrrrtest_spec_classs       zMockTest.test_spec_classcCsGddd}t|d}|||t|d}|||||j||tjjdt|d}|||t|d}|||dS)Nc@s eZdZdS)z2MockTest.test_spec_class_no_object_base..XNr]rrrrr^ sr^r_r ra)r rrrr:rrdrrrtest_spec_class_no_object_base s       z'MockTest.test_spec_class_no_object_basecsLGdddt}t|dd_t|dfdd}d_|t|dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set..XrkN)rr r!rrrrrr^sr^r_rSracs d_dSNrSrrrrrset_attr%sz?MockTest.test_setting_attribute_with_spec_set..set_attr)rcr rrrQr)rr^rrrr$test_setting_attribute_with_spec_sets   z-MockTest.test_setting_attribute_with_spec_setcCs4t}|tj|ttdttdS)NgeA)sysgetrecursionlimit addCleanupsetrecursionlimitintcopyr )rZcurrentrrr test_copy,szMockTest.test_copycs\Gdddt}||d|jdfdd}|t|fdd}|t|dS)Nc@s&eZdZddZddZeeeZdS)z8MockTest.test_subclass_with_properties..SubClasscSsdSNrkrrrrr_get8sz=MockTest.test_subclass_with_properties..SubClass._getcSs tddS)Nz strange error) NameError)rvaluerrr_set:sz=MockTest.test_subclass_with_properties..SubClass._setN)rr r!rrpropertysome_attributerrrrSubClass7srrarkcs d_dSr)rrsrrtestAsz4MockTest.test_subclass_with_properties..testcs d_dS)NrVrSrrrrrEs)r r:rrQrr)rrrrrrtest_subclass_with_properties6s    z&MockTest.test_subclass_with_propertiescCs>t}dd}|t|_|d|d|t|dddS)NcSs||||Sr)Z_increment_mock_callZ _mock_callrrrr__call__Ls z,MockTest.test_setting_call..__call__onetwo)r typer rsrQrO)rrr rrrtest_setting_callJs   zMockTest.test_setting_callcCst}tt|}tddttD}|t|||j|jf|dt||dt|d|_|_|dt||dt|dd|_ |d t|dS) NcSsg|]}|ds|qS)_) startswith).0rrrr Zs z%MockTest.test_dir..r%r&r'r(cSstgSr)rrrrrrjr*z#MockTest.test_dir..r) r setdirr:r%r&rWr'r(r)rrattrs type_attrsrrrtest_dirWs    zMockTest.test_dircCsXttjd}tttj}tt|}|t||d|_|t|dddS)Nr_rkversionrL)r unittestTestCaserrr:rcount)rrZtestcase_attrsrrrrtest_dir_from_specns   zMockTest.test_dir_from_speccCsVttdd}|z0ttt}ttt}|t||W5|XdS)NZ FILTER_DIRF) rrcrstartstoprrr r:)rZpatcherrrrrrtest_filter_dir{s zMockTest.test_filter_dircCs6t}d|j_|dt||`|dt|dS)NrLr{)r r{r=rWrrArGrrr,test_dir_does_not_include_deleted_attributess z5MockTest.test_dir_does_not_include_deleted_attributescCstdd}||jdtdd}||jdtdtd}tf|}|t|||jd||jtt}|jf||t|||jd||jtdS)NrVr!)rPzfoo.bar.return_valuerS) r r:rSr KeyErrorrQrVrZconfigure_mock)rrrhrrrtest_configure_mocks       zMockTest.test_configure_mockc Os:||}|||W5QRXt|j}|||dSr)rQstrrr:)rrmessagefuncrgrhcontextrrrrassertRaisesWithMsgs  zMockTest.assertRaisesWithMsgc Cst}d}d}d}|jt|||f|jddddd|jddddd |jj|jjg}|D]0}d }d }d}|jt|||f|dddddqZ|D]*}d }d }d}|jt|||f|ddq|D],}d }d }d}|t|||f|dddq|D]&}d }d}d}|t|||f|qdS)Nz not called.zmock(1, '2', 3, bar='foo')z0expected call not found. Expected: %s Actual: %srL2rkrS)rVrzfoo(1, '2', 3, foo='foo')zfoo(1, '2', 3, bar='foo')zfoo(bar='foo')z foo(1, 2, 3)rjzfoo())r r(rrsrSr)rrZactualexpectedr%Z assertersr)rrr'test_assert_called_with_failure_messagesz     z0MockTest.test_assert_called_with_failure_messagec Cst}||jgkdt}|ddifg}||j|||t||j|||jjddifgt}|jdddddd ddifd d tddd fg}||j|||jjjdd tddd fg||jjd d tddd fgt}|j ddifd difddifg}||j|||jtj ttddfD]$}tf|}t |jddifg}||j|tf|}| ddifddifg}||j||| jtgtf|}|ddd||jtddd ||jtdd ||jtd tf|}|dddj jd||jtdddj jd ||jtddj jd ||jtdj jd tf|}t |j ddif}||jd|||jtj  ||j jt  ||j j jt qpdS)NTrrLrjrkrrrz().foorLrjrkrSz ().foo.barz().foo.bar().bazrVrTz foo.__int__r%za()z().foo.bar().baz().__int__)r rrr:rSrrdictr=rVrZ call_listrr%r&r'__int__)rrr*rhZ last_callrrrtest_mock_callss                 zMockTest.test_mock_callscCsFt}|}|||jttg||jtgdSr)r Zwibbler:rr)rrrrrrtest_child_mock_call_equal4s z#MockTest.test_child_mock_call_equalcCsFt}|||jdt||jdtdSNrLr)r rSr2rrrrr:rrrrtest_mock_call_not_equal_leaf>s z&MockTest.test_mock_call_not_equal_leafcCsFt}|||jdt||jdtdSr4r rSrVrrrrZrrrr!test_mock_call_not_equal_non_leafEs z*MockTest.test_mock_call_not_equal_non_leafcCs8t}|jdd||jdtjdddS)NrLrrj)r rSrVr:rrrrrr2test_mock_call_not_equal_non_leaf_params_differentLsz;MockTest.test_mock_call_not_equal_non_leaf_params_differentcCs,t}|j||jdtjdSNrr6rrrr&test_mock_call_not_equal_non_leaf_attrSs z/MockTest.test_mock_call_not_equal_non_leaf_attrcCs.t}|j||jdtdSr9)r rSrVrrrrrrr2test_mock_call_not_equal_non_leaf_call_versus_attrYs z;MockTest.test_mock_call_not_equal_non_leaf_call_versus_attrcCs^t}|j|t|jdd|t|jdd|t|jdddS)Nrz call.foo()rLzcall.foo().bar()rjzcall.foo().bar().baz.bob())r rSrVrZrr:rXrrrrrtest_mock_call_repr_s zMockTest.test_mock_call_reprcCs0t}||_t||t|ddS)Nz)r rSrXZ assertRegexrrrrtest_mock_call_repr_loopgs z!MockTest.test_mock_call_repr_loopcCst}|tg|jkdSr)r r8rrrrrrtest_mock_calls_containsnsz!MockTest.test_mock_calls_containscCshGdddt}|}||j||||Gdddt}|}||j||||dS)Nc@s eZdZdS)+MockTest.test_subclassing..SubclassNr]rrrrSubclasstsr@c@seZdZddZdS)r?c[s tf|Sr)r )rrhrrr_get_child_mock|sz;MockTest.test_subclassing..Subclass._get_child_mockN)rr r!rArrrrr@{s)r rrSassertNotIsInstance)rr@rrrrtest_subclassingsszMockTest.test_subclassingcsttttg}fdd}|D]z}||t|rb||dd|dd|||||jjddd|dd|||q$dS)Ncs@d}|D]2}t||}|t|t|gqdS)N)r?r@r)rrrrr:)rnamesrUattrrrr assert_attrss    z-MockTest.test_arg_lists..assert_attrsrLrjrkr1) r r r r callabler~rSrVrZ)rr[rFrrrrtest_arg_listss&   zMockTest.test_arg_listscCst}|ddd|ddd|t|jd||jjd||jjtdddtddfdtddfg}t||jD]@\}}|t|d||d |d ||d|dq~dS) NrLrkr1rjrr&)rjrLr) r r:lenr>rgrhr/zipr?)rrZ expected_listr*r>rrrtest_call_args_two_tuples  z!MockTest.test_call_args_two_tuplecCsttdddgd}||||gdddg|t|tdddgd}||||gdddg|t|tdd}||||gd d d g|t|Gd d d t}t|d}|||ttd}|||||gddddg|t|dS)NrLrjrkrqr%r&r'Zghighic@s eZdZdS)z/MockTest.test_side_effect_iterator..FooNr]rrrrFoosrQrrrr) r rr:rQrr rcrr)rrrQrrrtest_side_effect_iterators"       z"MockTest.test_side_effect_iteratorcCs\ttfD]N}tdtdf}||d}|t|||d|t|||dqdS)Nrkrrq)r r rxr"rQr:)rKlassiterablerrrr$test_side_effect_iterator_exceptionss     z-MockTest.test_side_effect_iterator_exceptionscCst}tdddg|_||||gdddg|t||j}||ttgdddg|_||||gdddg|t||j}||ttgt}||_|||||gddd d g|t|| |j|dS) NrLrjrkr%r&r'rrrr) r rrPr:rQrrr rr)rrrPZ this_iterrrr!test_side_effect_setting_iterators$     z*MockTest.test_side_effect_setting_iteratorcCs4tdd}tdtg|_|||gddgdS)NrjrIrL)r rrrPr:rGrrr!test_side_effect_iterator_defaults z*MockTest.test_side_effect_iterator_defaultc Cst}|dd|dd|dd|dd|ddtddddifd d ddifd d ddifd d ifd d ddifg}|D]}|j|gddq|tddtddtdddfD]}|jt|j|gddqtddtddgtddtddgtddtddgg}|D]}|j|ddq tddtddtddgtddtddgtddtddtddgtddtddtddtddtddgg}|D]}|jt|j|ddqdS)NrLrjrkr1rrrIr%)rkrr)r,rLrjr,rYTZ any_orderr)rSr)r rassert_has_callsrQr)rrkallskallZ kall_listsZ kall_listrrrtest_assert_has_calls_any_ordersT        "*z(MockTest.test_assert_has_calls_any_orderc Cstddddifdtdddd d difg}ttdg}|tjdd |tjtid  dgg}t t fD]F}|dd|dd |dd |dd|ddd| ||fqt }||d|jdd |jtid  dg| ||f|D]j\}}t t|D]R}dD]F}||||}||t|dkr>|t|jtt|q>q6q"dS)NrLrjr%rkrXrrIr,rJr&r1rrr-)rrSrVextendZspamrZr0Zbamrrmr r rrangerKr\rQrrreversed) rZkalls1Zkalls2r[rr]rPstepZtheserrrtest_assert_has_callssD "         zMockTest.test_assert_has_callsc CsFGddd}t|}||fD]H}|jddddd|tjdddddg|tddddgq |||fD]l}|t|jtg|ddd|tdtdddg|jtdtddgq||tdt dt dtddddg}|D]}|t|j|gq(dS)Nc@s,eZdZddZdddZGdddZdS) z=MockTest.test_assert_has_calls_nested_spec..SomethingcSsdSrrrrrrrJr*zFMockTest.test_assert_has_calls_nested_spec..Something.__init__NcSsdSrrr$rrrr)Kr*zBMockTest.test_assert_has_calls_nested_spec..Something.methc@seZdZddZddZdS)zAMockTest.test_assert_has_calls_nested_spec..Something.FoocSsdSrrrrrrrOr*zJMockTest.test_assert_has_calls_nested_spec..Something.Foo.__init__cSsdSrr)rr%r&rrrmeth1Pr*zGMockTest.test_assert_has_calls_nested_spec..Something.Foo.meth1N)rr r!rrerrrrrQMsrQ)N)rr r!rr)rQrrrrr#Hs r#rLrjrkr(r) rr)r\rr~rQrrQreZ non_existent)rr#Z mock_classrZ invalid_callsr^rrr!test_assert_has_calls_nested_specGs. "  z*MockTest.test_assert_has_calls_nested_speccCsJt}||t}| |dSr) r rSrVrZr r threerr0r\)rrcallsrrr)test_assert_has_calls_nested_without_specos z2MockTest.test_assert_has_calls_nested_without_specc Csddd}t|d}|dddd|dd d d d |d dddddifdddd ifdifg}|||j|dd||dd|j|dddd||dd|j|ddddtt|}|t||W5QRX|j|dd|t||ddW5QRX|j|dddd|t||ddW5QRX|j|dddddS)NcSsdSrrr-rrrrKxr*z.fr_rLrjrkrrrrr[r'r( )r'r,r-)rrrr()rlrmrnTrZr.)N)r r\rrbrQr)rrKrrirrr(test_assert_has_calls_with_function_specws2        z1MockTest.test_assert_has_calls_with_function_specc Csd dd}t|d}|d|tdtd}|tgW5QRX||j j |tdtd}|ttddgW5QRX| |j j t dS) NcSsdSrrrrrrrKr*zAMockTest.test_assert_has_calls_not_matching_spec_error..fr_rLz^{}$z5Calls not found. Expected: [call()] Actual: [call(1)]zError processing expected calls. Errors: [None, TypeError('too many positional arguments')] Expected: [call(), call(1, 2)] Actual: [call(1)]rj)N) r ryrrrrr\rrCrrrrOrrrr-test_assert_has_calls_not_matching_spec_errors.   z6MockTest.test_assert_has_calls_not_matching_spec_errorcCst}|dd|dd|ddd|dd|jdd|jddd|t|j|t|jdd|jt|jdddS)NrLrjrkr1rrIr)r assert_any_callrQrrGrrrtest_assert_any_calls,     zMockTest.test_assert_any_callc Csddd}t|d}|dddd|dd d d d |ddd|jdddd |dd d d |jdd d d d|jt|jdddd|t}|jddW5QRX||jjtdS)NcSsdSrrr-rrrrKr*z;MockTest.test_assert_any_call_with_function_spec..fr_rLrjrkrrrrr[rkrr-rr)N)r rqrQrrrrrOrrrr'test_assert_any_call_with_function_specs     z0MockTest.test_assert_any_call_with_function_speccCsfdd}t}||_t|t|jg}|D]6}|dd|dd||jtddtddgq*dS)NcSsdSrrrrrrrKr*z3MockTest.test_mock_calls_create_autospec..frLrjrkr)rrKrr:rr)rrKobjZfuncsr&rrrtest_mock_calls_create_autospecs  z(MockTest.test_mock_calls_create_autospeccCs$tjtdd}|dt|dS)NZ sweet_funcrT)rrrcrWrXrrrrtest_create_autospec_with_namesz'MockTest.test_create_autospec_with_namec Cs`Gddd}dD]H}|j|d2tt||}|||t|dW5QRXqdS)Nc@s$eZdZeddZeddZdS)zMMockTest.test_create_autospec_classmethod_and_staticmethod..TestClasscSsdSrr)r+rrr class_methodszZMockTest.test_create_autospec_classmethod_and_staticmethod..TestClass.class_methodcSsdSrrrrrr static_methodsz[MockTest.test_create_autospec_classmethod_and_staticmethod..TestClass.static_methodN)rr r!r/rwr0rxrrrr TestClasss ry)rwrx)rZ extra_arg)ZsubTestrrrrrQrO)rryrZ mock_methodrrr1test_create_autospec_classmethod_and_staticmethodsz:MockTest.test_create_autospec_classmethod_and_staticmethodc Csht}d}|t||W5QRX|t||W5QRXtdd}||dS)Nz1Attributes cannot start with 'assert' or 'assret'T)Zunsafe)r ryrZassert_foo_callZassret_foo_call)rrrrrrtest_mock_unsafes zMockTest.test_mock_unsafec Cs<t}|j||t|jW5QRXdSr)r helloassert_not_calledrQrrrrrtest_assert_not_calleds   zMockTest.test_assert_not_calledcCs*t}|dd|ttd|jdS)NrLrjzCalls: [call(1, 2)])r ryrrrr}rrrrtest_assert_not_called_messages  z'MockTest.test_assert_not_called_messagec CsNt}|t|jW5QRX||j||jdSr)r rQrr|rrrrrtest_assert_calleds  zMockTest.test_assert_calledc Csdt}|t|jW5QRX||j||t|jW5QRXdSr)r rQrr|assert_called_oncerrrrtest_assert_called_once(s   z MockTest.test_assert_called_oncecCs2t}|dd|d|ttd|jdS)NrLrjrkzCalls: [call(1, 2), call(3)])r ryrrrrrrrrtest_assert_called_once_message3s z(MockTest.test_assert_called_once_messagec Cs:t}|t}|W5QRX|dt|jdS)NzCalls:)r rQrrrAr$r)rrrrrr*test_assert_called_once_message_not_called;s z3MockTest.test_assert_called_once_message_not_calledcCs0t}|jdddd}|t|jj|dS)Nr|Zhero)rUZdaddyz call(name='hello', daddy='hero'))r r|r:rXr>)rrtextrrrtest_ordered_call_signatureBsz$MockTest.test_ordered_call_signaturecCsVt}tdd}t}||dd||jd|||jd|dS)Nr|rrL)rrindexr r:r@)rr'rPrrrrtest_override_tuple_methodsIs  z$MockTest.test_override_tuple_methodscCs>tdddgd}|jddd||jt||jddS)Nrlrjrkr=rPT)r r~rr=r:rPrrrrtest_reset_return_sideeffectRsz%MockTest.test_reset_return_sideeffectcCs<tdddgd}|jdd||jt||jddS)NrlrjrkrTrI)r r~rr=rrPrrrrtest_reset_returnXs zMockTest.test_reset_returncCs<tdddgd}|jdd||jd||jddS)NrlrjrkrTrq)r r~r:r=rPrrrrtest_reset_sideeffect^s zMockTest.test_reset_sideeffectc sGdddt}Gdddt}Gdddtttttg}t|D]0}||ffdd ||ffd d qD|D]}ttd d fD]}|}|j|j |j f||fd gd gffD]\}}ttd d fD]}|j |f||j| t t|d | t t|dd|kr*| t t|dd|j |f|| t t|d |j | t t|dd|kr| t t|ddqqqqzdS)Nc@seZdZdZdS)z)MockTest.test_mock_add_spec.._OnerLN)rr r!r rrrr_Oneesrc@seZdZdZdS)z)MockTest.test_mock_add_spec.._TworjN)rr r!r rrrr_Twogsrc@seZdZdZZZdS)z-MockTest.test_mock_add_spec..AnythingZfourN)rr r!r r rhrrrrAnythingisrcs |dS)Nr_rKrrrrpr*z-MockTest.test_mock_add_spec..cs |dS)Nrarrrrrrqr*Trar r rhrb)rcr r r r rrr/r r rh mock_add_specrQrrsetattr) rrrZklassesrSrhrZOneZTworrrtest_mock_add_specdsz   zMockTest.test_mock_add_speccs|ttfD]n}|tt|tt|ddj_t| td|tfddqdS)NrSrcsdSrrrrrrrr*z;MockTest.test_mock_add_spec_magic_methods..) r r rrrcrQrOr1r=r:)rrSrrr test_mock_add_spec_magic_methodss   z)MockTest.test_mock_add_spec_magic_methodscCstttttfD]}|}t|_|||jtg||j tg|}tdd|_ | ||jg||j g|}t|_ | ||jg||j gqdS)NrUrT) r r r r r rSr:r@rrrVrZrrSrrrrtest_adding_child_mocks$  zMockTest.test_adding_child_mockcCs@ttfD]2}|}t|_|||jttgqdSr)r r r=r:rrrrrrtest_adding_return_value_mocks  z&MockTest.test_adding_return_value_mockcCsGdddt}t}t|d}t|d}|}||j|}||j||d||d||| |j t t gdS)Nc@seZdZdZdZdS)z'MockTest.test_manager_mock..Foor r N)rr r!r r rrrrrQsrQr r ) rcr rrrr attach_mockr r r:rr)rrQmanagerZp1Zp2Zmock_oneZmock_tworrrtest_manager_mocks      zMockTest.test_manager_mockcCshttfD]Z}|}tdd|_tdd|_t|t|||jttg||j gqdS)NrkrIg@) r r r1 __float__rfloatr:rrr@)rrSrrrrtest_magic_methods_mock_callss   z&MockTest.test_magic_methods_mock_callscCs<tjdd}|d}|}|d}|}|||dS)NdataZ read_dataa-namez another-name)rrreadr:)r mocked_openf1Zf1_dataf2Zf2_datarrr test_mock_open_reuse_issue_21750s  z)MockTest.test_mock_open_reuse_issue_21750cCsVtjdd}|d}dd|D}||dd||dd |t|gdS) NzRemarkable Norwegian BluerrcSsg|]}|qSrrrlinerrrrsz=MockTest.test_mock_open_dunder_iter_issue..rz Remarkable rLzNorwegian Blue)rrr:r)rrrlinesrrr test_mock_open_dunder_iter_issues  z)MockTest.test_mock_open_dunder_iter_issuec Cstjdd}|d}t|}|}dd|D}||d||d||dd |t|g|tt|W5QRXdS) Nz1st line 2nd line 3rd linerrcSsg|]}|qSrrrrrrrsz6MockTest.test_mock_open_using_next..z 1st line z 2nd line rz3rd line)rrrr"r:rrQr)rrrZline1Zline2rrrrtest_mock_open_using_nexts    z"MockTest.test_mock_open_using_nextc CsXttjdd}td|0|j}|j}td|_dd}|t|W5QRXdS)NZJLVrTztempfile.NamedTemporaryFilez Test 2 ErrorcSstddS)NZasd)tempfileZNamedTemporaryFilewriterrrrattemptsz.MockTest.test_mock_open_write..attempt) rrr rr=rOSErrorrPrQ)rZmock_namedtempZmock_filehandleZ mock_writerrrrtest_mock_open_write s zMockTest.test_mock_open_writecCsJtjdd}dd|jj_|}|}|d||d|dS)Nzfoo barnrcWsdS)Nabcr)rgrrrrr*z8MockTest.test_mock_open_alter_readline..r)rrr=readlinerPr:)rZmopenfirstsecondrrrtest_mock_open_alter_readlines     z&MockTest.test_mock_open_alter_readlinecCstjdd}|d}||d||d||d||d||g||g|dS)NrSrrVr,)rrrr:r readlines)rZ_openrOrrrtest_mock_open_after_eofs z!MockTest.test_mock_open_after_eofcCs ttfD]}|}t|}||_||||t|||||||t|||}|j|_| dt|j| dt|j|| dt|j| dt|j|}t|}||_||j_|t|||t||qdS)Nz name='mock.a') r r rXr=rr:r~r%r&rW)rrSrZ original_reprrrrtest_mock_parents+s, zMockTest.test_mock_parentscCsttttf}|D]}|D]z}|}|dd}||d||j||dt||j d| |j t j dg| |j t j dgqqdS)NrSrTrVzname='mock.bar'rL)r r r r rrrVrWrXrZr:rrr@rclassesrSZKlass2rZm2rrrtest_attach_mockHs    zMockTest.test_attach_mockcCsttttf}ttfD]h}|D]^}|}|dd}||d||||dt||| |j t  qqdS)NrSrTr=z name='mock()') r r r r rrrWrXrSr:rrr0rrrrtest_attach_mock_return_valueYs    z&MockTest.test_attach_mock_return_valuec Cst}tjtddd}||jd||d|dtd|dt dt dt dg}t dt dt dg}||j |||jj ||tj |||j || d t |jj||jd W5QRXdS) N .somethingTZautospecr2r{rLrjrk mock.child) r rrrr:Z_extract_mock_namerr{r2rrrWrX)rr|Z mock_funcZ parent_callsZ child_callsrrrtest_attach_mock_patch_autospecis  z(MockTest.test_attach_mock_patch_autospecc Cstjtddd}t}||dt}|jddddd |tj tj ddddd g|jttj ddddd g|ttj ddddd gW5QRXtjtd ddR}t}||d t d|t dgt tdg|tdgW5QRXtjtd dd}t}||d t}|jddddd |t t jddddd g|jtddddd g|ttjddddd gW5QRXdS)Nz.Something.methTr attach_methrLrjrkrrfr attach_funcz .Something attach_obj)rrrr rr#r)r\rrrr2rr)rZmockedrrtrrr)test_attach_mock_patch_autospec_signature}s2 &   z2MockTest.test_attach_mock_patch_autospec_signaturecCsfttttfD]L}|t|d|`|t|d|`|t|d| t t |dqdS)NrrK) r r r r r<hasattrrr8rKrQrrrGrrrtest_attribute_deletions z MockTest.test_attribute_deletioncCsttttfD]t}d|_|t|d||jd|`|t|dd|_|t|d||jd|`|t|dqdS)NrkrSr) r r r r rSr<rr:r8rGrrr7test_mock_does_not_raise_on_repeated_attribute_deletions z@MockTest.test_mock_does_not_raise_on_repeated_attribute_deletionc Cs<ttttfD]"}|`|t |`W5QRXqdSr)r r r r rSrQrrGrrr4test_mock_raises_when_deleting_nonexistent_attributes   z=MockTest.test_mock_raises_when_deleting_nonexistent_attributecCs,t}d|_|`||t|ddS)NTr{)r r{r~r8rrGrrr/test_reset_mock_does_not_raise_on_attr_deletions z8MockTest.test_reset_mock_does_not_raise_on_attr_deletioncCs:ttfD](}||tt|_||t|jq dSr)r r rBrrrrSrGrrrtest_class_assignables   zMockTest.test_class_assignablecCs8|tj|ttjt|ttjtdSr)assertIsNotNonerrUr:r rrrrrtest_name_attribute_of_calls z$MockTest.test_name_attribute_of_callcCs8|tj|ttjt|ttjtdSr)rrr|r:r rrrrrtest_parent_attribute_of_calls z&MockTest.test_parent_attribute_of_callcCsddd}t}t||_|dd|t|jd||jtddg|dt |jj dS)NcSsdSrrrrrrrSr*zBMockTest.test_parent_propagation_with_create_autospec..foorLrjr) r rr{rQrOr:rrrWrXr)rrSrrrr,test_parent_propagation_with_create_autospecs  z5MockTest.test_parent_propagation_with_create_autospeccCspdd}t}|t|ddd|dd|t|jd||jjtddg| dt |jj dS) NcSsdSrrrrrrrSr*zGMockTest.test_parent_propagation_with_autospec_attach_mock..foorVrTr{rLrjr) r rrr{rQrOr:rrrWrXr)rrSr|rrr1test_parent_propagation_with_autospec_attach_mocks z:MockTest.test_parent_propagation_with_autospec_attach_mockc stjj}|dd|td|tjd=fdd|tjttddl m }m }m }m }||||tg}|D]}|td }||tq~W5QRXdS) NcSsttjd|S)Nr)rrr)rrrrr r*z9MockTest.test_isinstance_under_settrace..z sys.modulesz unittest.mockcsSrr)frameZeventrtracerrrsz6MockTest.test_isinstance_under_settrace..tracer)r r r r r_)rrrrr/rmodulessettracegettrace unittest.mockr r r r r r#r) rZ old_patchr r r r r[rrtrrrtest_isinstance_under_settraces&      z'MockTest.test_isinstance_under_settraceN)rr r!r5rHrJrNrRr\rervrwrzrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrrr r#r(r+r2r3r5r7r8r:r;r<r=r>rCrHrMrRrUrVrWr_rdrgrjrorprrrsrurvrzr{r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr3+s )&                8N # ,((    5          r3__main__)rrrrrZunittest.test.testmock.supportrrrrrrrr r r r r rrrrcrr#r2rr3rmainrrrrs:  8