3 C\& @sddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZmZddlmZddlmZmZmZyeWnek reZYnXGdddeZGdddeZGd d d e ZGd d d eZGd ddejZ e!dkr ej"dS)N) callDEFAULTpatchsentinel MagicMockMockNonCallableMockNonCallableMagicMockcreate_autospec) _CallList)callable is_instancenextc@s(eZdZddZddZddZeZdS)ItercCstddddg|_dS)Nthisisaniter)rthing)selfri/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/mock/mock/tests/testmock.py__init__!sz Iter.__init__cCs|S)Nr)rrrr__iter__$sz Iter.__iter__cCs t|jS)N)rr)rrrrr'sz Iter.nextN)__name__ __module__ __qualname__rrr__next__rrrrr src@s2eZdZdddZed ddZed ddZdS) SomethingNcCsdS)Nr)rabcdrrrmeth.szSomething.methcCsdS)Nr)clsrr r!r"rrrcmeth1szSomething.cmethcCsdS)Nr)rr r!r"rrrsmeth5szSomething.smeth)N)N)N)rrrr# classmethodr% staticmethodr&rrrrr-s   rc@s eZdZdS)SubclassN)rrrrrrrr):sr)c@seZdZdZdZdS)ThingbarN)rrr attributefoorrrrr*>sr*c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ e j de jkdddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Z d7d8Z!d9d:Z"d;d<Z#d=d>Z$d?d@Z%dAdBZ&dCdDZ'dEdFZ(dGdHZ)dIdJZ*dKdLZ+e j,e-j.dMdNdOZ/e j,e-j.dMdPdQZ0dRdSZ1dTdUZ2dVdWZ3dXdYZ4dZd[Z5d\d]Z6d^d_Z7d`daZ8dbdcZ9dddeZ:dfdgZ;dhdiZdndoZ?dpdqZ@drdsZAdtduZBdvdwZCdxdyZDdzd{ZEd|d}ZFd~dZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[e j\ddZ]dS)MockTestcCs tddS)Nzfrom mock import *)exec)rrrrtest_allFszMockTest.test_allcCst}|j|jd|j|jdd|jt|jtd|j|jdd|j|j gd|j|j gd|j d|j d |j |jd |j |jd |j|jid dS) Nz called not initialised correctlyrz$call_count not initialised correctlyz&return_value not initialised correctlyz#call_args not initialised correctlyz(call_args_list not initialised correctlyz&method_calls not initialised correctlyZ_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_children)rmockrrrtest_constructorMs(      zMockTest.test_constructorcCstdd}|j|jddS)N)r7z(return value in constructor not honoured)rr=r7)rrArrr test_return_value_in_constructoris z)MockTest.test_return_value_in_constructorcCstdd}|jdt||jdt|t|tdftdddfg}x|D]\}}|jd|t|j|jd|t|j|jd|t|jj|jd |t||jd |t||jd |t|jjjjqPWdS) Nr.)namez'%s'rAr,z%s.barz%s.foo()z %s.foo().bingz%s()z%s()()z%s()().foo.bar.baz().bing)rassertInrepridr,r.Zbingbaz)rrAmocksrDrrr test_repros  zMockTest.test_reprcCsGdddt}t|d}|jdt|t|d}|jdt|t|d}|jdt|t|d}|jdt|t|dd}|jdt||jd t|tdd }|jd t|t}|jd t|tdgd}|jd t|dS) Nc@s eZdZdS)z'MockTest.test_repr_with_spec..XN)rrrrrrrXsrK)specz spec='X' )spec_setz spec_set='X' r.)rLrDz name='foo' )rDrL)objectrrErFr;)rrKrArrrtest_repr_with_specs$       zMockTest.test_repr_with_speccst}dd}||_|jt|dddd|jdddddddgfdd}||_|j|||gdddgdttjd }|j|jtjd d d }t|tjd }|j|tjdS)Nc_s tddS)NZkablooie) SystemError)argskwargsrrreffectsz)MockTest.test_side_effect..effect)fishcsjS)N)popr)resultsrrrSszside effect not used correctly) side_effectz#side effect in constructor not usedcSstS)N)rrrrrrZsz.MockTest.test_side_effect..side_effect)rZr7) rrZ assertRaisesrPassert_called_withr4r SideEffectZRETURN)rrArSrZr)rYrtest_side_effects     zMockTest.test_side_effectcsdddgfdd}dd}t|}dddg|_|j|||gdddgddddgt|}||_|j|||gdddgd dS) NrTrUrVcsjS)N)rXr)rYrrrSsz2MockTest.test_autospec_side_effect..effectcSsdS)Nrrrrrfsz-MockTest.test_autospec_side_effect..fz1side effect not used correctly in create_autospecz'callable side effect not used correctly)r rZr4)rrSr_rAr)rYrtest_autospec_side_effects    z"MockTest.test_autospec_side_effectcCs,dd}t|}td|_|jtd|dS)NcSsdS)Nrrrrrr_sz7MockTest.test_autospec_side_effect_exception..fzBazinga!)r ValueErrorrZassertRaisesRegex)rr_rArrr#test_autospec_side_effect_exceptions z,MockTest.test_autospec_side_effect_exceptionjavaz This test only applies to Jythonc Csdddl}t|jjdd}y|ddddWn|jjk rDYn X|jd|jdddddS) NrzBoom!)rZrTrUrV)rWzjava exception not raised)rdrlangZRuntimeExceptionfailr\)rrdrArrrtest_java_exception_side_effects z(MockTest.test_java_exception_side_effectcCsRt}dg}td||d}|tjtjd|j}|jtj|_|j}||j|j |j dd|j |j |d|j |j |d|j |jd|j |jd d |j |jdd |j |jgd |j |jgd |jgf|j |jg|j |jtjd|j |j|d|j |jd|j |jd|id|j |j|d|j |jjddS)N somethingchild)rDparentrL)rhzname 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)rrrZ SomethingElserhr]rZr7 reset_mockr4 _mock_namer>r?r2r3r5r8r9r: mock_callsr@)rrjrLrArhr7rrrtest_reset_mocksD       zMockTest.test_reset_mockcCst}||_|jdS)N)rr7rk)rrArrrtest_reset_mock_recursion sz"MockTest.test_reset_mock_recursioncCstj}|jdS)N)rA mock_openrk)rrrrr(test_reset_mock_on_mock_open_issue_18622sz1MockTest.test_reset_mock_on_mock_open_issue_18622cCst}|jt|jtd|}|j||d|j|tj}|j|jd|j|j dd|j|j tjfifd|j|j tjfifgdtj |_|tjtj d}|j|tj d |j|j d d |j|j tjfd tj ifd|j|j tjfiftjfd tj ifgd dS)Nz%Default return_value should be a Mockz'different result from consecutive callszcalled not setrTzcall_count incoreectzcall_args not setz(call_args_list not initialised correctly)keyzincorrect return valuerUzcall_count incorrectrrzcall_args_list not set)rr6r r7r4rkrArgr3r5r8r9Z ReturnValueZKeyArg)rrAresultZret_valrrr test_calls4    zMockTest.test_callcCst}||tj|tjd|tjtjd|j|jftjffdtjiftjfdtjifg|j|jtjfdtjif|j|jdkdS)N)kwrvza long sequence)rrrsZKwargr4r9r8r2)rrArrrtest_call_args_comparison:s   z"MockTest.test_call_args_comparisoncCsdt}||j|jt|jd|j|jt|j|dddddd|jdddddddS)NrTrUrVrWZnothing)rr )rr\r[AssertionErrorrk)rrArrrtest_assert_called_withMsz MockTest.test_assert_called_withc Csd dd}t|d}|dddd|jddd|jdddd|jt|jdddd|jt}|jd d WdQRXt|jd r|j|jjtdS) NcSsdS)Nr)rr r!r"rrrr_]sz9MockTest.test_assert_called_with_function_spec..f)rLrTrUrV)r r!)rr r!)e __cause__)N) rr\r[rxhasattr exceptionassertIsInstancer| TypeError)rr_rAcmrrr%test_assert_called_with_function_spec\s      z.MockTest.test_assert_called_with_function_speccszfdd}ttjd}||ttjd}||ttjd}||ttjd}||ttjd}||dS)NcsF|dddd|jddd|jddddjt|jdddddS)NrTrUrV)r r!)rr r!)r\r[rx)rA)rrr_checkos  z._check)rL)rrr#r%r&)rrrAr)rr#test_assert_called_with_method_specns   z,MockTest.test_assert_called_with_method_speccstj|jtjj|jtjddddjddddjdddd|jtfdddS)Nr.r,rU)rHcsjddddS)NZbobr,rU)rH)assert_called_once_withr)rArrsz7MockTest.test_assert_called_once_with..)rrr[rxrk)rr)rArtest_assert_called_once_withsz%MockTest.test_assert_called_once_withc Csddd}t|d}|dddd|jddd|jdddd|jt|jdddd|jt}|jd d WdQRXt|jd r|j|jjt|d d d|jt|jddd|jt|jd d ddS)NcSsdS)Nr)rr r!r"rrrr_sz>MockTest.test_assert_called_once_with_function_spec..f)rLrTrUrV)r r!)rr r!rz)r{r|r+)N) rrr[rxr}r~rr|r)rr_rArrrr*test_assert_called_once_with_function_specs           z3MockTest.test_assert_called_once_with_function_speccCsbt}|j}|jt|td|j|j|dt}d|j_|j|jdd|j|jjddS)Nzattribute isn't a mockz+different attributes returned for same namerVzmethod returned wrong valuez!method didn't record being called)rrhr6r r4r7r3)rrArhrrr#test_attribute_access_returns_mockss  z,MockTest.test_attribute_access_returns_mockscCs0t}|j}|j|jdd|j|j|ddS)Nrhz attribute name not set correctlyz"attribute parent not set correctly)rrhr4rlr>)rrArhrrr(test_attributes_have_name_and_parent_sets   z1MockTest.test_attributes_have_name_and_parent_setcCstt}|jddd|jjdtjd|j|jjdd dtjifgd|j|jdd ddifd d dtjifgddS) NrV)rWr+)cakerhrz#method calls not recorded correctlyrWzsomething_else.something)r+)rV)r+)rrhsomething_elserZCaker4r:)rrArrrtest_method_calls_recordeds  z#MockTest.test_method_calls_recordedcCst}|j|j|jd g|j|jdfifgt}|jd|j|jd g|j|jdd ifgt}|jdd|j|jdddifg|j|jdfddifgt}|jddd|j|jdd ddifgdS)Nrh differentrT)xrZmore)somer)rhr)rhr)r)r)rrhr4r:)rrArrr test_method_calls_compare_easilys"  z)MockTest.test_method_calls_compare_easilycCsLxFdgdfD]8}x2dD]*}tf||i}|j|jtdt|dqWq WdS)NrhrLrMz-Mock object has no attribute 'something_else'r)rh)rLrM)rrhrbAttributeErrorgetattr)rrLargrArrrtest_only_allowed_methods_exists z(MockTest.test_only_allowed_methods_existcs>Gdddt}fdd}|t|d|t|ddS)Nc@seZdZdZdZddZdS)z*MockTest.test_from_spec..SomethingrVNcSsdS)Nr)rrrrysz,MockTest.test_from_spec..Something.y)rrrr __something__rrrrrrsrcs:|j|j|jjtdt|djtdt|ddS)Nz Mock object has no attribute 'z'zz)Mock object has no attribute '__foobar__'Z __foobar__)rrrrbrr)rA)rrrtest_attributess z0MockTest.test_from_spec..test_attributes)rL)rNr)rrrr)rrtest_from_specs zMockTest.test_from_speccCsJt}t|d}|j|||j|dddd|jdddddS)N)wrapsrTrUrV)rW)rr4rkr\)rrealrArrrtest_wraps_callss  zMockTest.test_wraps_callscCs4t}t|d}d|_|j|d|j|jdS)N)rrV)rr7r4r2r3)rrrArrr,test_wraps_call_with_nondefault_return_value(s  z5MockTest.test_wraps_call_with_nondefault_return_valuecsGdddt}|}t|d|jj|j|jtfdd|jj|jjjdddd }|jjjdddd |j||jjdS) Nc@seZdZeZdS)z,MockTest.test_wraps_attributes..RealN)rrrrr-rrrrReal3sr)rcsjS)N)rWr)rArrr:sz0MockTest.test_wraps_attributes..rTrUrV)rW) rNrr4r-r[rZassertNotEqualZfrogr\)rrrrtr)rArtest_wraps_attributes2s zMockTest.test_wraps_attributescCs4ttd}|jt|ttdd}|jt|dS)N)rZr.)rrr[)rrArrrtest_exceptional_side_effectBs  z%MockTest.test_exceptional_side_effectcCs4ttd}|jt|ttdd}|jt|dS)N)rZr.)rKeyboardInterruptr[)rrArrr test_baseexceptional_side_effectJs  z)MockTest.test_baseexceptional_side_effectcCst}|jtd|jdS)Nz Not called)rrbrxr\)rrArrrtest_assert_called_with_messageRsz(MockTest.test_assert_called_with_messagecCstdd}|jtd|jdS)NZgeoffrey)rDz'Expected 'geoffrey' to be called once\.)rrbrxr)rrArrr$test_assert_called_once_with_messageXs z-MockTest.test_assert_called_once_with_messagecs2t|jtfddd_|jjddS)NcsjS)N)rr)rArrrasz'MockTest.test__name__..r.)rr[rrr4)rr)rAr test__name___szMockTest.test__name__cCsJGdddt}t|dgd}|jd|jjd|jtt|ddS)Nc@s eZdZdS)z-MockTest.test_spec_list_subclass..SubN)rrrrrrrSubhsrr.)rLrV)listrappendr\r[rr)rrrArrrtest_spec_list_subclassgs   z MockTest.test_spec_list_subclasscCsGdddt}t|d}|j||t|d}|j|||j|j||jtjjdt|d}|j||t|d}|j||dS)Nc@s eZdZdS)z#MockTest.test_spec_class..XN)rrrrrrrrKrsrK)rLr)rM)rNrrassertIs __class__r4r)rrKrArrrtest_spec_classqs       zMockTest.test_spec_classcsLGdddt}t|dd_t|dfdd}d_|jt|dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set..XrVN)rrrrrrrrrKsrK)rLr.)rMcs d_dS)Nr.)rr)rArrset_attrsz?MockTest.test_setting_attribute_with_spec_set..set_attr)rNrrrr[r)rrKrr)rAr$test_setting_attribute_with_spec_sets   z-MockTest.test_setting_attribute_with_spec_setcCs4tj}|jtj|tjtdtjtdS)NgeA)sysgetrecursionlimit addCleanupsetrecursionlimitintcopyr)rcurrentrrr test_copyszMockTest.test_copyz no old style classes in Python 3cs\Gddd}t|dd_|jtfddt|dd_|jtfdddS)Nc@seZdZdZdS)z1MockTest.test_spec_old_style_classes..FooN)rrrr,rrrrFoosr)rLr+csjS)N)r.r)rArrrsz6MockTest.test_spec_old_style_classes..csjS)N)r.r)rArrrs)rr,r[r)rrr)rArtest_spec_old_style_classess  z$MockTest.test_spec_old_style_classescsGddd}t|dd_|jtfddfdd}|jt|t|dd_|jtfd dfd d}|jt|dS) Nc@seZdZdZdS)z5MockTest.test_spec_set_old_style_classes..FoorN)rrrr,rrrrrsr)rMr+csjS)N)r.r)rArrrsz:MockTest.test_spec_set_old_style_classes..cs d_dS)NrV)r.r)rArr_setsz6MockTest.test_spec_set_old_style_classes.._setcsjS)N)r.r)rArrrscs d_dS)NrV)r.r)rArrrs)rr,r[r)rrrr)rArtest_spec_set_old_style_classess     z(MockTest.test_spec_set_old_style_classescs\Gdddt}||d|jjdfdd}|jt|fdd}|jt|dS)Nc@s&eZdZddZddZeeeZdS)z8MockTest.test_subclass_with_properties..SubClasscSsdS)NrVr)rrrr_getsz=MockTest.test_subclass_with_properties..SubClass._getcSs tddS)Nz strange error) NameError)rvaluerrrrsz=MockTest.test_subclass_with_properties..SubClass._setN)rrrrrpropertysome_attributerrrrSubClasssr)rMrVcs d_dS)NrV)rr)srrtestsz4MockTest.test_subclass_with_properties..testcs d_dS)Nr,)r.r)rrrrs)rr4rr[rr)rrrr)rrtest_subclass_with_propertiess    z&MockTest.test_subclass_with_propertiescCs>t}dd}|t|_|d|jd|jt|dddS)NcSs |j|S)N)Z _mock_call)rrrrr__call__sz,MockTest.test_setting_call..__call__onetwo)rtyperr\r[r)rrArrrrtest_setting_calls   zMockTest.test_setting_callcCst}tt|}tddttD}|jt|||j|jf|jdt||jdt|d|_|_|jdt||jdt|dd|_ |jd t|dS) NcSsg|]}|jds|qS)_) startswith).0mrrr sz%MockTest.test_dir..rr r!r"cSstgS)N)r)rrrrrsz#MockTest.test_dir..r) rsetdirr4rr rEr!r"r)rrAattrs type_attrsrrrtest_dirs    zMockTest.test_dircCsXttjd}tttj}tt|}|jt||d|_|jt|jdddS)N)rLrVversionrT)runittestTestCaserrr4rcount)rrAZtestcase_attrsrrrrtest_dir_from_specs   zMockTest.test_dir_from_specc CsVtjtdd}|jz0ttt}ttt}|jt||Wd|jXdS)NZ FILTER_DIRF) rrNrAstartrrrr4stop)rZpatcherrrrrrtest_filter_dirs zMockTest.test_filter_dircCstdd}|j|jdtdd}|j|jdtdtd}tf|}|jt||j|jjd|j|jtt}|jf||jt||j|jjd|j|jtdS)Nr,)r.!)rZzfoo.bar.return_valuer.) rr4r.rKeyErrorr[r,rZconfigure_mock)rrArRrrrtest_configure_mocks       zMockTest.test_configure_mockc Os\y|||Wn$tjd}|j||YnX|jd|ft|}|j||dS)NrTzException %r not raised)rexc_inforrfstrr4)rr~messagefuncrQrRinstancemsgrrrassertRaisesWithMsg(s zMockTest.assertRaisesWithMsgc Cs(t}d}d}|jt||f|jddddd|jddddd|jj|jjg}x8|D]0}d }d }d }|jt|||f|dddddqVWx2|D]*}d }d }d }|jt|||f|ddqWx4|D],}d }d }d }|jt|||f|dddqWx.|D]&}d }d}d }|jt|||f|qWdS)Nzmock(1, '2', 3, bar='foo')zExpected call: %s Not calledrT2rVr.)r,)r.zfoo(1, '2', 3, foo='foo')zfoo(1, '2', 3, bar='foo')z!Expected call: %s Actual call: %szfoo(bar='foo')z foo(1, 2, 3)rUzfoo())rrrxr\r.r)rrAexpectedrZ assertersr#actualrrr'test_assert_called_with_failure_message6sF        z0MockTest.test_assert_called_with_failure_messagecCst}|j|jgkdt}|dfifg}|j|j||j|jtj|j|j||j|jjdfifgt}|jdddddddfifd dtdddfg}|j|j||j|jjjddtdddfg|j|jjd dtdddfgt}|jj j dfifd fifd fifg}|j|j||j|jtjj j j x:ttd dfD]$}tf|}t |jdfifg}|j|j|tf|}|j dfifdfifg}|j|j||j|j jtgtf|}|ddd|j|jtdddj |j|jtddj |j|jtdj tf|}|dddj jjd|j|jtdddj jjdj |j|jtddj jjdj |j|jtdj jjdj tf|}t |jj j dfif}|j|jd||j|jtjj j jj |j|jj jtj jj |j|jj j jtjj qtWdS)NTrTrUrVrr)rr z().foor.z ().foo.barz().foo.bar().bazr,)rDz foo.__int__rza()z().foo.bar().baz().__int__)rTrUrV)rTrUrV)rTrUrV)rrrmr4r.rrdictr7r,rH call_listrrr r!__int__)rrArrRZ last_callrrrtest_mock_callsmst                  zMockTest.test_mock_callscCshGdddt}|}|j|j||j||Gdddt}|}|j|j||j||dS)Nc@s eZdZdS)z+MockTest.test_subclassing..SubclassN)rrrrrrrr)sr)c@seZdZddZdS)z+MockTest.test_subclassing..Subclassc[s tf|S)N)r)rrRrrr_get_child_mocksz;MockTest.test_subclassing..Subclass._get_child_mockN)rrrrrrrrr)s)rrr.assertNotIsInstance)rr)rArrrtest_subclassingszMockTest.test_subclassingcsttttg}fdd}x|D]z}||t|rd||dd|dd|j|||j|jjddd|jdjjd|j||q&WdS)NcsDd}x:|D]2}t||}j|tj|tj|gq WdS)Nr9r:rm)r9r:rm)rrr rr4)rAnamesrDattr)rrr assert_attrss     z-MockTest.test_arg_lists..assert_attrsrTrUrV)r) rrrr r rkr.r,rH)rrIrrAr)rrtest_arg_listss$    zMockTest.test_arg_listscCst}|ddd|ddd|jt|jd|j\}}|j|d|j|tddd tddfd tddfg}xPt||jD]@\}}|jt|d|j|d|d|j|d|dqWdS) NrTrV)rrUr)r r)rU)rT)rU)rr4lenr8rzipr9)rrArQrRZ expected_listrr8rrrtest_call_args_two_tuples    z!MockTest.test_call_args_two_tuplecCsttdddgd}|j|||gdddg|jt|tdddgd}|j|||gdddg|jt|tdd}|j|||gd d d g|jt|Gd d d t}t|d}|j||ttd}|j||||gddddg|jt|dS)NrTrUrV)rZrr r!Zghighic@s eZdZdS)z/MockTest.test_side_effect_iterator..FooN)rrrrrrrr srrrrr) rrr4r[ StopIterationrrNrr)rrArrrrtest_side_effect_iterators       z"MockTest.test_side_effect_iteratorcCst}tdddg|_|j|||gdddg|jt||j}|j|ttgdddg|_|j|||gdddg|jt||j}|j|ttgt}||_|j||||gddd d g|jt||j |j|dS) NrTrUrVrr r!rrrr) rrrZr4r[rrrrr)rrArZZ this_iterrrr!test_side_effect_setting_iterators"    z*MockTest.test_side_effect_setting_iteratorcCs`xZttfD]N}tdtdf}||d}|jt||j|d|jt||j|dq WdS)NrVr+)rZ)rrrarr[r4)rKlassiterablerrrr$test_side_effect_iterator_exceptions.s    z-MockTest.test_side_effect_iterator_exceptionscCs4tdd}tdtg|_|j||gddgdS)NrU)r7rT)rrrrZr4)rrArrr!test_side_effect_iterator_default8s z*MockTest.test_side_effect_iterator_defaultc Cst}|dd|dd|dd|dd|ddtddddifdfddifdd ddifd difd fddifg}x|D]}|j|gd d q~WxWq(WdS)NrTrUrrVrr+)r rr )r)r.rVr)r)rT)rTrUrV)rr.r,extendZspamrHrZbamrrWrrrrangerr r[rxrreversed) rZkalls1Zkalls2rIrAr rstepZtheserrrtest_assert_has_callsis< "        zMockTest.test_assert_has_callscCsddd}t|d}|dddd|dd d d d |d dddddifdddd ifdifg}|j||j|dd|j|dd|j|dddd|j|dd|j|ddddtt|}|jt|j|WdQRX|j|dd|jt|j|ddWdQRX|j|dddd|jt|j|ddWdQRX|j|dddddS)NcSsdS)Nr)rr r!r"rrrr_sz.f)rLrTrUrV)r r!rrr+r)r!r" )r!rr"T)r)N)rTrUrV)rrr+)rrrrrrr)rr rrr[rx)rr_rAZcallsrrr(test_assert_has_calls_with_function_specs0         z1MockTest.test_assert_has_calls_with_function_speccCst}|dd|dd|ddd|jdd|jdd|jddd|jt|j|jt|jdd|jt|jdddS)NrTrUrV)rr+)r r)rassert_any_callr[rx)rrArrrtest_assert_any_calls$     zMockTest.test_assert_any_callc Csddd}t|d}|dddd|dd d d d |jddd|jdddd |jdd d d |jdd d d d|jt|jdddd|jt}|jddWdQRXt|jdr|j|jjtdS)NcSsdS)Nr)rr r!r"rrrr_sz;MockTest.test_assert_any_call_with_function_spec..f)rLrTrUrV)r r!rrr+r)r!r")rr r!)rr r!r"rz)r{r|)N) rrr[rxr}r~rr|r)rr_rArrrr'test_assert_any_call_with_function_specs      z0MockTest.test_assert_any_call_with_function_speccCsjdd}t}||_t|t|jg}x>|D]6}|dd|dd|j|jtddtddgq,WdS)NcSsdS)Nr)rr rrrr_sz3MockTest.test_mock_calls_create_autospec..frTrUrVr)rr_r r4rmr)rr_objfuncsrrrrtest_mock_calls_create_autospecs    z(MockTest.test_mock_calls_create_autospeccCs$tjtdd}|jdt|dS)NZ sweet_func)rD)rAr rNrErF)rrrrrtest_create_autospec_with_namesz'MockTest.test_create_autospec_with_namecCs`t}|jt|jWdQRX|jt|jWdQRXtdd}|j|jdS)NT)Zunsafe)rr[rZassert_foo_callZassret_foo_call)rrrrrtest_mock_unsafes   zMockTest.test_mock_unsafec Cs<t}|jj|j|jt|jjWdQRXdS)N)rhelloZassert_not_calledr[rx)rrrrrtest_assert_not_calleds   zMockTest.test_assert_not_calledc CsNt}|jt|jjWdQRX|j|jj|j|jjdS)N)rr[rxr Z assert_called)rrrrrtest_assert_called s  zMockTest.test_assert_calledcCsdt}|jt|jjWdQRX|j|jj|j|jt|jjWdQRXdS)N)rr[rxr Zassert_called_once)rrrrrtest_assert_called_onces   z MockTest.test_assert_called_oncecCs0t}|jdddd}|jt|jj|dS)Nr Zhero)rDZdaddyz call(daddy='hero', name='hello'))rr r4rFr8)rrtextrrrtest_sorted_call_signature!sz#MockTest.test_sorted_call_signaturecCsVtj}tjdd}t}|j|jdd|j|jd||j|jd|dS)Nr rrT)rrindexrr4r:)rr!rrrrrtest_override_tuple_methods(s  z$MockTest.test_override_tuple_methodsc sGdddt}Gdddt}Gdddtttttg}x._OnerTN)rrrrrrrr_One2sr)c@seZdZdZdS)z)MockTest.test_mock_add_spec.._TworUN)rrrrrrrr_Two4sr*c@seZdZdZZZdS)z-MockTest.test_mock_add_spec..AnythingZfourN)rrrrrthreerrrrAnything6sr,cs |dS)N)rLr)K)r,rrr=sz-MockTest.test_mock_add_spec..cs |dS)N)rMr)r-)r,rrr>sT)rMrrr+rM)rNrrrr rrrrrr+ mock_add_specr[rrsetattr) rr)r*ZklassesrrRrAZOneZTwor)r,rtest_mock_add_spec1s>      zMockTest.test_mock_add_speccsxzttfD]n}|tjt|jtt|ddj_jt|j td|jtfddq WdS)Nr.rcsdS)Nr.rr)rArrrtsz;MockTest.test_mock_add_spec_magic_methods..) rr rr.rNr[rrr7r4)rrr)rAr test_mock_add_spec_magic_methodsfs  z)MockTest.test_mock_add_spec_magic_methodscCsxttttfD]}|}t|_|j|j|jtjg|j|jtjg|}tdd|_ |j |j|jg|j|jg|}t|_ |j |j|jg|j|jgqWdS)NrD)rD) rrrr r.r4r:rrmr,rH)rrrArrrtest_adding_child_mockws   zMockTest.test_adding_child_mockcCsDx>ttfD]2}|}t|_||j|jttgq WdS)N)rrr7r4rmr)rrrArrrtest_adding_return_value_mocks z&MockTest.test_adding_return_value_mockcCsGdddt}t}tj|d}tj|d}|j}|j|j|j}|j|j|j|d|j|d|j|j|j |j t jt jgdS)Nc@seZdZdZdZdS)z'MockTest.test_manager_mock..FoorrN)rrrrrrrrrrsrrr) rNrrrrr attach_mockrrr4rmr)rrmanagerp1p2Zmock_oneZmock_tworrrtest_manager_mocks      zMockTest.test_manager_mockcCslxfttfD]Z}|}tdd|_tdd|_t|t||j|jtjtjg|j|j gq WdS)NrV)r7g@) rrr __float__rfloatr4rmrr:)rrrrrrtest_magic_methods_mock_callss  z&MockTest.test_magic_methods_mock_callscCs<tjdd}|d}|j}|d}|j}|j||dS)Ndata) read_dataza-namez another-name)rArpreadr4)rZ mocked_openf1Zf1_dataf2Zf2_datarrr test_mock_open_reuse_issue_21750s  z)MockTest.test_mock_open_reuse_issue_21750c CsXtjtjdd}tjd|0|j}|j}td|_dd}|jt|WdQRXdS)NZJLV)rDztempfile.NamedTemporaryFilez Test 2 ErrorcSstjjddS)Nasd)tempfileNamedTemporaryFilewriterrrrattemptsz.MockTest.test_mock_open_write..attempt) rArprrr7rEOSErrorrZr[)rZmock_namedtempZmock_filehandleZ mock_writerFrrrtest_mock_open_writes zMockTest.test_mock_open_writecCsJtjdd}dd|jj_|j}|j}|jd||jd|dS)Nzfoo barn)r=cWsdS)Nabcr)rQrrrrsz8MockTest.test_mock_open_alter_readline..rI)rArpr7readlinerZr4)rZmopenfirstsecondrrrtest_mock_open_alter_readlines     z&MockTest.test_mock_open_alter_readlinecCsxttfD]}|}t|}||_|j|||jt|||j|j|||jt|||}|j|_|j dt|j|j dt|j|j|j dt|j|j dt|j|}t|}||_||j_|jt|||jt|j|q WdS)Nz name='mock.a') rrrFr7rr4rkrr rE)rrrZ original_reprrrrtest_mock_parentss,zMockTest.test_mock_parentscCsttttf}x|D]}x|D]z}|}|dd}|j|d|j|j||jdt||jj d|j |j t jj dg|j |j t jj dgqWqWdS)Nr.)rDr,zname='mock.bar'rT)rrr rr4rr,rErFrHr4rmrr:)rclassesrKlass2rm2rrrtest_attach_mocks      zMockTest.test_attach_mockcCsttttf}xxttfD]l}xf|D]^}|}|dd}|j|d|j|||jdt||j|j |j t jj q WqWdS)Nr.)rDr7z name='mock()') rrr rr4rrErFr.r4rmrr)rrOrrPrrQrrrtest_attach_mock_return_values    z&MockTest.test_attach_mock_return_valuecCsjxdttttfD]L}|jt|d|`|jt|d|`|jt|d|j t t |dqWdS)Nrr_) rrr rr6r}rr2r_r[rr)rrArrrtest_attribute_deletions z MockTest.test_attribute_deletioncCs>x8ttfD](}|j|tt|_|j|t|jqWdS)N)rrrrrrr.)rrArrrtest_class_assignables   zMockTest.test_class_assignablecCsxttttfD]}|ddd}|jdddtj|}tj|}|jjddd|j |j |j t |||j |t|jdt||j|jdqWdS)Nr.rV)rDr-rTrUz name="foo")rrr)r r.pickledumpsloadsrr2r3r6r rr*rErFr4r-)rrrAr<newrrr test_pickle(s     zMockTest.test_pickleN)^rrrr1rBrCrJrOr^r`rcrZ skipUnlessrplatformrgrnrorqrurwryrrrrrrrrrrrrrrrrrrrrrrZskipIfsixPY3rrrrrrrrrrrrrrrrrrr rrrrrrrr!r"r#r%r(r0r1r2r3r8r;rArHrMrNrRrSrTrUZexpectedFailurerZrrrrr/Ds )"        7N# ,(!    5     r/__main__)#rrVrrCr\Z unittest2rrArrrrrrrr r Z mock.mockr Zmock.tests.supportr r runicoderrrNrrr)r*rr/rmainrrrrs@,