bg/dZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZddlmZmZddlmZddlmZdd lmZGd d eZd eeDZd ZeZdZdZdZ dZ!dZ"dZ#ddZ$dZ%dZ&dZ'dZ(ddZ)ddZ*dZ+dZ,dZ-Gdd e.Z/Gd!d"e.Z0e0Z1e1j2Z2e1j3Z4e1j5Z6hd#Z7d$Z8Gd%d&e9Z:d'Z;Gd(d)e.Z<Gd*d+e.Z=Gd,d-e=Z> e?j@Z@n#eA$rd.Z@YnwxYweBd/ee>DZCGd0d1e9ZDd2ZEGd3d4e=ZFGd5d6eFe>ZGd7ZHd8ZId9ZJGd:d;e.ZKd<ZLe2dddddfdd=d>ZM dd?ZNe2dddddfdd=d@ZOGdAdBe.ZPdCZQdDZReMeO_.ePeO_SeNeO_TeReO_UdEeO_VdFZWereWXdGdHZWdIZYdJZdKeY[DZ\dJZdLeY[DZ]hdMZ^dNZ_dOdJZeWeYe\e]g[DZ`hdPZadQhZbeaebzZce`e^zZdedeczZehdRZfdSdTdUdVdWZgehehehehdddddXdYd dddZ Zid[Zjd\Zkd]Zld^Zmejekelemd_Znd`ZoGdadbe=ZpGdcddepe>ZqGdedfepZrGdgdhepeGZsGdidje=Ztee Zuejvee jwdZxGdkdle=ZyGdmdneyereGZzGdodpe.Z{e{Z|dqZ}Gdrdse~ZedtZ ddd=duZdvZGdwdxe.Zeeee|jfZdadadyZddzZGd{d|eGZe1jZGd}d~e=ZGddeepeGZdZGddZdS))Mock MagicMockpatchsentinelDEFAULTANYcallcreate_autospec AsyncMock ThreadingMock FILTER_DIRNonCallableMockNonCallableMagicMock mock_open PropertyMocksealN)CodeType ModuleType MethodType) safe_repr)wrapspartial)RLock)IS_PYPY)iscoroutinefunctionceZdZdZdS)InvalidSpecErrorz8Indicates that an invalid value was used as a mock spec.N__name__ __module__ __qualname____doc__Z/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/mock/mock.pyrr-sBBBBr%rc<h|]}|d|S_ startswith.0names r& r/1s) H H Hd4??33G3G HT H H Hr%Tct|rt|tsdSt|drt |d}t |pt j|S)NF__func__)_is_instance_mock isinstancer hasattrgetattrrinspect isawaitableobjs r& _is_async_objr:9sgji&@&@usJ'c:&& s # # ?w':3'?'??r%cFt|ddrt|SdS)N__code__F)r5r)funcs r&_is_async_funcr>As)tZ&&"4(((ur%cFtt|tSN) issubclasstyper r8s r&r2r2Hs d3ii 1 11r%ct|tp)t|tot|tSr@)r3 BaseExceptionrBrAr8s r& _is_exceptionrENs63 && A3@*S-"@"@r%c^t|trt|dr|jS|SNmock)r3 FunctionTypesr4rHr8s r& _extract_mockrJUs3#}%%'#v*>*>x r%ct|tr |s |j}d}njt|ttfrt|trd}|j}n/t|t s |j}n#t$rYdSwxYw|rt|d}n|} |tj |fS#t$rYdSwxYw)z Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None. TN) r3rB__init__ classmethod staticmethodr1rI__call__AttributeErrorrr6 signature ValueError)r= as_instanceeat_selfsig_funcs r&_get_signature_objectrV^s $k} D; 5 6 6  dK ( ( H} m , , =DD   44 4&&W&x0000 tts$3A;; B B "B88 CCFct|||dS\}fd}t|||t|_t|_dS)Nc"j|i|dSr@bind) _mock_selfargskwargssigs r&checksigz"_check_signature..checksig $!&!!!!!r%)rV_copy_func_detailsrB_mock_check_sig __signature__)r=rH skipfirstinstancer_r^s @r&_check_signaturerfsr h : :C {ID#"""""tX&&&!)DJJ"DJJr%c pdD]2} t||t||##t$rY/wxYwdS)N)r r#__text_signature__r! __defaults____kwdefaults__)setattrr5rP)r=funcopy attributes r&rarasa   GYi(@(@ A A A A    D  s & 33ct|trdSt|tttfrt |jSt|dddSdS)NTrOF)r3rBrNrMr _callabler1r5r8s r&roros^#tt# k:>??'&&&sJ%%1t 5r%c<t|ttfvSr@)rBlisttupler8s r&_is_listrss 99u %%r%ct|tst|ddduS|f|jzD]}|jddS dS)ztGiven an object, return True if the object is callable. For classes, return True if instances would be callable.rONTF)r3rBr5__mro____dict__get)r9bases r&_instance_callablerysn c4 :sJ--T99$ =  Z ( ( 444 5 5r%c0 t|t}t|||}||S|\} fd}t|||j}|sd}||d}d|z} t | |||} t| | | S)Nc"j|i|dSr@rYr\r]r^s r&r_z _set_signature..checksigr`r%rl _checksig_rHzYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs))r3rBrVrar isidentifierexec _setup_func) rHoriginalrerdresultr=r_r.contextsrcrlr^s @r&_set_signaturers 8T**I "8Xy A AF ~ ID#"""""tX&&&  D     %t44G $&* +C #wdmGs### Nr%c t|t}t|||\} fd}t|||j}||d}d|z} t | |||} t | | t| | S)Nc"j|i|dSr@rYr|s r&r_z&_set_async_signature..checksigr`r%r}zeasync def %s(*args, **kwargs): _checksig_(*args, **kwargs) return await mock(*args, **kwargs))r3rBrVrar rr_setup_async_mock) rHrre is_async_mockrdr=r_r.rrrlr^s @r&_set_async_signaturers 8T**I%h)DDID#"""""tX&&&  D%t44G *,0 1C #wdmGs###g Nr%c_fd}fd}fd}fd}fd}fd}fd} fd} d _d _d_t _t _t _j_j _ j _ |_ |_ |_ | _| _|_|_|_|__dS) Ncj|i|Sr@)assert_called_withr\r]rHs r&rz'_setup_func..assert_called_with&t&7777r%cj|i|Sr@) assert_calledrs r&rz"_setup_func..assert_calleds!t!426222r%cj|i|Sr@)assert_not_calledrs r&rz&_setup_func..assert_not_calleds%t%t6v666r%cj|i|Sr@)assert_called_oncers r&rz'_setup_func..assert_called_oncerr%cj|i|Sr@)assert_called_once_withrs r&rz,_setup_func..assert_called_once_withs+t+T.assert_has_callss$t$d5f555r%cj|i|Sr@)assert_any_callrs r&rz$_setup_func..assert_any_calls#t#T4V444r%ct_t_j}t |r|ur|dSdSdSr@) _CallList method_calls mock_calls reset_mock return_valuer2)retrlrHs r&rz_setup_func..reset_mockso({{&[[ " S ! ! #++ NN       ++r%Fr)rHcalled call_count call_argsrcall_args_listrrr side_effect_mock_childrenrrrrrrrrrc_mock_delegate) rlrHr^rrrrrrrrs `` r&rrsGL88888333337777788888=====6666655555GNGG&[[G$;;G"G,G*G!0G!3G&=G#/G-G#G)G 1G!3GG!Dr%c tjj_d_d_t _fd}dD]!}t|t||"dS)Nrc:tj||i|Sr@)r5rH)attrr\r]rHs r&wrapperz"_setup_async_mock..wrapper$s$'wty$''8888r%)assert_awaitedassert_awaited_onceassert_awaited_withassert_awaited_once_withassert_any_awaitassert_has_awaitsassert_not_awaited) asyncio coroutines _is_coroutine await_count await_argsrawait_args_listrkr)rHrrms` r&rrs +9DDDO$;;D 99999, > >  i)! >r%c$d|ddz|kS)N__%s__r$r.s r& _is_magicr6s d1R4j D ((r%c$eZdZdZdZdZdZdS)_SentinelObjectz!A unique, named, sentinel object.c||_dSr@rselfr.s r&rLz_SentinelObject.__init__<s  r%cd|jzSNz sentinel.%srrs r&__repr__z_SentinelObject.__repr__?ty((r%cd|jzSrrrs r& __reduce__z_SentinelObject.__reduce__Brr%N)r r!r"r#rLrrr$r%r&rr:sG''))))))))r%rc$eZdZdZdZdZdZdS) _SentinelzAAccess attributes to return a named object, usable as a sentinel.ci|_dSr@) _sentinelsrs r&rLz_Sentinel.__init__Hs r%cl|dkrt|j|t|S)N __bases__)rPr setdefaultrrs r& __getattr__z_Sentinel.__getattr__Ks3 ;   ))$0E0EFFFr%cdS)Nrr$rs r&rz_Sentinel.__reduce__Qszr%N)r r!r"r#rLrrr$r%r&rrFsJKKGGG r%r> _mock_namer _mock_parentr_mock_new_name_mock_new_parent_mock_side_effect_mock_return_valuecxt|d|z}||fd}||fd}t||S)N_mock_cT|j}|t||St||Sr@)rr5)rr. _the_namer^s r&_getz"_delegating_property.._getfs/! ;4++ +sD!!!r%cR|j}| ||j|<dSt|||dSr@)rrvrk)rvaluer.rr^s r&_setz"_delegating_property.._setks9! ;',DM) $ $ $ Cu % % % % %r%)_allowed_namesaddproperty)r.rrrs r&_delegating_propertyrcset4I """" $y&&&& D$  r%ceZdZdZdZdS)rct|tst||St|}t|}||krdSt d||z dzD]}||||z}||krdSdS)NFrrT)r3rq __contains__lenrange)rr len_valuelen_selfisub_lists r&rz_CallList.__contains__xs%&& 2$$T511 1JJ t99 x  5q(Y.233  AAa kM*H5  tt!ur%cDtjt|Sr@)pprintpformatrqrs r&rz_CallList.__repr__s~d4jj)))r%N)r r!r"rrr$r%r&rrvs2   *****r%rct|}t|sdS|js|js|j|jdS|}|||urdS|j}||r||_||_|r||_||_dS)NFT)rJr2rrrr)parentrr.new_name_parents r&_check_and_set_parentrs % E U # #u  U1   '   +uG   e  5*  (!''  # 4r%ceZdZdZdZdS) _MockIterc.t||_dSr@)iterr9)rr9s r&rLz_MockIter.__init__s99r%c*t|jSr@)nextr9rs r&__next__z_MockIter.__next__sDH~~r%N)r r!r"rLrr$r%r&rrs2r%rceZdZeZdZdZdS)BaseNcdSr@r$rr\r]s r&rLz Base.__init__s r%)r r!r"rrrrLr$r%r&rrs/      r%rceZdZdZeZ d-dZ d-dZdZd.dZ d/d Z d Z d Z d Z ee e e Zed ZedZedZedZedZedZdZdZeeeZd0ddddZdZdZdZdZdZdZ dZ!dZ"d1d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d.d(Z+d)Z,d*Z-d2d,Z.dS)3r z A non-callable version of `Mock`NFc  |f} t|ts|p|}|t|r t|f} t|j| d|ji}t t||}|S)Nr#) rAAsyncMockMixinr:rBr r# _safe_superr __new__)clsspecrr.spec_setr _spec_state _new_name _new_parent_spec_as_instance _eat_selfunsafer]basesspec_argnewres r&r zNonCallableMock.__new__s#~.. .'4H# h(?(?#'-3<CK(@AA44<>&& D'C!$D  r%cb|j||j_dS||_t||dddS)Nr9)rrrr)rrs r&__set_return_valuez"NonCallableMock.__set_return_valueJs>   */4D  , , ,&+D # !$tT : : : : :r%z1The value to be returned when the mock is called.c<|jt|S|jSr@)r+rBrs r& __class__zNonCallableMock.__class__Vs   #:: r%rrrrrc|j}||jS|j}|It|s:t |t s%t |st |}||_|Sr@)rrrcallabler3rrE)r delegatedsfs r&__get_side_effectz!NonCallableMock.__get_side_effectcsj'  ) )  " N8B<>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs)c8|ddS)Nr.)count)entrys r&z0NonCallableMock.configure_mock..sq1D1Dr%)keyrSN)sorteditemssplitpopr5rk)rr]argvalr\finalr9rUs r&r!zNonCallableMock.configure_mocksv||~~$E#D FFF % %HC 99S>>DHHJJEC * *c5)) C $ $ $ $ % %r%c |dvrt||j%||jvs |tvrtd|znt|rt||jsC|jr ||jvr3|ds |t vrt|d|dtj5|j |}|turt||Cd}|j t|j |}||||||}||j |<nt|t rv t#|j|j|j|j|j}n>#t.$r1|jdp|}t/d|d |d |d |jd wxYw||j |<dddn #1swxYwY|S) N>rr.zMock object has no attribute %r)assertassretasertaseertassrtz6 is not a valid assertion. Use a spec for the mock if z is meant to be an attribute.)rr.rrrrCannot autospec attr from target , as it has already been mocked out. [target=, attr=r*)rPr. _all_magicsrrr+_ATTRIB_DENY_LISTr _lockrrwrNrr5r;r3rMr r r rerr.rrv)rr.rr target_names r&rzNonCallableMock.__getattr__s 4 4 4 && &   +4---1D1D$%F%MNNN2E t__ ' && &  N$*< NDL^@^@^OPP NTX\mTmTm$MM'+MMMNNN " 4 4(,,T22F!!$T***#/$D$4d;;E--d%4 $..4#D))FJ// 4 D, V_fo v{FF(DDD"&- "="EK*CCC&CC#'CC28+CCCDDDD .4#D); 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4> s+4B G,E/.G/;F** GG Gcn|jg}|j}|}d}|dgkrd}|7|}||j|zd}|jdkrd}|j}|7tt |}|jpd}t |dkr|ddvr|dz }||d<d|S)NrSr9rrHr)r9z().r)rrr3rqreversedrrjoin)r _name_listrlastdot_firsts r&_extract_mock_namez"NonCallableMock._extract_mock_names)* ' $  C!D   g4s: ; ; ;C%--.G!(:..// *F z??Q  !}M11#  1 wwz"""r%c|}d}|dvrd|z}d}|jd}|jrd}||jjz}dt |j||dt |dS) Nr)rHzmock.z name=%rz spec=%rz spec_set=%r)rtr+r,r rBrK)rr. name_string spec_strings r&rzNonCallableMock.__repr__s&&(( ( ( ($t+K   '$K~ -, %(8(AAK JJ   K KK tHHHH   r%cvtst|S|jpg}t t |}t |j}d|j D}d|D}d|D}tt||z|z|zS)z8Filter the output of `dir(mock)` to only useful members.c*g|]\}}|tu|Sr$)rN)r-m_namem_values r& z+NonCallableMock.__dir__..s1(((&vwh&& &&&r%c<g|]}|d|Sr(r*r-es r&r}z+NonCallableMock.__dir__..s)CCC1c1B1BCQCCCr%cZg|](}|drt|&|)Sr()r+rrs r&r}z+NonCallableMock.__dir__..sE###1c1B1B#q\\#Q###r%) r object__dir__r.r0rBrqrvrrYrXset)rextras from_type from_dictfrom_child_mockss r&rzNonCallableMock.__dir__ s (>>$'' '#)rT OO '' ((*.*=*C*C*E*E(((DC CCC ## ### c&9,y8;KKLLMMMr%cT|tvrt||Sjr+j$|jvr|jvrt d|z|tvrd|z}t ||tvrj|jvrt d|zt|s5tt|t|||fd}nft|d|tt|||j|<n+|dkr |_dSt|||r |j|<jr;t#|s+d|}t d|t||S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cg|Ri|Sr@r$)r\kwrrs r&rVz-NonCallableMock.__setattr__..1s!HHT,GD,G,G,GB,G,Gr%r@rSz Cannot set )rr __setattr__r,r.rvrP_unsupported_magicsrir2rkrB _get_methodrrr+rr4rt)rr.rmsg mock_namers` @r&rzNonCallableMock.__setattr__s > ! !%%dD%88 8n 2!3!? * * *  % % !Dt!KLL L ( ( (BTIC %% % [ !-$d>P2P2P$%H4%OPPP$U++ 2T D+dE*B*BCCC GGGGG&dE4>>>T D%000,1#D)) [ $D  F$T5$== 2,1#D)   |t|jvr(tt||||jvrdS|j|t }||jvr)tt| |n|turt||t ur|j|=t|j|<dSr@) rirBrvdelattrrrw_missingr r __delattr__rNrP)rr.r9s r&rzNonCallableMock.__delattr__Fs ;  44::+>#>#> DJJ % % %4=((!%%dH55 4=  . . : :4 @ @ @ @ H__ && & h  #D)$,D!!!r%c6|jpd}t|||SrG)r_format_call_signaturerr\r]r.s r&_format_mock_call_signaturez+NonCallableMock._format_mock_call_signatureXs (&%dD&999r%rcdd}|||}|j}|j|}||||fzS)Nz.expected %s not found. Expected: %s Actual: %s)rr)rr\r]actionmessageexpected_stringr actual_strings r&_format_mock_failure_messagez,NonCallableMock._format_mock_failure_message]sDD::4HHN 88)D &/=AAAr%c|s|jSd}|ddd}|j}|D]M}||}|t |t rnt|}|j}|j}N|S)aH * If call objects are asserted against a method/function like obj.meth1 then there could be no name for the call object to lookup. Hence just return the spec_signature of the method/function being asserted against. * If the name is not empty then remove () and split by '.' to get list of names to iterate through the children until a potential match is found. A child mock is created only during attribute access so if we get a _SpecState then no attributes of the spec were accessed and can be safely exited. Nr9rrS)r-replacerZrrwr3rMrJ)rr.r^nameschildrenrPs r&_get_call_signature_from_namez-NonCallableMock._get_call_signature_from_namees (' ' T2&&,,S11& , ,DLL&&E} 5* = =} &e,, /+ r%ct|tr/t|dkr||d}n|j}|vt|dkrd}|\}}n|\}}} |j|i|}t ||j|jS#t$r}| dcYd}~Sd}~wwxYw|S)a Given a call (or simply an (args, kwargs) tuple), return a comparison key suitable for matching with other calls. This is a best effort method which relies on the spec's signature, if available, or falls back on the arguments themselves. rrNr) r3rrrrr-rZrr\r] TypeErrorwith_traceback)r_callr^r.r\r] bound_callrs r& _call_matcherzNonCallableMock._call_matchers eU # # 'E Q44U1X>>CC&C ?5zzQ$ ff%*"dF .%SXt6v66 D*/:3DEEE . . .''-------- .Ls0'B C"B<6C<Cc|}|jdkr8d|jpdd|jd|}t|dS)z/assert that the mock was never called. r Expected 'rHz"' to not have been called. Called  times.Nrr _calls_reprAssertionErrorr[rrs r&rz!NonCallableMock.assert_not_calledsc ?a   o///ooo&&(((*C!%% % r%cV|}|jdkrd|jpdz}t|dS)z6assert that the mock was called at least once rz"Expected '%s' to have been called.rHN)rrrrs r&rzNonCallableMock.assert_calleds@ ?a  7?,f.C %% % r%c|}|jdks8d|jpdd|jd|}t|dS)z3assert that the mock was called only once. rrrHz#' to have been called once. Called rNrrs r&rz"NonCallableMock.assert_called_oncesc!###o///ooo&&(((*C!%% % $#r%cx|j/}d}d|d|}t|fd}t fd}j}||kr1t |t r|nd}t||dS)zassert that the last call was made with the specified arguments. Raises an AssertionError if the args and keyword args passed in are different to the last call to the mock.Nz not called.z#expected call not found. Expected: Actual: c4}|Sr@rrr\r]rs r&_error_messagez:NonCallableMock.assert_called_with.._error_messages33D&AACJr%Ttwo)rrrr_Callr3 Exception) r[r\r]expectedactual error_messagercausers `` @r&rz"NonCallableMock.assert_called_withs  > !77fEEH"FFxx)M // /       %%eT6N&E&E&EFF##DN33 X   *8Y ? ?IHHTE !1!122 =  r%c|}|jdks8d|jpdd|jd|}t||j|i|S)ziassert that the mock was called exactly once and that that call was with the specified arguments.rrrHz' to be called once. Called r)rrrrrr[r\r]rrs r&rz'NonCallableMock.assert_called_once_withss!###o///ooo&&(((*C!%% %&t&7777r%cfd|D}td|Dd}tfdjD}|su||vro|d}ndd|D}t |dt|d d |dSt|}g}|D]=} ||#t$r| |Y:wxYw|r-t j pd d t|d|d|dS)aassert the mock has been called with the specified calls. The `mock_calls` list is checked for the calls. If `any_order` is False (the default) then the calls must be sequential. There can be extra calls before or after the specified calls. If `any_order` is True then the calls can be in any order, but they must all appear in `mock_calls`.c:g|]}|Sr$rr-crs r&r}z4NonCallableMock.assert_has_calls..'999aD&&q))999r%c3DK|]}t|t|VdSr@r3rrs r& z3NonCallableMock.assert_has_calls..s1FFAZ9-E-EFaFFFFFFr%Nc3BK|]}|VdSr@rrs r&rz3NonCallableMock.assert_has_calls..s1MMd0033MMMMMMr%zCalls not found.z+Error processing expected calls. Errors: {}c@g|]}t|tr|ndSr@rrs r&r}z4NonCallableMock.assert_has_calls..;$7$7$7()*4Ay)A)A$KAAt$7$7$7r% Expected: Actual)prefixrSrHz does not contain all of z in its call list, found z instead) rrrformatrrrstriprqremoverRr3rrr) rcalls any_orderrr all_callsproblem not_foundkalls ` r&rz NonCallableMock.assert_has_callss:9995999FFFFFMMMMMMT_MMMMM  y((=0GG ,-3V$7$7-5$7$7$7.8.8%GG!*5!1!1G''x'88??DDGG  FOO   ' 'D '  &&&& ' ' '  &&&&& '   &*o&?&?&?&+I&6&6&6&6 C    sC--DDc$t||fd}t|tr|nd}fdjD}|s|t |vr)||}td|z|dS)zassert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike `assert_called_with` and `assert_called_once_with` that only pass if the call is the most recent one.TrNc:g|]}|Sr$rrs r&r}z3NonCallableMock.assert_any_call..s'EEEA$$$Q''EEEr%z%s call not found)rrr3rr _AnyComparerrr)rr\r]rrrrs` r&rzNonCallableMock.assert_any_calls %%eT6N&E&E&EFF&x;;EEEEE1DEEE  HL$8$888">>tVLLO #o5 98r%c |jr7d|vr d|dnd}||z}t||d}||jdvr t di|St |}t|tr|tvrt }nt|tr)|tvs|j r||j vrt}ndt }n\t|ts:t|trt}n*t|trt }n |jd}|di|S)aPCreate the child mocks for attributes and return value. By default child mocks will be the same type as the parent. Subclasses of Mock may want to override this to customize the way child mocks are made. For non-callable mocks the callable variant will be used (rather than any custom subclass).r.rSr9rr/rr$)rrtrPrwrvr rBrAr_async_method_magicsr_all_sync_magicsr. CallableMixinrr rru)rrrmrr_typeklasss r&r;zNonCallableMock._get_child_mock!s[   ,,2bLL(BvJ(((dI//11I=I ++ +FF;''  n5 5 5??r?? "T  eY ' ' %I9M,M,MEE ~ . . %---&.+48J+J+J!!E=11 %%!566 !E?33 M!$Eu{{r{{r%CallscJ|jsdSd|dt|jdS)zRenders self.mock_calls as a string. Example: " Calls: [call(1), call(2)]." If self.mock_calls is empty, an empty string is returned. The output will be truncated if very long. r z: rS)rr)rrs r&rzNonCallableMock._calls_reprGs6 2;F;;i88;;;;r%) NNNNNNrNFNFFFFr@)r)r)/r r!r"r#rrkr rLr$r(r "_NonCallableMock__get_return_value"_NonCallableMock__set_return_value"_NonCallableMock__return_value_docrrr@rrrrrr!_NonCallableMock__get_side_effect!_NonCallableMock__set_side_effectrrr!rrtrrrrrrrrrrrrrrrr;rr$r%r&r r s** EGGE=AEIBEI>>. 8 8 8****Z    ###L < < < < < .ks1$HfF"r%TF)rallzip)ritemrs r&rz_AnyComparer.__contains__hs{  Et99E ****(+D%(8(8 tt   ur%N)r r!r"r#rr$r%r&rrcs-r%rc||St|r|St|r|S t|S#t$r|cYSwxYwr@)rErorrr8s r&rGrGssk { S ~~ Cyy  s7 AAc HeZdZddedddddddf dZdZdZdZdZdZ dS) rNrc x||jd<tt|j||||||| | fi| ||_dS)Nr)rvr rrLr) rr rrrr.r rrrrr]s r&rLzCallableMixin.__init__sa/; *+1 M4((1 %x K  39   'r%cdSr@r$rs r&rbzCallableMixin._mock_check_sigs r%cP|j|i||j|i||j|i|Sr@)rb_increment_mock_call _mock_callr[r\r]s r&rOzCallableMixin.__call__sL # "D3F333' '8888$z$d5f555r%c|j|i|Sr@)_execute_mock_callrs r&rzCallableMixin._mock_calls,z,d=f===r%c|}d|_|xjdz c_t||fd}||_|j||jdu}|j}|j}|dk}|j td||f|j } | |rB| j t|||f| jdu}|r | jdz|z}t|||f} | j | | jr|rd} nd} | jdk}| j| z|z}| j } | dSdS)NTrrr9rrS) rrrrrr3rrrrrr) r[r\r]rrdo_method_callsmethod_call_namemock_call_name is_a_callrthis_mock_callrrs r&rz"CallableMixin._increment_mock_calls  1 tVn$/// ""5)))+47?,"d*  ub$%788999+ % W(//7Gv6V0W0WXXX"-":$"F"W'2'='CFV'V$#ND&#ABBN  " ) ). 9 9 9) SCCC'6$> !,!;c!AN!R&6K-%%%%%r%c |}|j}|Tt|r|t|s!t|}t|r|n||i|}|tur|S|jtur|jS|j |j|i|S|jSr@)rrErorrrrr)r[r\r]reffectrs r&rz CallableMixin._execute_mock_calls!  V$$ 1 v&& 1f ((! L! 000W$$  "' 1 1$ $   '#4#T4V44 4  r%) r r!r"rrLrbrOrrrr$r%r&rrs d$d!RT ' ' ' '   666>>>-7-7-7^!!!!!r%rceZdZdZdS)ra Create a new `Mock` object. `Mock` takes several optional arguments that specify the behaviour of the Mock object: * `spec`: This can be either a list of strings or an existing object (a class or instance) that acts as the specification for the mock object. If you pass in an object then a list of strings is formed by calling dir on the object (excluding unsupported magic attributes and methods). Accessing any attribute not in this list will raise an `AttributeError`. If `spec` is an object (rather than a list of strings) then `mock.__class__` returns the class of the spec object. This allows mocks to pass `isinstance` tests. * `spec_set`: A stricter variant of `spec`. If used, attempting to *set* or get an attribute on the mock that isn't on the object passed as `spec_set` will raise an `AttributeError`. * `side_effect`: A function to be called whenever the Mock is called. See the `side_effect` attribute. Useful for raising exceptions or dynamically changing return values. The function is called with the same arguments as the mock, and unless it returns `DEFAULT`, the return value of this function is used as the return value. If `side_effect` is an iterable then each call to the mock will return the next value from the iterable. If any of the members of the iterable are exceptions they will be raised instead of returned. * `return_value`: The value returned when the mock is called. By default this is a new Mock (created on first access). See the `return_value` attribute. * `unsafe`: By default, accessing any attribute whose name starts with *assert*, *assret*, *asert*, *aseert*, or *assrt* raises an AttributeError. Additionally, an AttributeError is raised when accessing attributes that match the name of an assertion method without the prefix `assert_`, e.g. accessing `called_once` instead of `assert_called_once`. Passing `unsafe=True` will allow access to these attributes. * `wraps`: Item for the mock object to wrap. If `wraps` is not None then calling the Mock will pass the call through to the wrapped object (returning the real result). Attribute access on the mock will return a Mock object that wraps the corresponding attribute of the wrapped object (so attempting to access an attribute that doesn't exist will raise an `AttributeError`). If the mock has an explicit `return_value` set then calls are not passed to the wrapped object and the `return_value` is returned instead. * `name`: If the mock has a name then it will be used in the repr of the mock. This can be useful for debugging. The name is propagated to child mocks. Mocks can also be called with arbitrary keyword arguments. These will be used to set attributes on the mock after it is created. Nrr$r%r&rrs7777r%rc t||S#t$r"t|t||cYSwxYwr@)r5rP __import__)thingcomp import_paths r& _dot_lookupr'sV$ud### $$$;ud#####$s )>>c|d}|d}t|}|D]}|d|zz }t|||}|S)NrSrz.%s)rZr[r r)target componentsrrrs r& _importerr/sfc""J..##K { # #E66ut|# E455 Lr%c@d}|D]}||vrt|ddS)N) autospect auto_specset_specz5 might be a typo; use unsafe=True if this is intended) RuntimeError)kwargs_to_checktypostypos r&_check_spec_arg_typosr<sN 2E ? " "PPP  #r%c~eZdZdZgZdddZdZdZdZe j dZ d Z d Z d Zd Zd ZdZdZdS)_patchNFrc |)|turtd|td| st| t|rt d|d|dt|rt d|d|d||_||_||_||_||_ ||_ d|_ ||_ ||_ | |_g|_dS)Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherzCannot spec attr z0 as the spec has already been mocked out. [spec=r*z? as the spec_set target has already been mocked out. [spec_set=F)rrRrr2rgetterrmr new_callabler create has_localr autospecr]additional_patchers) rr#rmrr r%r r'r$r]rs r&rLz_patch.__init__JsV  #'!! B# G * !& ) ) ) T " " A"@I@@6:@@@AA A X & & P"OIOOAIOOOPP P "(       #%   r%c t|j|j|j|j|j|j|j|j|j }|j |_ d|j D|_ |S)Nc6g|]}|Sr$)copy)r-ps r&r}z_patch.copy..vs-' ' ' AFFHH' ' ' r%) r r#rmrr r%r r'r$r]attribute_namer()rpatchers r&r+z _patch.copyosq K49 K M4,dk   "&!4' ' "6' ' ' #r%ct|tr||Stj|r||S||Sr@r3rBdecorate_classr6rdecorate_async_callabledecorate_callable)rr=s r&rOz_patch.__call__|sc dD ! ! -&&t,, ,  &t , , 6//55 5%%d+++r%ct|D]q}|tjs"t ||}t |dsC|}t||||r|SNrO)r0r+r TEST_PREFIXr5r4r+rk)rrr attr_valuer.s r&r1z_patch.decorate_classsJJ 6 6D??5#455  --J:z22 iikkG E4!4!4 5 5 5 5 r%c#TKg}tj5}|jD]W}||}|j||4|jtur||X|t|z }||fVddddS#1swxYwYdSr@) contextlib ExitStack patchings enter_contextr-updaterrr3rr)rpatchedr\keywargs extra_args exit_stackpatchingr\s r&decoration_helperz_patch.decoration_helpers  ! # # #z#- + + ..x88*6OOC((((\W,,%%c*** E*%% %D" " " " # # # # # # # # # # # # # # # # # #sA8BB!$B!ctdrjStfdg_S)Nr;c|||5\}}|i|cdddS#1swxYwYdSr@rCr\r?newargs newkeywargsr=r>rs r&r>z)_patch.decorate_callable..patcheds''(,(022 55Kg{tW4 44 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s 155r4r;r3rrr=r>s``@r&r3z_patch.decorate_callablesv 4 % %  N ! !$ ' ' 'K t 5 5 5 5 5 5  5 "Fr%ctdrjStfdg_S)Nr;cK||5\}}|i|d{VcdddS#1swxYwYdSr@rFrGs r&r>z/_patch.decorate_async_callable..patcheds''(,(022 ;5Kg{!T7:k:::::::: ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s 9==rJrKs``@r&r2z_patch.decorate_async_callablesv 4 % %  N ! !$ ' ' 'K t ; ; ; ; ; ;  ; "Fr%c`|}|j}t}d} |j|}d}n-#tt f$rt ||t}YnwxYw|tvrt|trd|_ |j s|turt |d|||fS)NFTz does not have the attribute ) r#rmrrvrPKeyErrorr5 _builtinsr3rr%)rrr.rlocals r& get_originalz_patch.get_originals~ t,HEE) 6 6 6vtW55HHH 6 9  FJ!?!? DK{ x722 7=vvttD s 6'A A c |j|j|j}}}|j|j}}|j}||_|durd}|durd}|durd}||td|||dvrtd| \}}|tur|d} |dur |}|dur|}d}n| |dur|}d}n|dur|}||/|turtdt|trd} |t|rt} nt} i} ||} nN||J|} ||} t!| rd| v} nt#|  } t| rt} n | rt$} ||| d <||| d <t| tr&t'| t(r|jr |j| d <| || di| }| r_t/|rP|} ||} t!| st1| st$} | d | d|d d | |_n||turtd|turtdt7|}|dur|}t/|jr#t9d|jd|jd|dt/|rAt;|jd|j}t9d|jd|d|jd|d t=|f||jd|}n|rtd|}||_||_ tCj"|_# tI|j|j||j%ci}|jtur |||j%<|j&D]?}|j#'|}|jtur||@|S|S#|j(tSj*sYdSxYw)zPerform the patch.FNzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!Can't use 'spec' with create=TruerOr r r.r9r:zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=Truerez: as the patch target has already been mocked out. [target=rhr*r rfrg)r _namez.Can't pass kwargs to a mock we aren't creatingr$)+rr r r'r]r$r#rrrRrr3rBr:r rrsrBrrAr rmr=r2ryr[rboolrr5r temp_originalis_localr9r: _exit_stackrkr-r(r<__exit__sysexc_info)rrr r r'r]r$rrQinheritKlass_kwargs this_spec not_callablerlnew_attrr@rBr\s r& __enter__z_patch.__enter__s"h 4=8T=$+&( kkmm  5==D u  H u  H   4=>> >  !5 L ( (TUU U++--% '>>h.Gt||t##'HD!t###HDT!!#8#7w&&#$GHHHh--#"G| h 7 7|!!G'$!X%9 ' (II&&;#-Y#>LL'/ ':':#:L ++1%EE!10E"&#&. #5$'' 15/22 17;~ 1"&. NN6 " " "%""'""C 4,S11 4! ' (I ++1&y1110E F####(5$4SD$4$4+2$4$4  !'!!(7"" GHHHH~~H4# -- D&CDNCC#{CC5=CCCDDD!** D%dk:t{KK &CDNCC"CC#{CC5=CCCDDD "(BX(,BB:@BBCC  NLMM M% %/11  DK : : :". 8w&&7:Jt23 $ 8//H*88BBC|w.."))#...!!J  4=#,..1    sBOOO<ch|jr/|jtur!t|j|j|jndt |j|j|jsCt|j|jr |jdvr t|j|j|j|`|`|`|j }|` |j |S)zUndo the patch.)r#r!ri__annotations__rj) rWrVrrkrrmrr%r4rXrY)rr[rAs r&rYz_patch.__exit__ms = IT/w>> DK1C D D D D DK 0 0 0; I T^(L(L I+=== T^T5GHHH   M K%  "z"H--r%cb|}|j||Sz-Activate a patch, returning any created mock.)rb_active_patchesr3rrs r&startz _patch.starts-!! ##D))) r%c |j|n#t$rYdSwxYw|dddSzStop an active patch.N)rgrrRrYrs r&stopz _patch.stops[   ' ' - - - -   44 }}T4...s  ++)r r!r"r-rgrLr+rOr1r9contextmanagerrCr3r2rRrbrYrirlr$r%r&r r EsNOAF"&"&"&"&"&J   ,,,    # # #""0PPPd...*/////r%r c dd\}n-#tttf$rtdwxYwfd}||fS)NrSrz,Need a valid target to patch. You supplied: c"tSr@rrsr&rVz_get_target..sYv&&r%)rsplitrrRrP)rrmr#s` r& _get_targetrssG"MM#q11 z> 2GGG E6 E EGG GG' & & &F 9 s *Ar!c tturtdfd} t| |||||||| | S)a patch the named member (`attribute`) on an object (`target`) with a mock object. `patch.object` can be used as a decorator, class decorator or a context manager. Arguments `new`, `spec`, `create`, `spec_set`, `autospec` and `new_callable` have the same meaning as for `patch`. Like `patch`, `patch.object` takes arbitrary keyword arguments for configuring the mock object it creates. When used as a class decorator `patch.object` honours `patch.TEST_PREFIX` for choosing which methods to wrap. z3 must be the actual object to be patched, not a strcSr@r$rqsr&rVz_patch_object..sVr%r!)rBstrrr ) rrmrr r%r r'r$rr]r#s ` r& _patch_objectrwsn$ F||s L L L   ^^^F  3f(L&   r%c tturfd}nfd}|stdt|}|d\} } t || | |||||i } | | _|ddD]=\} } t || | |||||i } | | _| j| >| S)aPerform multiple patches in a single call. It takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use `DEFAULT` as the value if you want `patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when `patch.multiple` is used as a context manager. `patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments `spec`, `spec_set`, `create`, `autospec` and `new_callable` have the same meaning as for `patch`. These arguments will be applied to *all* patches done by `patch.multiple`. When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX` for choosing which methods to wrap. c"tSr@rprqsr&rVz!_patch_multiple..s6**r%cSr@r$rqsr&rVz!_patch_multiple..sr%z=Must supply at least one keyword argument with patch.multiplerrN) rBrvrRrqrYr r-r(r3) rr r%r r'r$r]r#rYrmrr. this_patchers ` r&_patch_multipler|s, F||s****   K     E1XNIs 3fh,G'G)99 3 IsD&( lB  '0 ##**<8888 Nr%c Xt|\} } t| | |||||||| S)a: `patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the `target` is patched with a `new` object. When the function/with statement exits the patch is undone. If `new` is omitted, then the target is replaced with an `AsyncMock if the patched object is an async function or a `MagicMock` otherwise. If `patch` is used as a decorator and `new` is omitted, the created mock is passed in as an extra argument to the decorated function. If `patch` is used as a context manager the created mock is returned by the context manager. `target` should be a string in the form `'package.module.ClassName'`. The `target` is imported and the specified object replaced with the `new` object, so the `target` must be importable from the environment you are calling `patch` from. The target is imported when the decorated function is executed, not at decoration time. The `spec` and `spec_set` keyword arguments are passed to the `MagicMock` if patch is creating one for you. In addition you can pass `spec=True` or `spec_set=True`, which causes patch to pass in the object being mocked as the spec/spec_set object. `new_callable` allows you to specify a different class, or callable object, that will be called to create the `new` object. By default `AsyncMock` is used for async functions and `MagicMock` for the rest. A more powerful form of `spec` is `autospec`. If you set `autospec=True` then the mock will be created with a spec from the object being replaced. All attributes of the mock will also have the spec of the corresponding attribute of the object being replaced. Methods and functions being mocked will have their arguments checked and will raise a `TypeError` if they are called with the wrong signature. For mocks replacing a class, their return value (the 'instance') will have the same spec as the class. Instead of `autospec=True` you can pass `autospec=some_object` to use an arbitrary object as the spec instead of the one being replaced. By default `patch` will fail to replace attributes that don't exist. If you pass in `create=True`, and the attribute doesn't exist, patch will create the attribute for you when the patched function is called, and delete it again afterwards. This is useful for writing tests against attributes that your production code creates at runtime. It is off by default because it can be dangerous. With it switched on you can write passing tests against APIs that don't actually exist! Patch can be used as a `TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods share a common patchings set. `patch` finds tests by looking for method names that start with `patch.TEST_PREFIX`. By default this is `test`, which matches the way `unittest` finds tests. You can specify an alternative prefix by setting `patch.TEST_PREFIX`. Patch can be used as a context manager, with the with statement. Here the patching applies to the indented block after the with statement. If you use "as" then the patched object will be bound to the name after the "as"; very useful if `patch` is creating a mock object for you. Patch will raise a `RuntimeError` if passed some common misspellings of the arguments autospec and spec_set. Pass the argument `unsafe` with the value True to disable that check. `patch` takes arbitrary keyword arguments. These will be passed to `AsyncMock` if the patched object is asynchronous, to `MagicMock` otherwise or to `new_callable` if specified. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. r!)rsr ) rrr r%r r'r$rr]r#rms r&rrsDV$F++FI  3f(L&   r%cVeZdZdZddZdZdZdZdZd Z d Z d Z d Z d Z dZdS) _patch_dicta# Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test. `in_dict` can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys. `in_dict` can also be a string specifying the name of the dictionary, which will then be fetched by importing it. `values` can be a dictionary of values to set in the dictionary. `values` can also be an iterable of `(key, value)` pairs. If `clear` is True then the dictionary will be cleared before the new values are set. `patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary:: with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()): ... `patch.dict` can be used as a context manager, decorator or class decorator. When used as a class decorator `patch.dict` honours `patch.TEST_PREFIX` for choosing which methods to wrap. r$Fc ||_t||_|j|||_d|_dSr@)in_dictdictrLr=clear _original)rrrLrr]s r&rLz_patch_dict.__init__\s> 6ll  6""" r%ct|tr||Stj|r||S||Sr@r0)rfs r&rOz_patch_dict.__call__esc a   *&&q)) )  &q ) ) 3//22 2%%a(((r%c@tfd}|S)Nc |i|S#wxYwr@r _unpatch_dictr\rrrs r&_innerz-_patch_dict.decorate_callable.._innernsV       %q$~"~~""$$$$""$$$$s 3A rrrrs`` r&r3z_patch_dict.decorate_callablem9 q % % % % %  % r%c@tfd}|S)NcK |i|d{V S#wxYwr@rrs r&rz3_patch_dict.decorate_async_callable.._innerzso       %Q^^^+++++++""$$$$""$$$$s <Arrs`` r&r2z#_patch_dict.decorate_async_callableyrr%c t|D]}}t||}|tjrLt |dr=A>B11CCc|j}|j}t| ||dS#t$r|D] }||||<YdSwxYwr@)rrrr=rP)rrrrWs r&rz_patch_dict._unpatch_dicts,>G - NN8 $ $ $ $ $ - - - - -'}  - - - -s6AAc<|j|dS)zUnpatch the dict.NF)rr)rr\s r&rYz_patch_dict.__exit__s! > %    ur%cl|}tj||Srf)rbr rgr3rhs r&riz_patch_dict.starts-!!%%d+++ r%c tj|n#t$rYdSwxYw|dddSrk)r rgrrRrYrs r&rlz_patch_dict.stops[   " ) )$ / / / /   44 }}T4...s " 00N)r$F)r r!r"r#rLrOr3r2r1rbrrrYrirlr$r%r&rr?s8)))       +++8 - - -/////r%rc |dS#t$rt|}|D]}||=YdSwxYwr@)rrPrq)rkeysrWs r&rrse  G}}  C    s !==cfttjD]}|dS)z7Stop all active patches. LIFO to unroll nested patches.N)rnr rgrl)rs r&_patch_stopallrs5&011 r%testzlt 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 round trunc floor ceil bool next fspath aiter zsizeof rzDadd sub mul matmul truediv floordiv mod lshift rshift and xor or pow c# K|] }d|zV dS)zi%sNr$r-ns r&rrs&77519777777r%c# K|] }d|zV dS)zr%sNr$rs r&rrs&55q555555r%>r__get____set__r __delete__ __format__r __missing__ __getstate__ __reversed__ __setstate__ __getformat__ __reduce_ex____getnewargs____subclasses____getinitargs____getnewargs_ex__c fd}||_|S)z:Turns a callable object (like a mock) into a real functionc|g|Ri|Sr@r$)rr\rr=s r&methodz_get_method..methods#tD&4&&&2&&&r%)r )r.r=rs ` r&rrs('''''FO Mr%ch|]}d|zS)rr$)r-rs r&r/r/s*    Hv   r%> __aexit__ __anext__ __aenter__ __aiter__>__del__r rLr __prepare__r__instancecheck____subclasscheck__c6t|Sr@)r__hash__rs r&rVrV2sV__T22r%c6t|Sr@)r__str__rs r&rVrV3sFNN400r%c6t|Sr@)r __sizeof__rs r&rVrV4sv0066r%cxt|jd|dt|S)N/)rBr rtrKrs r&rVrV5s;$t**"5^^8O8O8Q8Q^^TVW[T\T\^^r%)rrr __fspath__y?g?) __lt____gt____le____ge____int__r__len__rY __complex__ __float____bool__ __index__rcfd}|S)NcLjj}|tur|S|urdStSNT)__eq__rrNotImplemented)otherret_valrs r&rz_get_eq..__eq__Js1+0 ' ! !N 5==4r%r$)rrs` r&_get_eqrIs# Mr%cfd}|S)NcRjjturtS|urdStSNF)__ne__rrr)rrs r&rz_get_ne..__ne__Ts, ; ) 8 8N 5==5r%r$)rrs` r&_get_nerSs# Mr%cfd}|S)Ncjjj}|turtgSt|Sr@)__iter__rrrrrs r&rz_get_iter..__iter__]s1-2 g  88OG}}r%r$)rrs` r& _get_iterr\s# Or%cfd}|S)Ncjj}|turtt gStt |Sr@)rrr_AsyncIteratorrrs r&rz"_get_async_iter..__aiter__gs@.3 g  !$r((++ +d7mm,,,r%r$)rrs` r&_get_async_iterrfs$----- r%)rrrrc&t|t}|tur ||_dSt|}|||}||_dSt |}||||_dSdSr@)_return_valuesrwrr_calculate_return_value_side_effect_methodsr)rHrr.fixedreturn_calculatorr side_effectors r&_set_return_valuerws   tW - -E G#/33D99$((.. *(,,T22M *]400! r%ceZdZdZdZdS) MagicMixinc|tt|j|i||dSr@)_mock_set_magicsr rrL)rr\rs r&rLzMagicMixin.__init__sN . J%%.;;;; r%c ttz}|}t|ddX||j}t }||z }|D](}|t |jvrt||)|t t |jz }t |}|D]!}t||t||"dS)Nr.) _magicsrr5 intersectionr.rrBrvrrk MagicProxy)r orig_magics these_magics remove_magicsrUrs r&rzMagicMixin._mock_set_magicss 44 " 4$ / / ;&33D4FGGLEEM',6M& ) )DJJ///D%((($c$t***=&>&>> T ! ; ;E E5*UD"9"9 : : : : ; ;r%N)r r!r"rLrr$r%r&rrs2   ;;;;;r%rceZdZdZddZdS)rz-A version of `MagicMock` that isn't callable.FcZ||||dSr&r rr's r&r(z"NonCallableMagicMock.mock_add_spec2 D(+++ r%Nrr r!r"r#r(r$r%r&rrs.77      r%rceZdZdS)AsyncMagicMixinN)r r!r"r$r%r&rrsDr%rceZdZdZddZdS)ra MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. If you use the `spec` or `spec_set` arguments then *only* magic methods that exist in the spec will be created. Attributes and the return value of a `MagicMock` will also be `MagicMocks`. FcZ||||dSr&rr's r&r(zMagicMock.mock_add_specrr%Nrrr$r%r&rrs2        r%rc"eZdZdZdZddZdS)rc"||_||_dSr@r.r)rr.rs r&rLzMagicProxy.__init__s  r%c|j}|j}||||}t|||t ||||S)N)r.rr)r.rr;rkr)rrUrms r& create_mockzMagicProxy.create_mocksZ   " "/5 # 7 7q!!!&!U+++r%Nc*|Sr@)r )rr9rs r&rzMagicProxy.__get__s!!!r%r@)r r!r"rLr rr$r%r&rrsF""""""r%rceZdZedZedZedZfdZdZdZ dZ dZ d Z d Z dd Zd ZfdZxZS)rrrrcTtj|i|tjj|jd<d|jd<d|jd<t |jd<tt}t|jd<t|jd<tj tj ztjz|_d|_d |_ d|_n#t&$rYnwxYwd|_||jd <d |jd <t+|jd <i|jd<d|jd<dS)Nrr_mock_await_count_mock_await_args_mock_await_args_listr r+r-)r\r]r<r r rirjrd)superrLrrrrvrr _CODE_ATTRSr _CODE_SIGr6 CO_COROUTINE CO_VARARGSCO_VARKEYWORDSco_flags co_argcount co_varnamesco_posonlyargcountrPco_kwonlyargcountrr)rr\r] code_mockr@s r&rLzAsyncMockMixin.__init__sA$)&)))*1);)I o&-. )*,0 ()1: -.#[999 ,4 =)09 ,-    !$ %  !"  2  +,I ( (    D '( #$- j!$/ j!(- n%*, &'+/ '(((s C C C cdK|}t||fd}|xjdz c_||_|j||j}|t |r|t|s8 t|}n#t$rtwxYwt |r|n&t|r||i|d{V}n||i|}|tur|S|j tur|jS|j4t|jr|j|i|d{VS|j|i|S|jS)NTrr)rrrrr3rrEror StopIterationStopAsyncIterationrrrrr)r[r\r]rrr rs r&rz!AsyncMockMixin._execute_mock_call stVn$/// A ##E***!  V$$ 1 v&& 1-!&\\FF$----,-!((! L!$V,, 1%vt6v66666666000W$$  "' 1 1$ $   '"4#344 ?-T-t>v>>>>>>>>>#4#T4V44 4  s 3BBcX|}|jdkrd|jpdd}t|dS)zA Assert that the mock was awaited at least once. r Expected rHz to have been awaited.Nrrrrs r&rzAsyncMockMixin.assert_awaited4 sD  q Odo7OOOC %% % ! r%ch|}|jdks$d|jpdd|jd}t|dS)z@ Assert that the mock was awaited exactly once. rr"rH$ to have been awaited once. Awaited rNr#rs r&rz"AsyncMockMixin.assert_awaited_once= s\1$$9t8&99#/999C %% %%$r%cl|j)}td|dfd}t fd}j}||kr1t |t r|nd}t||dS)zN Assert that the last await was with the specified arguments. NzExpected await: z Not awaitedc8d}|S)Nawait)rrrs r&rz:AsyncMockMixin.assert_awaited_with.._error_messageP s"33D&3QQCJr%Tr)rrrrrr3r)r[r\r]rrrrrs `` @r&rz"AsyncMockMixin.assert_awaited_withG s ? "77fEEH !KH!K!K!KLL L       %%eT6N&E&E&EFF##DO44 X   *8Y ? ?IHHTE !1!122 =  r%c~|}|jdks$d|jpdd|jd}t||j|i|S)zi Assert that the mock was awaited exactly once and with the specified arguments. rr"rHr%r)rrrrrs r&rz'AsyncMockMixin.assert_awaited_once_withZ sl 1$$9t8&99#/999C %% %'t'8888r%c(|t||fd}t|tr|nd}fdjD}|s|t |vr)||}td|z|dS)zU Assert the mock has ever been awaited with the specified arguments. TrNc:g|]}|Sr$rrs r&r}z3AsyncMockMixin.assert_any_await..m s'FFFA$$$Q''FFFr%z%s await not found)rrr3rrrrr)r[r\r]rrrrrs @r&rzAsyncMockMixin.assert_any_awaitf s%%eT6N&E&E&EFF&x;;EFFFF1EFFF  HL$8$888">>tVLLO $6 98r%Fc2 | fd|D}td|Ddx}}t fd jD}|sT||vrN|d}ndd|D}t |dt|d j|dSt |}g}|D]=} ||#t$r||Y:wxYw|r t t|d |dS) a Assert the mock has been awaited with the specified calls. The :attr:`await_args_list` list is checked for the awaits. If `any_order` is False (the default) then the awaits must be sequential. There can be extra calls before or after the specified awaits. If `any_order` is True then the awaits can be in any order, but they must all appear in :attr:`await_args_list`. c:g|]}|Sr$rrs r&r}z4AsyncMockMixin.assert_has_awaits.. rr%c3DK|]}t|t|VdSr@rrs r&rz3AsyncMockMixin.assert_has_awaits.. s1NNAZ95M5MNaNNNNNNr%Nc3BK|]}|VdSr@rrs r&rz3AsyncMockMixin.assert_has_awaits.. s1SSt11!44SSSSSSr%zAwaits not found.z,Error processing expected awaits. Errors: {}c@g|]}t|tr|ndSr@rrs r&r}z4AsyncMockMixin.assert_has_awaits.. rr%rrz not all found in await list) rrrrrrqrrRr3rr) r[rrrr all_awaitsrrrrs @r&rz AsyncMockMixin.assert_has_awaitst s99995999NNNNNPTUUUSSSSd>RSSSSS  z))=1GG ,-3V$7$7-5$7$7$7.8.8%66!*5!1!166#366  F*%%   ' 'D '!!$'''' ' ' '  &&&&& '   49)4D4D4D4DF   s:CC21C2ch|}|jdkr$d|jpdd|jd}t|dS)z9 Assert that the mock was never awaited. rr"rHz# to not have been awaited. Awaited rNr#rs r&rz!AsyncMockMixin.assert_not_awaited s\  q 9t8&99#/999C %% % ! r%c|tj|i|d|_d|_t |_dS)0 See :func:`.Mock.reset_mock()` rN)rrrrrrrr\r]r@s r&rzAsyncMockMixin.reset_mock sB D+F+++({{r%r)r r!r"rrrrrLrrrrrrrrr __classcell__r@s@r&rrs&&}55K%%l33J**+<==O 0 0 0 0 0D'!'!'!R&&&&&&>>>& 9 9 9   ++++Z&&&+++++++++r%rceZdZdZdS)r aY Enhance :class:`Mock` with features allowing to mock an async function. The :class:`AsyncMock` object will behave so the object is recognized as an async function, and the result of a call is an awaitable: >>> mock = AsyncMock() >>> iscoroutinefunction(mock) True >>> inspect.isawaitable(mock()) True The result of ``mock()`` is an async function which will have the outcome of ``side_effect`` or ``return_value``: - if ``side_effect`` is a function, the async function will return the result of that function, - if ``side_effect`` is an exception, the async function will raise the exception, - if ``side_effect`` is an iterable, the async function will return the next value of the iterable, however, if the sequence of result is exhausted, ``StopIteration`` is raised immediately, - if ``side_effect`` is not defined, the async function will return the value defined by ``return_value``, hence, by default, the async function returns a new :class:`AsyncMock` object. If the outcome of ``side_effect`` or ``return_value`` is an async function, the mock async function obtained when the mock object is called will be this async function itself (and not an async function returning an async function). The test author can also specify a wrapped object with ``wraps``. In this case, the :class:`Mock` object behavior is the same as with an :class:`.Mock` object: the wrapped object may have methods defined as async function functions. Based on Martin Richard's asynctest project. Nrr$r%r&r r s''''r%r c$eZdZdZdZdZdZdS)_ANYz2A helper object that compares equal to everything.cdSrr$rrs r&rz _ANY.__eq__ str%cdSrr$r<s r&rz _ANY.__ne__ sur%cdS)Nzr$rs r&rz _ANY.__repr__ swr%N)r r!r"r#rrrr$r%r&r:r: sG88r%r:cd|z}d}dd|D}dd|D}|r|}|r |r|dz }||z }||zS)Nz%s(%%s)rz, c,g|]}t|Sr$)repr)r-r\s r&r}z*_format_call_signature.. s7773T#YY777r%c"g|] \}}|d| S)=r$)r-rWrs r&r}z*_format_call_signature.. s4#-3333r%)rorY)r.r\r]rformatted_args args_string kwargs_strings r&rr s$GN))77$77788KII17M%$(  # d "N-' ^ ##r%ceZdZdZ ddZ ddZd ZejZd Z d Z d Z d Z e dZe dZdZdZdS)ra A tuple for holding the results of a call to a mock, either in the form `(args, kwargs)` or `(name, args, kwargs)`. If args or kwargs are empty then a call tuple will compare equal to a tuple without those values. This makes comparisons less verbose:: _Call(('name', (), {})) == ('name',) _Call(('name', (1,), {})) == ('name', (1,)) _Call(((), {'a': 'b'})) == ({'a': 'b'},) The `_Call` object provides a useful shortcut for comparing with call:: _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) If the _Call has no name then it will match any name. r$rNFTcd}i}t|}|dkr|\}}}n~|dkr<|\} } t| tr| }t| tr| }nD| }nA| | }}n<|dkr6|\}t|tr|}nt|tr|}n|}|rt|||fSt||||fS)Nr$rr)rr3rvrrr ) r rr.rr from_kallr\r]_lenfirstseconds r&r z _Call.__new__ s5zz 199!& D$ QYY!ME6%%% -fe,,$!DD#FF$ff QYYFE%%% E5))   6==tVn55 5}}S4v"6777r%c0||_||_||_dSr@)rr_mock_from_kall)rrr.rrrJs r&rLz_Call.__init__5 s"(r%cr t|}n#t$r tcYSwxYwd}t|dkr|\}}n|\}}}t|ddr#t|ddr|j|jkrdSd}|dkrdi}}n|dkr|\}}}n|dkr?|\} t | t r| }i}nit | tr| }di}}nMd}| }nH|dkr@|\} } t | tr!| }t | t r| i}}n d| }}n| | }}ndS|r||krdS||f||fkS) NrrrFrr$rIr)rrrr5rr3rrrv) rr len_other self_name self_args self_kwargs other_name other_args other_kwargsrrLrMs r&rz _Call.__eq__< s "E II " " "! ! ! ! " t99>>%) "I{{04 -Iy+ D.$ / / GE>SW4X4X %);;;5 >>')2 JJ !^^38 0J LL !^^FE%'' %" ! E3'' %" +-rL  $ !^^!ME6%%% 9" fe,,:/5r JJ/16 JJ+0&L 5  y005L)i-EEEs &&c|jtd||fdS|jdz}t|j||f||S)Nrr9rrrrrs r&rOz_Call.__call__t sN ? ""dF+$777 7%dotV44MMMMr%cn|jt|dS|jd|}t||dS)NF)r.rJrS)r.rrJrY)rrr.s r&rz_Call.__getattr__| sD ? "de444 4///440$tu====r%cb|tjvrtt||Sr@)rrrvrP__getattribute__)rrs r&r\z_Call.__getattribute__ s+ 5> ! ! %%dD111r%cHt|dkr|\}}n|\}}}||fS)Nrrrs r&_get_call_argumentsz_Call._get_call_arguments s2 t99>>LD&&!% D$V|r%c6|dSNrr^rs r&r\z _Call.args ''))!,,r%c6|dS)Nrrars r&r]z _Call.kwargs rbr%c|js%|jpd}|drd|z}|St|dkrd}|\}}n+|\}}}|sd}n |dsd|z}nd|z}t |||S)Nrr9zcall%srzcall.%s)rOrr+rr)rr.r\r]s r&rz_Call.__repr__ s# ?,fDt$$ '$K t99>>DLD&&!% D$ '__T** ' 4'$%dD&999r%cg}|}|%|jr|||j}|%tt |S)zFor a call object that represents multiple calls, `call_list` returns a list of all the intermediate calls as well as the final call.)rOr3rrrn)rvalsrs r& call_listz_Call.call_list sW$ # E"""&E$(((r%)r$rNFT)r$NNFT)r r!r"r#r rLrrrrOrr\r^rr\r]rrgr$r%r&rr s$:?8888@>C))))2F2F2Fj]FNNN>>>222 --X---X-:::* ) ) ) ) )r%r)rJc t|rt|}t|t}t|rt d|dt |}d|i} |rd|i} n|i} | r|rd| d<|st || |t} tj |ri} nL|r|rtdt} n1t|st} n|r|rt|st} | d |}|} |d } | d||| |d | } t|t"r$|rt%| |} n#t'| |} nt)|| ||| |s | |j|<|r|sd |vrt-||dd | | _t1|D]"} t3| r t5|| }n#t6$rY1wxYwd|i}|rd|i}t|t"st9||| | |}|| j| <n| }t|t"r| j}t=|| |}||d<t?|rt}nt}|d|| | |d|}|| j| <||_t)|||t|t"rtA| | |$| S)aCreate a mock object using another object as a spec. Attributes on the mock will use the corresponding attribute on the `spec` object as their spec. Functions or methods being mocked will have their arguments checked to check that they are called with the correct signature. If `spec_set` is True then attempting to set attributes that don't exist on the spec object will raise an `AttributeError`. If a class is used as a spec then the return value of the mock (the instance of the class) will have the same spec. You can use a class as the spec for an instance object by passing `instance=True`. The returned mock will only be callable if instances of the mock are callable. `create_autospec` will raise a `RuntimeError` if passed some common misspellings of the arguments autospec and spec_set. Pass the argument `unsafe` with the value True to disable that check. `create_autospec` also takes arbitrary keyword arguments that are passed to the constructor of the created mock.z'Cannot autospec a Mock object. [object=r*r r NTrzJInstance can not be True when create_autospec is mocking an async functionr.r)rrrr.rr9)rerTrr)rr.rr)rdr$)!rsrBr3r2rr>rr=rr6isdatadescriptorrr rorryr[rIrrrfrr rr0rr5rPrMrH _must_skiprrk)r r rerrTrr]is_type is_async_funcr^r]rrHrUrrrrd child_klasss r&r r s.~~Dzzt$$G5 4*. 4 4 455 5"4((MtnGt$ ,8,'+#$ &f%%% NN6 E%% % %  ? >?? ? t__%$ %X%&8&>&>%$ KK & &EI 5 (W  ( (& ( (D$ &&8  .'d33DD!$--DDtWh7778(,u%FxFN&$@$@+D(T26FFFT1&1& U     tU++HH    H (#  , (+F(M22 AXxuhGGC),D  & &F$ .. #"488I"+F; "8,, (' ' +(V%5*0(( &((C*-D  &*{}}C  Xsi @ @ @ @ c= ) ) & D% % % % KsG$$ G10G1cDt|ts|t|divrdS|j}|jD]f}|j|t}|tur,t|ttfrdSt|tr|cSdS|S)z[ Return whether we should skip the first argument on spec's `entry` attribute. rvF) r3rBr5r@rurvrwrrNrMrI)r rUrkrrs r&rjrjL s dD ! ! GD*b11 1 15~  ##E733 W    f|[9 : : 55  . . NNN55 Nr%ceZdZ ddZdS)rMFNcZ||_||_||_||_||_||_dSr@)r idsr rrer.)rr r rr.rqres r&rLz_SpecState.__init__j s0       r%)FNNNF)r r!r"rLr$r%r&rMrMh s.48/4r%rMc|t|trtj|Stj|Sr@)r3bytesioBytesIOStringIO) read_datas r& _to_streamrx s4)U##&z)$$${9%%%r%c x t}|dg fd} fd} fd fd fd} fd}tdddl}tt t |jt t |jat2ddl}tt t |j a |td t }tt  j _ d j_ d j_ d j_ d j_ | j_ d < d  j_| j_ j_| j_| j_ fd }||_ |_ |S)a A helper function to create a mock to replace the use of `open`. It works for `open` called directly or used as a context manager. The `mock` argument is the mock object to configure. If `None` (the default) then a `MagicMock` will be created for you, with the API limited to methods or attributes available on standard file handles. `read_data` is a string for the `read`, `readline` and `readlines` of the file handle to return. This is an empty string by default. NcZjj jjSdj|i|Sr`) readlinesrr\r]_statehandles r&_readlines_side_effectz)mock_open.._readlines_side_effect s7   ( 4#0 0"vay"D3F333r%cZjj jjSdj|i|Sr`)readrr|s r&_read_side_effectz$mock_open.._read_side_effect s4 ; # /;+ +vay~t.v...r%c?VKEd{V dj|i|VNTr)readline)r\r]_iter_side_effectr}s r&_readline_side_effectz(mock_open.._readline_side_effect sT$$&&&&&&&&& 6$&)$d5f55 5 5 5 6r%c3bKjj jjVdD]}|VdSr)rr)liner}r~s r&rz$mock_open.._iter_side_effect sU ? ' 3 3o2222 31I  DJJJJ  r%c^jj jjStdSr`)rrr)r}r~sr&_next_side_effectz$mock_open.._next_side_effect s) ? ' 3?/ /F1Ir%c0dSr@)close)exctypeexcinstexctbr~s r&_exit_side_effectz$mock_open.._exit_side_effect s r%ropen)r.r )r rctd<jjdkrd<dj_tS)Nrr)rxrrr)r\r]rr}r~rws r& reset_datazmock_open..reset_data sMy))q ? &&) 3 3--//F1I*0)FO 'r%)rx file_spec_iorqrr0 TextIOWrapperunionru open_specrrrbrwriterrr{rrrrY) rHrw _read_datarrrrrrrrr}r~s ` @@@@r&rr s;I&&J$ F444444 ////// 666666   S!23344::3s3;?O?O;P;PQQRR  S]]++,,  |f9555 I & & &F$*F! $FL#FK#'FO $(F!/FK%%''F1I"()FO#9F "3FO"3FO"3FO"DD Kr%c&eZdZdZdZddZdZdS)raW A mock intended to be used as a property, or other descriptor, on a class. `PropertyMock` provides `__get__` and `__set__` methods so you can specify a return value when it is fetched. Fetching a `PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock with the value being set. c tdi|S)Nr$)r)rr]s r&r;zPropertyMock._get_child_mock s""6"""r%Nc|Sr@r$)rr9obj_types r&rzPropertyMock.__get__ s tvv r%c||dSr@r$)rr9r]s r&rzPropertyMock.__set__ s S r%r@)r r!r"r#r;rrr$r%r&rr sP###r%rc^eZdZdZfdZedfd ZfdZdZfdZ eddZ d Z xZ S) ThreadingMixinNc t|dtr|dj|d<n8t|dtr|dj|d<t jdi|S)Nrtimeoutrr$)r3rwr_mock_wait_timeoutrr;)rrr@s r&r;zThreadingMixin._get_child_mock s bffX&& 7 7 AxL;ByMM }--~ > > A}-@ByM&uww&,,,,,r%rctj|i||tur|j}t j|jd<g|jd<t j|jd<||jd<dS)N _mock_event_mock_calls_events_mock_calls_events_lockr)rrL_timeout_unsetDEFAULT_TIMEOUT threadingEventrvLock)rrr\r]r@s r&rLzThreadingMixin.__init__ s{$)&))) n $ $*G'0'8'8 m$.0 *+3<>3C3C /0.5 *+++r%ctj|i|tj|jd<g|jd<dS)r4rrN)rrrrrvr5s r&rzThreadingMixin.reset_mock sH D+F+++'0'8'8 m$.0 *+++r%c|j5|jD] \}}}||f||fkr|ccdddS!tj}|j|||fdddn #1swxYwY|Sr@)rrrrr3)r expected_argsexpected_kwargsr\r]event new_events r& __get_eventzThreadingMixin.__get_event s   ) X X'+'> ! !#fe&>m_%EEE LL X X X X X X X XE!))I  # * *M?I+V W W W  X X X X X X X X X X X X X X X sA-1A--A14A1ctj|i|}|||}||j|Sr@)rr_ThreadingMixin__get_eventrr)rr\r] ret_value call_eventr@s r&rzThreadingMixin._mock_call s^&EGG&777 %%dF33  r%c|tur|j}|j|s|jpdd|d}t |dS)zWait until the mock object is called. `timeout` - time to wait for in seconds, waits forever otherwise. Defaults to the constructor provided timeout. Use None to block undefinetively. rrHz was not called before timeout(z).N)rrrwaitrr)rrrs r&wait_until_calledz ThreadingMixin.wait_until_called ss n $ $-G$$W$55 &o/++&+++C %% % & &r%c|||}||js(|||}t |ddS)zWait until the mock object is called with given args. Waits for the timeout in seconds provided in the constructor. rz call not foundN)rrrrr)rr\r]rrs r&wait_until_any_call_withz'ThreadingMixin.wait_until_any_call_with. sk   v..zz$"9z:: F">>tVLLO O!D!D!DEE E F Fr%) r r!r"rr;rrLrrrrrr6r7s@r&rr sO-----'5666666611111,: & & & & &FFFFFFFr%rceZdZdZdS)r a A mock that can be used to wait until on calls happening in a different thread. The constructor can take a `timeout` argument which controls the timeout in seconds for all `wait` calls of the mock. You can change the default timeout of all instances via the `ThreadingMock.DEFAULT_TIMEOUT` attribute. If no timeout is set, it will block undefinetively. Nrr$r%r&r r 9 s   Dr%r c4d|_t|D]} t||}n#t$rY wxYwt |t s:t |j|trh|j |urt|dS)aDisable the automatic generation of child mocks. Given an input Mock, seals it to ensure no further mocks will be generated when accessing an attribute that was not already defined. The operation recursively seals the mock passed in, meaning that the mock itself, any mocks generated by accessing one of its attributes, and all assigned mocks without a name or spec will be sealed. TN) rr0r5rPr3r rrwrMrr)rHrr s r&rrI sDD   d##AA    H !_--   a&**400* = =    % % GGG  s + 88ceZdZdZdZdZdS)rz8 Wraps an iterator in an asynchronous iterator. ct||_tt}tj|_||jd<dS)Nrr<)iteratorr rr6CO_ITERABLE_COROUTINErrv)rrrs r&rLz_AsyncIterator.__init__e s6  #X666 $: $- j!!!r%c^K t|jS#t$rYnwxYwtr@)rrrr rs r&rz_AsyncIterator.__anext__k sA  && &    D   s  %%N)r r!r"r#rLrr$r%r&rra s<... !!!!!r%rrr)NFNNN)FFNN)Nr)__all__rr9rtr6rrZrbuiltinstypesrrr unittest.utilr functoolsrrrrHr backportsrrrr0rPr rr r:r>r2rErJrVrfrarorsryrrrrrrrrrrMISSINGrDELETEDrNrrrqrrrrr rvrrP frozensetrjrrGrrrrrr rsrwr|rrrrrmultiplestopallr6 magic_methodsrnumericsrorZinplaceright _non_defaultsrrr_sync_async_magics _async_magicsrrirrrrrrrrrrrrrrrrrQrLrrr r:rrrrrrr rjrMrBrrIrrrxrr TIMEOUT_UNSETrrr rrr$r%r&rs  (  2222222222######$$$$$$$$******CCCCCyCCC I Hcc(mm H H H   @@@222    F # # # #   &&&   4.."."."b>>>6))) ) ) ) ) )f ) ) )         9;;         &********(6      6   ^ <^ <^ <^ <^       :         j        D   ,""""""""$c(mm G ggh&7>> ? ? N+N+N+N+N+TN+N+N+b((((((((V     6    dff$$$$v)v)v)v)v)Ev)v)v)r uuCGK*/KKKKK\8         DD     &&&SSSSl4$'EFEFEFEFEFTEFEFEFP      NJ    0!!!!!!!!!!s%D--D87D8