3 \7@sFdZd ZddlZddlZddlZddlZddlmZddlm Z m Z dde eDZ e fZdejkrzddlZe ejjfZdZeZddZddZddZdddZdd Zd!d"Zd#d$Zd%d&Zdd'd(Zd)d*Zd+d,Z Gd-d.d.e!Z"Gd/d0d0e!Z#e#Z$e$j%Z%e$j&Z'e$j(Z)d1d2Z*d3d4d5d6d7d8d9d:hZ+d;d<Z,Gd=d>d>e-Z.d?d@Z/GdAdBdBe!Z0GdCdDdDe!Z1GdEd d e1Z2dFdGZ3GdHdIdIe1Z4GdJdde4e2Z5dKdLZ6dMdNZ7dOdPZ8GdQdRdRe!Z9dSdTZ:e%dddddfdUdVZ;ddWdXZd\d]Z?d^d_Z@e;e=_!e>e=_Ae#srjavaTcCstt|tS)N) issubclasstyper )objrrr_is_instance_mock2srcCst|tpt|tot|tS)N) isinstanceBaseExceptionsrr)rrrr _is_exception8s r cCst|tr6| r6y |j}Wntk r.dSXd}n*t|ts`y |j}Wntk r^dSX|rpt|d}n|}y|tj|fSt k rdSXdS)NT) rr__init__AttributeError FunctionTypes__call__rinspectZ signature ValueError)funcZ as_instanceZeat_selfZsig_funcrrr_get_signature_object?s$    r(FcsDt|||dkrdS\}fdd}t|||t|_dS)Ncsj||dS)N)bind) _mock_selfargskwargs)sigrrchecksigdsz"_check_signature..checksig)r(_copy_func_detailsr_mock_check_sig)r'mock skipfirstinstancer.r)r-r_check_signature_s   r4c#Cs|j|_|j|_y |j|_Wntk r0YnXy |j|_Wntk rRYnXy |j|_Wntk rtYnXy |j|_Wntk rYnXdS)N)__name____doc____text_signature__r" __module__ __defaults____kwdefaults__)r'funcopyrrrr/js$    r/cCs&t|trdSt|dddk r"dSdS)NTr$F)rrgetattr)rrrr _callables  r=cCst|ttfkS)N)rlisttuple)rrrr_is_listsr@cCsHt|tst|dddk Sx(|f|jD]}|jjddk r(dSq(WdS)Nr$TF)rrr<__mro____dict__get)rbaserrr_instance_callables  rEc st|s dSt|t}t|||}|dkr.|S|\}fdd}t|||j}|js^d}||d}d|} t| |||} t| || S)Ncsj||dS)N)r))r+r,)r-rrr.sz _set_signature..checksigr;)Z _checksig_r1zYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs)) r=rrr(r/r5 isidentifierexec _setup_func) r1originalr3r2resultr'r.rcontextsrcr;r)r-r_set_signatures$       rMc s_tsdSfdd}fdd}fdd}fdd}fd d }fd d }fd d}fdd} d_d_d_t_t_t_j _ j _ j _ |_ |_ |_|_| _|_|_|__dS)Ncs j||S)N)assert_called_with)r+r,)r1rrrNsz'_setup_func..assert_called_withcs j||S)N) assert_called)r+r,)r1rrrOsz"_setup_func..assert_calledcs j||S)N)assert_not_called)r+r,)r1rrrPsz&_setup_func..assert_not_calledcs j||S)N)assert_called_once)r+r,)r1rrrQsz'_setup_func..assert_called_oncecs j||S)N)assert_called_once_with)r+r,)r1rrrRsz,_setup_func..assert_called_once_withcs j||S)N)assert_has_calls)r+r,)r1rrrSsz%_setup_func..assert_has_callscs j||S)N)assert_any_call)r+r,)r1rrrTsz$_setup_func..assert_any_callcs:t_t_jj}t|r6|k r6|jdS)N) _CallList method_calls mock_calls reset_mock return_valuer)ret)r;r1rrrXs z_setup_func..reset_mockFr)r1rcalled call_count call_argsrUcall_args_listrVrWrY side_effect_mock_childrenrNrRrSrTrXrOrPrQ_mock_delegate) r;r1rNrOrPrQrRrSrTrXr)r;r1rrHs:       rHcCsd|dd|kS)Nz__%s__r)rrrr _is_magicsrdc@seZdZddZddZdS)_SentinelObjectcCs ||_dS)N)r)selfrrrrr!sz_SentinelObject.__init__cCs d|jS)Nz sentinel.%s)r)rfrrr__repr__sz_SentinelObject.__repr__N)r5r8 __qualname__r!rgrrrrresrec@seZdZddZddZdS) _SentinelcCs i|_dS)N) _sentinels)rfrrrr!sz_Sentinel.__init__cCs|dkr t|jj|t|S)N __bases__)r"rj setdefaultre)rfrrrr __getattr__sz_Sentinel.__getattr__N)r5r8rhr!rmrrrrrisricCs$t|ttttfkr t||S|S)N)rdictr>r?set)valuerrr_copys rqrY_mock_return_valuer__mock_side_effect _mock_parent_mock_new_parent _mock_name_mock_new_namecCs8tj|d|}||fdd}||fdd}t||S)NZ_mock_cSs"|j}|dkrt||St||S)N)rar<)rfr _the_namer-rrr_gets z"_delegating_property.._getcSs*|j}|dkr||j|<n t|||dS)N)rarBsetattr)rfrprrxr-rrr_set$s z"_delegating_property.._set)_allowed_namesaddproperty)rrxryr{rrr_delegating_propertys  rc@seZdZddZddZdS)rUcCsnt|tstj||St|}t|}||kr2dSx6td||dD] }||||}||krFdSqFWdS)NFrT)rr> __contains__lenrange)rfrpZ len_valueZlen_selfiZsub_listrrrr1s  z_CallList.__contains__cCstjt|S)N)pprintZpformatr>)rfrrrrg?sz_CallList.__repr__N)r5r8rhrrgrrrrrU/srUcCsxt|s dS|js,|js,|jdk s,|jdk r0dS|}x|dk rR||krJdS|j}q6W|rd||_||_|rt||_||_dS)NFT)rrvrwrtru)parentrprnew_name_parentrrr_check_and_set_parentCs$     rc@s$eZdZddZddZddZdS) _MockItercCst||_dS)N)iterr)rfrrrrr!]sz_MockIter.__init__cCs|S)Nr)rfrrr__iter___sz_MockIter.__iter__cCs t|jS)N)nextr)rfrrr__next__asz_MockIter.__next__N)r5r8rhr!rrrrrrr\src@seZdZeZdZddZdS)BaseNcOsdS)Nr)rfr+r,rrrr!gsz Base.__init__)r5r8rhrrrrsr!rrrrrdsrc @sDeZdZddZdCddZdd ZdDd d ZdEd d ZddZddZ dZ e ee e Z e ddZ edZedZedZedZedZddZddZe eeZdFddddd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Z d3d4Z!d5d6Z"d7d8Z#d9d:Z$d;d<Z%dGd=d>Z&d?d@Z'dAdBZ(dS)Hr cOs$t|j|fd|ji}tj|}|S)Nr6)rr5r6object__new__)clsr+kwnewr3rrrros zNonCallableMock.__new__NFc Ks|dkr |}|j} || d<|| d<|| d<|| d<|dk rB|}d}| dkrR|dk } |j||| | i| d<|| d<d| d<d | d <d| d <d | d <t| d<t| d<t| d<| | d<| r|jf| tt|j||||||dS)NrtrvrwruTr` _mock_wrapsraFZ _mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrV _mock_unsafe)rB_mock_add_specrUconfigure_mock _safe_superr r!)rfspecrrspec_setr _spec_state _new_name _new_parent_spec_as_instance _eat_selfZunsafer,rBrrrr!xs8      zNonCallableMock.__init__cCs(d|_d|_d|_d|_t|||dS)Nr)rtrurvrwrz)rfr1 attributerrr attach_mocks zNonCallableMock.attach_mockcCs|j||dS)N)r)rfrrrrr mock_add_specszNonCallableMock.mock_add_specc Cs|d}d}|dk rRt| rRt|tr*|}nt|}t|||}|oH|d}t|}|j}||d<||d<||d<||d<dS)Nr _spec_class _spec_set_spec_signature _mock_methods)r@rr _get_classr(dirrB) rfrrrrrrresrBrrrrs  zNonCallableMock._mock_add_speccCs8|j}|jdk r|jj}|tkr4|j|dd}||_|S)Nz())rr)rrrarYr_get_child_mock)rfrZrrrZ__get_return_values  z"NonCallableMock.__get_return_valuecCs,|jdk r||j_n||_t||dddS)Nz())rarYrrr)rfrprrrZ__set_return_values  z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs|jdkrt|S|jS)N)rr)rfrrr __class__s zNonCallableMock.__class__r[r\r]r^rWcCsT|j}|dkr|jS|j}|dk rPt| rPt|t rPt| rPt|}||_|S)N)rarsr_callablerrr )rf delegatedZsfrrrZ__get_side_effectsz!NonCallableMock.__get_side_effectcCs(t|}|j}|dkr||_n||_dS)N) _try_iterrarsr_)rfrprrrrZ__set_side_effects z!NonCallableMock.__set_side_effect)rYr_cCs|dkr g}t||krdS|jt|d|_d|_d|_t|_t|_t|_|r^t |_ |rhd|_ x0|j j D]"}t|tst|tkrqt|j|qtW|j }t|r||k r|j|dS)NFr)idappendr[r]r\rUrWr^rVrrrrsr`valuesr _SpecState_deletedrXr)rfZvisitedrYr_ZchildrZrrrrX s, zNonCallableMock.reset_mockcKs`xZt|jdddD]B\}}|jd}|j}|}x|D]}t||}q:Wt|||qWdS)NcSs|djdS)Nr.)count)entryrrr8sz0NonCallableMock.configure_mock..)keyr)sorteditemssplitpopr<rz)rfr,argvalr+finalrrrrrr+s   zNonCallableMock.configure_mockcCs|dkrt|n:|jdk r<||jks.|tkrLtd|nt|rLt||jsd|jdrdt||jj|}|tkrt|np|dkrd}|j dk rt |j |}|j |||||d}||j|<n.t |t rt|j|j|j|j|j}||j|<|S) NrrzMock object has no attribute %rassertassret)rrrrr>rr)rr)r"r _all_magicsrdrrr`rCrrr<rrrrrrr3rr)rfrrJrrrrrmAs6            zNonCallableMock.__getattr__c Cs"|jg}|j}|}d}|dgkr$d}t}xT|dk r~|}|j|j|d}|jdkrZd}|j}t||krnP|jt|q,Wtt|}|jpd}t |dkr|dd kr|d7}||d<dj |}d}|dkrd |}d} |j dk rd } |j rd } | |j j } d t|j || t|fS)Nr()rr1r().rmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)rr)r1r)rwrurorrr}r>reversedrvrjoinrrr5r) rfZ _name_listrZlastdotseenZ_firstrZ name_stringZ spec_stringrrrrggsL           zNonCallableMock.__repr__cCshtstj|S|jpg}tt|}t|j}dd|D}dd|D}tt |||t|j S)NcSsg|]}|jds|qS)r)r)rerrr sz+NonCallableMock.__dir__..cSs$g|]}|jd st|r|qS)r)rrd)rrrrrrs) r r__dir__rrrr>rBrror`)rfZextrasZ from_typeZ from_dictrrrrs    zNonCallableMock.__dir__cs"|tkrtj||SjrHjdk rH|jkrH|jkrHtd|n|tkrbd|}t|n|tkrjdk r|jkrtd|t |st t |t |||fdd}n(t |d|t t |||j|<n.|dkr|_dSt |||r|j|<tj||S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.csf||S)Nr)r+r)rIrfrrrsz-NonCallableMock.__setattr__..r)r|r __setattr__rrrBr"_unsupported_magicsrrrzr _get_methodrr`r)rfrrpmsgr)rIrfrrs2       zNonCallableMock.__setattr__cCs|tkr2|t|jkr2tt||||jkr2dS||jkrHtj|||jj|t}|t krft ||tk rv|j|=t |j|<dS)N) rrrBdelattrr __delattr__r`rC_missingrr")rfrrrrrrs   zNonCallableMock.__delattr__cCs|jpd}t|||S)Nr1)rv_format_call_signature)rfr+r,rrrr_format_mock_call_signatures z+NonCallableMock._format_mock_call_signaturecCsDd}|j||}|j}t|dkr.|dd}|j|}|||fS)Nz!Expected call: %s Actual call: %sr)rr]r)rfr+r,messageexpected_stringr]Z actual_stringrrr_format_mock_failure_messages    z,NonCallableMock._format_mock_failure_messagecCst|j}|dk rlt|dkr(d}|\}}n |\}}}y||j||fStk rh}z |jdSd}~XqpXn|SdS)Nrbr)rrr) TypeErrorwith_traceback)rf_callr-rr+r,rrrr _call_matchers   zNonCallableMock._call_matchercCs.|}|jdkr*d|jpd|jf}t|dS)Nrz7Expected '%s' to not have been called. Called %s times.r1)r\rvAssertionError)r*rfrrrrrPs  z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|dS)Nrz"Expected '%s' to have been called.r1)r\rvr)r*rfrrrrrO s   zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|dS)Nrz8Expected '%s' to have been called once. Called %s times.r1)r\rvr)r*rfrrrrrQs  z"NonCallableMock.assert_called_oncecs||jdkr(j}td|ffdd}jf}jj}||krxt|trh|nd}t||dS)NzExpected call: %s Not calledcsj}|S)N)r)r)r+r,rfrr_error_message's z:NonCallableMock.assert_called_with.._error_message)r]rrrr Exception)r*r+r,expectedractualcauser)r+r,rfrrNs   z"NonCallableMock.assert_called_withcOs6|}|jdks*d|jpd|jf}t||j||S)Nrz1Expected '%s' to be called once. Called %s times.r1)r\rvrrN)r*r+r,rfrrrrrR1s  z'NonCallableMock.assert_called_once_withc sfdd|D}t|tr |nd}tfddjD}|sd||kr`tdt|jf|dSt|}g}x:|D]2}y|j|Wqvtk r|j|YqvXqvW|rtdt |f|dS)Ncsg|]}j|qSr)r)rc)rfrrrFsz4NonCallableMock.assert_has_calls..c3s|]}j|VqdS)N)r)rr)rfrr Hsz3NonCallableMock.assert_has_calls..z(Calls not found. Expected: %r Actual: %rz%r not all found in call list) rrrUrWrr>remover&rr?)rfZcallsZ any_orderrrZ all_callsZ not_foundZkallr)rfrrS<s*  z NonCallableMock.assert_has_callscsZj||f}fddjD}||krVt|tr8|nd}j||}td||dS)Ncsg|]}j|qSr)r)rr)rfrrrfsz3NonCallableMock.assert_any_call..z%s call not found)rr^rrrr)rfr+r,rrrrr)rfrrT_s zNonCallableMock.assert_any_callcKsFt|}t|ts2t|tr"t}q.) rrrrrrrrrr,attribute_namer)rfrrrrrisz _patch.copycCst|tr|j|S|j|S)N)rrdecorate_classdecorate_callable)rfr'rrrr$vs  z_patch.__call__cCsRxLt|D]@}|jtjsq t||}t|ds2q |j}t||||q W|S)Nr$)rrr TEST_PREFIXr<rrrz)rfrattr attr_valuerrrrr|s   z_patch.decorate_classcs<tdrjj|Stfdd|g_S)N patchingscsg}g}t}zybxJjD]@}|j}|j||jdk rF|j|q|jtkr|j|qW|t|7}||S||krt|r|j|t j }YnXWdxt |D]}|j |qWXdS)N) r?r __enter__rrupdaterrrsysexc_infor__exit__)r+Zkeywargs extra_argsZentered_patchersr patchingr)r'patchedrrrs*         z)_patch.decorate_callable..patched)rrrr)rfr'r)r'rrrs   z_patch.decorate_callablec Cs|j}|j}t}d}y|j|}Wn$ttfk rHt||t}YnXd}|tkrft|t rfd|_ |j r|tkrtd||f||fS)NFTz!%s does not have the attribute %r) rrrrBr"KeyErrorr< _builtinsrrr)rfrrrIlocalrrr get_originalsz_patch.get_originalcCs>|j|j|j}}}|j|j}}|j}|j|_|dkr@d}|dkrLd}|dkrXd}|dk rp|dk rptd|dk s|dk r|dkrtd|j \}}|t ko|dkrTd} |dkr|}|dkr|}d}n&|dk r|dkr|}d}n |dkr|}|dk s |dk r,|t krtdt |t r,d} t } i} |dk rD|} nN|dk sX|dk r|} |dk rj|} t| r~d| k} n t|  } | rt} |dk r|| d<|dk r|| d<t | t rt| tr|jr|j| d <| j|| f| }| rt|r|} |dk r|} t|  r2t|  r2t} | jd | f|d d | |_nl|dk r|t k rptd |t krtd t|}|dkr|}t|f||jd|}n|rtd|}||_||_t|j|j||jdk r:i}|jt kr|||j<x.|jD]$}|j }|jt kr|j|qW|S|S)NFzCan't specify spec and autospecTz6Can't provide explicit spec_set *and* spec or autospecz!Can't use 'spec' with create=Truer$rrrz())rrzBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r_namez.Can't pass kwargs to a mock we aren't creating)TN)!rrrrr,rrrrrrrrrr@rr rr rr rrErrYboolr temp_originalrrzrrr )rfrrrrr,rrIrZinheritKlass_kwargsZ this_specZ not_callableZnew_attrrrrrrrr s                              z_patch.__enter__cGst|std|jr4|jtk r4t|j|j|jnBt|j|j|j rvt |j|j sd|jdkrvt|j|j|j|`|`|`x$t |j D]}t|r|j |qWdS)Nz stop called on unstarted patcherr6r8r9__annotations__r:)r6r8r9rr:)r RuntimeErrorrrrrzrrrrrrrr )rfr rrrrr Hs z_patch.__exit__cCs|j}|jj||S)N)r _active_patchesr)rfrJrrrstart`s z _patch.startc Cs.y|jj|Wntk r$YnX|jS)N)rrr&r )rfrrrstopgs z _patch.stop)r5r8rhrrr!rr$rrrr r rrrrrrrIs (~rc sPyjdd\}Wn&ttfk r:tdfYnXfdd}||fS)Nrrz.Need a valid target to patch. You supplied: %rcstS)N)rr)rrrrysz_get_target..)rsplitrr&)rrrr)rr _get_targetss r c s$fdd} t| |||||||| S)NcsS)Nrr)rrrrsz_patch_object..)r) rrrrrrrrr,rr)rr _patch_object}s  r!c sttkrfdd}n fdd}|s2tdt|j}|d\} } t|| | |||||i } | | _xB|ddD]2\} } t|| | |||||i } | | _| jj| qvW| S)NcstS)N)rr)rrrrsz!_patch_multiple..csS)Nrr)rrrrsz=Must supply at least one keyword argument with patch.multiplerr) rstrr&r>rrrrr) rrrrrrr,rrrrrZ this_patcherr)rr_patch_multiples&        r#c Ks$t|\}} t|| ||||||| S)N)r r) rrrrrrrr,rrrrrrsE  c@sReZdZfdfddZddZddZdd Zd d Zd d ZddZ eZ e Z dS) _patch_dictFcKs>t|trt|}||_t||_|jj|||_d|_dS)N) rr"rin_dictrnrr clear _original)rfr%rr&r,rrrr!0s   z_patch_dict.__init__cs.ttrjStfdd}|S)Nc s"jz ||SjXdS)N)r$ _unpatch_dict)r+r)frfrr_inner>s z$_patch_dict.__call__.._inner)rrrr)rfr)r*r)r)rfrr$;s  z_patch_dict.__call__cCs\xVt|D]J}t||}|jtjr t|dr t|j|j|j }||}t |||q W|S)Nr$) rr<rrrrr$r%rr&rz)rfrrrZ decoratorZ decoratedrrrrIs   z_patch_dict.decorate_classcCs |jdS)N)r$)rfrrrr Tsz_patch_dict.__enter__cCs|j}|j}|j}y |j}Wn2tk rPi}x|D]}||||<q8WYnX||_|rdt|y|j|Wn.tk rx|D]}||||<qWYnXdS)N)rr%r&rr"r' _clear_dictr )rfrr%r&rIrrrrr$Ys"   z_patch_dict._patch_dictc CsV|j}|j}t|y|j|Wn.tk rPx|D]}||||<q8WYnXdS)N)r%r'r+r r")rfr%rIrrrrr(ss z_patch_dict._unpatch_dictcGs |jdS)NF)r()rfr+rrrr sz_patch_dict.__exit__N) r5r8rhr!r$rr r$r(r rrrrrrr$s   r$c CsBy |jWn0tk r<t|}x|D] }||=q*WYnXdS)N)r&r"r>)r%keysrrrrr+s   r+cCs xttjD] }|jq WdS)N)rrrr)rrrr_patch_stopallsr-Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index trunc floor ceil bool next zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv ccs|]}d|VqdS)zi%sNr)rnrrrrsrccs|]}d|VqdS)zr%sNr)rr/rrrrs__get____set__ __delete__ __reversed__ __missing__ __reduce__ __reduce_ex__Z__getinitargs____getnewargs__ __getstate__ __setstate__ __getformat__ __setformat__rgr__subclasses__ __format____getnewargs_ex__csfdd}||_|S)Ncs|f||S)Nr)rfr+r)r'rrmethodsz_get_method..method)r5)rr'r?r)r'rrs rcCsh|] }d|qS)z__%s__r)rr?rrrrsrmrr!r __prepare____instancecheck____subclasscheck____del__cCs tj|S)N)r__hash__)rfrrrrsrcCs tj|S)N)r__str__)rfrrrrscCs tj|S)N)r __sizeof__)rfrrrrs)rDrErFry?g?) __lt____gt____le____ge____int__r__len__r  __complex__ __float____bool__ __index__csfdd}|S)Ncs$jj}|tk r|S|kr dStS)NT)__eq__rrrNotImplemented)otherret_val)rfrrrQs z_get_eq..__eq__r)rfrQr)rfr_get_eqs rUcsfdd}|S)Ncs jjtk rtS|krdStS)NF)__ne__rrrrR)rS)rfrrrVs  z_get_ne..__ne__r)rfrVr)rfr_get_nes rWcsfdd}|S)Ncs jj}|tkrtgSt|S)N)rrrrr)rT)rfrrrsz_get_iter..__iter__r)rfrr)rfr _get_iters rX)rQrVrc Cstj|t}|tk r||_dStj|}|dk rdy ||}Wntk rXt|}YnX||_dStj|}|dk r|||_dS)N)_return_valuesrCrrY_calculate_return_valuer"_side_effect_methodsr_)r1r?rZfixedZreturn_calulatorrYZ side_effectorrrr_set_return_values    r\c@seZdZddZddZdS) MagicMixincOs&|jtt|j|||jdS)N)_mock_set_magicsrr]r!)rfr+rrrrr!(szMagicMixin.__init__cCst}t|dddk rTtj|j}t}t|}x$|D]}|t|jkr4t||q4W|tt|j}t|}x|D]}t||t ||qtWdS)Nr) _magicsr< intersectionrrorrBrrz MagicProxy)rfZ these_magicsZ remove_magicsrrrrrr^.s   zMagicMixin._mock_set_magicsN)r5r8rhr!r^rrrrr]'sr]c@seZdZdddZdS)r FcCs|j|||jdS)N)rr^)rfrrrrrrGs z"NonCallableMagicMock.mock_add_specN)F)r5r8rhrrrrrr Esc@seZdZdddZdS)rFcCs|j|||jdS)N)rr^)rfrrrrrr]s zMagicMock.mock_add_specN)F)r5r8rhrrrrrrRs c@s.eZdZddZddZddZd dd ZdS) racCs||_||_dS)N)rr)rfrrrrrr!iszMagicProxy.__init__cOs|j}|||S)N) create_mock)rfr+r,mrrrr$mszMagicProxy.__call__cCs8|j}|j}|j|||d}t|||t||||S)N)rrr)rrrrzr\)rfrrrcrrrrbqs  zMagicProxy.create_mockNcCs|jS)N)rb)rfrrrrrr0zszMagicProxy.__get__)N)r5r8rhr!r$rbr0rrrrrahs rac@s$eZdZddZddZddZdS)_ANYcCsdS)NTr)rfrSrrrrQsz _ANY.__eq__cCsdS)NFr)rfrSrrrrVsz _ANY.__ne__cCsdS)Nzr)rfrrrrgsz _ANY.__repr__N)r5r8rhrQrVrgrrrrrdsrdcCsdd|}d}djdd|D}djddt|jD}|rD|}|r\|rT|d7}||7}||S)Nz%s(%%s)rz, cSsg|] }t|qSr)repr)rrrrrrsz*_format_call_signature..cSsg|]\}}d||fqS)z%s=%rr)rrrprrrrs)rrr)rr+r,rZformatted_argsZ args_stringZ kwargs_stringrrrrsrc@sreZdZfddddfddZfddddfddZd d ZejZd d Zd dZ ddZ ddZ ddZ ddZ dS)rrNFTc Csf}i}t|}|dkr$|\}}}nr|dkrd|\} } t| trX| }t| trR| }qb| }q| | }}n2|dkr|\}t|tr|}nt|tr|}n|}|rtj|||fStj||||fS)Nrrbr)rrr"r?r) rrprrr from_kallr+r,_lenfirstsecondrrrrs.      z _Call.__new__cCs||_||_||_dS)N)rvrt_mock_from_kall)rfrprrrrfrrrr!sz_Call.__init__c Csf|tkr dSy t|}Wntk r,dSXd}t|dkrH|\}}n |\}}}t|ddrzt|ddrz|j|jkrzdSd}|dkrfi}}n|dkr|\}}}n|dkr|\} t| tr| }i}n"t| tr| }fi}}nf}| }nV|dkr>|\} } t| tr2| }t| tr&| i}}n f| }}n | | }}ndS|rV||krVdS||f||fkS) NTFrrbrtrrr)rrrr<rtrr?r") rfrSZ len_otherZ self_nameZ self_argsZ self_kwargsZ other_nameZ other_argsZ other_kwargsrprhrirrrrQsP                z _Call.__eq__cOs<|jdkrtd||fddS|jd}t|j||f||dS)Nrz())r)rr)rvr)rfr+r,rrrrr$s  z_Call.__call__cCs2|jdkrt|ddSd|j|f}t||ddS)NF)rrfz%s.%s)rrrf)rvr)rfrrrrrrms  z_Call.__getattr__cOs|jd||S)Nr)rm)rfr+r,rrrr$sz _Call.countcOs|jd||S)Nindex)rm)rfr+r,rrrrk'sz _Call.indexcCs||js&|jpd}|jdr"d|}|St|dkr@d}|\}}n0|\}}}|sTd}n|jdshd|}nd|}t|||S)Nrz()zcall%srbzcall.%s)rjrvrrr)rfrr+r,rrrrg*s       z_Call.__repr__cCs8g}|}x"|dk r*|jr"|j||j}q Wtt|S)N)rjrrtrUr)rfvalsrrrr call_list?s   z_Call.call_list)r5r8rhrr!rQrrVr$rmrrkrgrmrrrrrs  7r)rfcKs,t|rt|}t|t}d|i}|r0d|i}n |dkr.rrxrxrxrx)rbytesr) read_dataZ data_as_listliner)rwr_iterate_read_data s  r|rcsfdd}fdd}fddtdkr`ddl}ttt|jjtt|ja|dkrttdt d }ttd j _ t dgdj _ dj_ dj_ dj_ |j_d <d j_|j_fd d }||_|_ |S)Ncs jjdk rjjStdS)Nr) readlinesrYr>)r+r,)_statehandlerr_readlines_side_effect( s z)mock_open.._readlines_side_effectcs(jjdk rjjStjdS)Nr)readrYrr)r+r,)r~rrzrr_read_side_effect- s z$mock_open.._read_side_effectc3sJjjdk rxjjVqWxdD] }|Vq&WxtVq6WdS)Nr)readlinerYr)r{)r~rrzrr_readline_side_effect2 s  z(mock_open.._readline_side_effectropen)rr)rrcs6td<jjdkr2d<dj_tS)Nrr)r|rr_r)r+r,)rr~rrzrr reset_dataS s    zmock_open..reset_data) file_spec_ior>ror TextIOWrapperunionBytesIOrrr rYr|writerrr}r_)r1rzrrrrr)rr~rrzrr  s.  "     c@s$eZdZddZddZddZdS)r cKs tf|S)N)r)rfr,rrrri szPropertyMock._get_child_mockcCs|S)Nr)rfrZobj_typerrrr0l szPropertyMock.__get__cCs ||dS)Nr)rfrrrrrr1n szPropertyMock.__set__N)r5r8rhrr0r1rrrrr ` s ) rrrrrrrrr r r r r )F)F)NFNNN)FFNN)Nr)o__all__ __version__r%rr builtinstypesr functoolsrrrr BaseExceptionrplatformrZlangZ Throwabler superrrr r(r4r/r=r@rErMrHrdrrerirrZMISSINGrZDELETEDrrqr|rr>rUrrrr rrrrrrrr r!r#rr$r+r-rnZmultipleZstopallrZ magic_methodsZnumericsrrZinplacerightZ _non_defaultsrr_rrrZrRrYrUrWrXr[r\r]r rrardrrr?rrrrnrrrrQr#r0rrrr|r r rrrrs     4  i5 ,   1Jv        ,  w  D