fH`dZddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z ddlmZddlmZmZddlmZGdd eZd eeDZd ZeZd Zd ZdZdZdZ dZ!dydZ"dZ#dZ$dZ%dZ&dydZ'dZ(dZ)dZ*Gdde+Z,Gdde+Z-e-Z.e.j/Z/e.j0Z1e.j2Z3hd Z4d!Z5Gd"d#e6Z7d$Z8Gd%d&e+Z9Gd'd(e+Z:Gd)d*e:Z;ej<e;j=Z>Gd+d,e6Z?d-Z@Gd.d/e:ZAGd0d1eAe;ZBd2ZCGd3d4e+ZDd5ZEe/dddddfdd6d7ZF dzd8ZGe/dddddfdd6d9ZHGd:d;e+ZId<ZJd=ZKeFeH_+eIeH_LeGeH_MeKeH_Nd>eH_Od?ZPd@ZQdARdBeQSDZTdARdCeQSDZUhdDZVdEZWdFdARePeQeTeUgSDZXhdGZYdHhZZeYeZzZ[eXeVzZ\e\e[zZ]hdIZ^dJdKdLdMdNZ_e`e`e`e`dOddddPdQd dOddR ZadSZbdTZcdUZddVZeebecedeedWZfdXZgGdYdZe:ZhGd[d\ehe;ZiGd]d^ehZjGd_d`eheBZkGdadbe:ZlGdcdde:ZmGdedfemejeBZnGdgdhe+ZoeoZpdiZqGdjdkerZsesdlZt d{dd6dmZudnZvGdodpe+ZwexeuexepjyfZzda{da|dqZ}d|dsZ~GdtdueBZdvZGdwdxZdS)})Mock MagicMockpatchsentinelDEFAULTANYcallcreate_autospec AsyncMock FILTER_DIRNonCallableMockNonCallableMagicMock mock_open PropertyMocksealN)iscoroutinefunction)CodeType ModuleType MethodType) safe_repr)wrapspartial)RLockceZdZdZdS)InvalidSpecErrorz8Indicates that an invalid value was used as a mock spec.N__name__ __module__ __qualname____doc__4/opt/alt/python311/lib64/python3.11/unittest/mock.pyrr)sBBBBr"rc<h|]}|d|S_ startswith).0names r# r+-s) 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_objr65sgji&@&@usJ'c:&& s # # ?w':3'?'??r"cFt|ddrt|SdS)N__code__F)r1r)funcs r#_is_async_funcr:=s)tZ&&"4(((ur"cFtt|tSN) issubclasstyper r4s r#r.r.Ds d3ii 1 11r"ct|tp)t|tot|tSr<)r/ BaseExceptionr>r=r4s r# _is_exceptionrAJs63 && A3@*S-"@"@r"c^t|trt|dr|jS|SNmock)r/ FunctionTypesr0rDr4s r# _extract_mockrFQs3#}%%'#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) r/r>__init__ classmethod staticmethodr-rE__call__AttributeErrorrr2 signature ValueError)r9 as_instanceeat_selfsig_funcs r#_get_signature_objectrRZs $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)selfargskwargssigs r#checksigz"_check_signature..checksig $!&!!!!!r")rR_copy_func_detailsr>_mock_check_sig __signature__)r9rD skipfirstinstancer[rZs @r#_check_signaturerb}sr h : :C {ID#"""""tX&&&!)DJJ"DJJr"c pdD]2} t||t||##t$rY/wxYwdS)N)rr __text_signature__r __defaults____kwdefaults__)setattrr1rL)r9funcopy attributes r#r]r]sa   GYi(@(@ A A A A    D  s & 33ct|trdSt|tttfrt |jSt|dddSdS)NTrKF)r/r>rJrIr _callabler-r1r4s r#rkrks^#tt# k:>??'&&&sJ%%1t 5r"c<t|ttfvSr<)r>listtupler4s r#_is_listros 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.rKNTF)r/r>r1__mro____dict__get)r5bases r#_instance_callablerusn 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<rU)rXrYrZs r#r[z _set_signature..checksigr\r"rh) _checksig_rDzYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs))r/r>rRr]r isidentifierexec _setup_func) rDoriginalrar`resultr9r[r*contextsrcrhrZs @r#_set_signaturers 8T**I "8Xy A AF ~ ID#"""""tX&&&  D     %t44G $&* +C #wdmGs### 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_withrXrYrDs 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_valuer.)retrhrDs r#rz_setup_func..reset_mockso({{&[[ " S ! ! #++ NN       ++r"Fr)rDcalled call_count call_argsrcall_args_listrrr side_effect_mock_childrenrrrrrrrrr__mock_delegate) rhrDrZrrrrrrrrs `` r#r{r{sGL88888333337777788888=====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<)r1rD)attrrXrYrDs 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_listrgr)rDrris` r#_setup_async_mockrs +9DDDO$;;D 99999, > >  i)! >r"c$d|ddz|kS)N__%s__r!r*s r# _is_magicrs d1R4j D ((r"c$eZdZdZdZdZdZdS)_SentinelObjectz!A unique, named, sentinel object.c||_dSr<rrWr*s r#rHz_SentinelObject.__init__"s  r"cd|jzSNz sentinel.%srrWs r#__repr__z_SentinelObject.__repr__%ty((r"cd|jzSrrrs r# __reduce__z_SentinelObject.__reduce__(rr"N)rrrr rHrrr!r"r#rr sG''))))))))r"rc$eZdZdZdZdZdZdS) _SentinelzAAccess attributes to return a named object, usable as a sentinel.ci|_dSr<) _sentinelsrs r#rHz_Sentinel.__init__.s r"cl|dkrt|j|t|S)N __bases__)rLr setdefaultrrs r# __getattr__z_Sentinel.__getattr__1s3 ;   ))$0E0EFFFr"cdS)Nrr!rs r#rz_Sentinel.__reduce__7szr"N)rrrr rHrrr!r"r#rr,sJKKGGG 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<)rr1)rWr* _the_namerZs r#_getz"_delegating_property.._getLs/! ;4++ +sD!!!r"cR|j}| ||j|<dSt|||dSr<)rrrrg)rWvaluer*rrZs r#_setz"_delegating_property.._setQs9! ;',DM) $ $ $ Cu % % % % %r")_allowed_namesaddproperty)r*rrrs r#_delegating_propertyrIset4I """" $y&&&& D$  r"ceZdZdZdZdS)rct|tst||St|}t|}||krdSt d||z dzD]}||||z}||krdSdS)NFrT)r/rm __contains__lenrange)rWr len_valuelen_selfisub_lists r#rz_CallList.__contains__^s%&& 2$$T511 1JJ t99 x  5q(Y.233  AAa kM*H5  tt!ur"cDtjt|Sr<)pprintpformatrmrs r#rz_CallList.__repr__ls~d4jj)))r"N)rrrrrr!r"r#rr\s2   *****r"rct|}t|sdS|js|js|j|jdS|}|||urdS|j}||r||_||_|r||_||_dS)NFT)rFr.rrrr)parentrr*new_name_parents r#_check_and_set_parentrps % E U # #u  U1   '   +uG   e  5*  (!''  # 4r"ceZdZdZdZdS) _MockIterc.t||_dSr<)iterr5)rWr5s r#rHz_MockIter.__init__s99r"c*t|jSr<)nextr5rs r#__next__z_MockIter.__next__sDH~~r"N)rrrrHrr!r"r#rrs2r"rceZdZeZdZdZdS)BaseNcdSr<r!rWrXrYs r#rHz Base.__init__s r")rrrrrrrHr!r"r#rrs/      r"rceZdZdZeZdZ 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`cz|f}t|ts]tj|g|Ri|j}|d|d}|t |r t|f}t|j|d|j i}tt| |}|S)Nspec_setspecr ) r=AsyncMockMixin _MOCK_SIG bind_partial argumentsrsr6r>rr _safe_superr __new__)clsrXkwbases bound_argsspec_argnewras r#rzNonCallableMock.__new__s#~.. ."/AdAAAbAAKJ!~~j*..2H2HIIH# h(?(?#'-3<CK(@AA44<rRrr) rWrrrrr&r(r*rresrrs r#rzNonCallableMock._mock_add_specs' T " " T"#R#R#R#RSS S  II * *D"74t#<#<== *##D)))  HTNN $%% )" "4jj '(99FFC!nc!fOt99D="- (&5"#$(!#/   r"c|j}|j |jj}|tur%|j||d}||_|S)N()rr)rrrrr_get_child_mock)rWrs r#__get_return_valuez"NonCallableMock.__get_return_values]%   *%2C '>>d.6&& D'C!$D  r"cb|j||j_dS||_t||dddS)Nr/)rrrr)rWrs r#__set_return_valuez"NonCallableMock.__set_return_value%s>   */4D  , , ,&+D # !$tT : : : : :r"z1The value to be returned when the mock is called.c<|jt|S|jSr<)r&r>rs r# __class__zNonCallableMock.__class__1s   #:: r"rrrrrc|j}||jS|j}|It|s:t |t s%t |st |}||_|Sr<)rrrcallabler/rrA)rW delegatedsfs r#__get_side_effectz!NonCallableMock.__get_side_effect>sj'  ) )  " N8B<>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs)c8|ddS)Nr.)count)entrys r#z0NonCallableMock.configure_mock..sq1D1Dr")keyrIN)sorteditemssplitpopr1rg)rWrYargvalrXfinalr5rKs r#rzNonCallableMock.configure_mockrsv||~~$E#D FFF % %HC 99S>>DHHJJEC * *c5)) C $ $ $ $ % %r"c |dvrt||j%||jvs |tvrtd|znt|rt||js:|jr ||jvr*|drt|d|dt j5|j |}|turt||Cd}|j t|j |}| |||||}||j|<nt|trv 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%)rLr) _all_magicsrrr(r _lockrrsrDrr1r1r/rCr rrrarr*rrr)rWr*r}r target_names r#rzNonCallableMock.__getattr__s 4 4 4 && &   +4---1D1D$%F%MNNN2E t__ ' && &  N$*< NDL^@^@^OPP N$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++B F:9,E&%F:&;F!! F::F>F>cn|jg}|j}|}d}|dgkrd}|7|}||j|zd}|jdkrd}|j}|7tt |}|jpd}t |dkr|ddvr|dz }||d<d|S)NrIr/r rDr)r/z().r)rrr,rmreversedrrjoin)rW _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 )rDzmock.z name=%rz spec=%rz spec_set=%r)rir&r'rr>rA)rWr* 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!)rD)r)m_namem_values r# z+NonCallableMock.__dir__..s1(((&vwh&& &&&r"c<g|]}|d|Sr%r'r)es r#rrz+NonCallableMock.__dir__..s)CCC1c1B1BCQCCCr"cZg|](}|drt|&|)Sr%)r(rrts r#rrz+NonCallableMock.__dir__..sE###1c1B1B#q\\#Q###r") r object__dir__r)r+r>rmrrrrOrNset)rWextras from_type from_dictfrom_child_mockss r#rxzNonCallableMock.__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!)rXrr|rWs r#rLz-NonCallableMock.__setattr__.. s!HHT,GD,G,G,GB,G,Gr"r6rIz Cannot set )rrw __setattr__r'r)rrrL_unsupported_magicsr_r.rgr> _get_methodrrr&r r0ri)rWr*rmsg mock_namer|s` @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<) r_r>rrdelattrrrs_missingrr __delattr__rDrL)rWr*r5s r#rzNonCallableMock.__delattr__!s ;  44::+>#>#> DJJ % % %4=((!%%dH55 4=  . . : :4 @ @ @ @ H__ && & h  #D)$,D!!!r"c6|jpd}t|||SrC)r_format_call_signaturerWrXrYr*s r#_format_mock_call_signaturez+NonCallableMock._format_mock_call_signature3s (&%dD&999r"rcdd}|||}|j}|j|}||||fzS)Nz0expected %s not found. Expected: %s Actual: %s)rr)rWrXrYactionmessageexpected_stringr actual_strings r#_format_mock_failure_messagez,NonCallableMock._format_mock_failure_message8sDF::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. Nr/r rI)r(replacerPrrsr/rCrF)rWr*rZnameschildrenrFs r#_get_call_signature_from_namez-NonCallableMock._get_call_signature_from_name@s (' ' 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 ) r/rnrrr(rVrrXrY TypeErrorwith_traceback)rW_callrZr*rXrY bound_callrus r# _call_matcherzNonCallableMock._call_matcheras 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 'rDz"' to not have been called. Called  times.Nrr _calls_reprAssertionErrorrWrs r#rz!NonCallableMock.assert_not_called|s^ ?a   o///ooo&&(((*C!%% % r"cR|jdkrd|jpdz}t|dS)z6assert that the mock was called at least once rz"Expected '%s' to have been called.rDN)rrrrs r#rzNonCallableMock.assert_calleds; ?a  7O-v/C %% % r"c|jdks8d|jpdd|jd|}t|dS)z3assert that the mock was called only once. rrrDz#' to have been called once. Called rNrrs r#rz"NonCallableMock.assert_called_onces^!###o///ooo&&(((*C!%% % $#r"ctj/}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: z Actual: c4}|Sr<rrrXrYrWs r#_error_messagez:NonCallableMock.assert_called_with.._error_messages33D&AACJr"Ttwo)rrrr_Callr/ Exception)rWrXrYexpectedactual error_messagercauses``` 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.rrrDz' to be called once. Called r)rrrrrrWrXrYrs r#rz'NonCallableMock.assert_called_once_withsn!###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)crWs r#rrz4NonCallableMock.assert_has_calls..'999aD&&q))999r"c3DK|]}t|t|VdSr<r/rrts r# z3NonCallableMock.assert_has_calls..1FFAZ9-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<rrts r#rrz4NonCallableMock.assert_has_calls..;$7$7$7()*4Ay)A)A$KAAt$7$7$7r" Expected: z Actual)prefixrIrDz does not contain all of z in its call list, found z instead) rrrformatrrrstriprmremoverNr,rrn) rWcalls 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%II!*5!1!1I''z'::AA#FFII  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#rrz3NonCallableMock.assert_any_call..s'EEEA$$$Q''EEEr"z%s call not found)rrr/rr _AnyComparerrrrWrXrYrrrrs` 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*rIr/rr*rr!)r rirLrsrrr r>r=r_async_method_magicsr_all_sync_magicsr) CallableMixinr r rrq)rWrrirr_typeklasss r#r1zNonCallableMock._get_child_mocks[   ,,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: rI)rr)rWrs r#rzNonCallableMock._calls_reprs6 2;F;;i88;;;;r") NNNNNNr NFNFF)FFr<)r)r)/rrrr rr`rrHrr#r"_NonCallableMock__get_return_value"_NonCallableMock__set_return_value"_NonCallableMock__return_value_docrrr6rrrrrr!_NonCallableMock__get_side_effect!_NonCallableMock__set_side_effectrrrrrirrxrrrrrrrrrrrrrr1rr!r"r#r r s** EGGE   ">BEI   ;;;M8.0B.00L  X " !( + +F%%l33J$$[11I))*:;;N%%l33J   ***(,.?@@K$u%$$$$$<%%%,---`###6   *NNN$$5$5$5N---$::: BBBBB6&&&&&&&&&>>>, 8 8 8****Z    ###L < < < < < .5s1$HfF"r"TF)allzip)rWitemrs r#rz_AnyComparer.__contains__2s^  E(+D%(8(8 tt   ur"N)rrrr rr!r"r#rr-s-r"rc||St|r|St|r|S t|S#t$r|cYSwxYwr<)rArkrrr4s r#r=r==sk { S ~~ Cyy  s7 AAc HeZdZddedddddddf dZdZdZdZdZdZ dS) rNr c x||jd<tt|j||||||| | fi| ||_dS)Nr)rrrrrHr) rWrrrrr*rrrrrrYs r#rHzCallableMixin.__init__Nsa/; *+1 M4((1 %x K  39   'r"cdSr<r!rs r#r^zCallableMixin._mock_check_sigZs r"cP|j|i||j|i||j|i|Sr<)r^_increment_mock_call _mock_callrs r#rKzCallableMixin.__call___sK d-f---!!426222t////r"c|j|i|Sr<)_execute_mock_callrs r#rzCallableMixin._mock_callgs&t&7777r"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)NTrrr/r rI) rrrrrr,rrrrrr) rWrXrYrdo_method_callsmethod_call_namemock_call_name is_a_callrthis_mock_callrgs r#rz"CallableMixin._increment_mock_calljs  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|jr|jjtur|jS|j |j|i|S|jSr<) rrArkrrrrrr)rWrXrYeffectr}s r#rz CallableMixin._execute_mock_calls!  V$$ 1 v&& 1f ((! L! 000W$$  "' 1 1$ $   %4#6#C7#R#R$ $   '#4#T4V44 4  r") rrrrrHr^rKrrrr!r"r#rrLs d$d!RT ' ' ' '   000888,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* will raise an AttributeError. 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#rrs5555r"rc@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_typosrsN 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)rrNrr.rgetterrir  new_callablercreate has_localrautospecrYadditional_patchers) rWrrir rrrr rrYrs r#rHz_patch.__init__sV  #'!! 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#rrz_patch.copy..,s-' ' ' AFFHH' ' ' r") rrrir rrrr rrYattribute_namer )rWpatchers r#rz _patch.copy%sq K49 K M4,dk   "&!4' ' "6' ' ' #r"ct|tr||Stj|r||S||Sr<r/r>decorate_classr2rdecorate_async_callabledecorate_callable)rWr9s r#rKz_patch.__call__2sc dD ! ! -&&t,, ,  &t , , 6//55 5%%d+++r"ct|D]q}|tjs"t ||}t |dsC|}t||||r|SNrK)r+r(r TEST_PREFIXr1r0rrg)rWrr attr_valuers r#rz_patch.decorate_class:sJJ 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_contextrupdater rr,rn)rWpatchedrXkeywargs extra_args exit_stackpatchingrRs r#decoration_helperz_patch.decoration_helperHs  ! # # #z#- + + ..x88*6OOC((((\W,,%%c*** E*%% %D" " " " # # # # # # # # # # # # # # # # # #sA8BB!$B!ctdrjStfdg_S)Nrc|||5\}}|i|cdddS#1swxYwYdSr<r&rXr"newargs newkeywargsr9r!rWs r#r!z)_patch.decorate_callable..patched]s''(,(022 55Kg{tW4 44 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s 155r0rr,rrWr9r!s``@r#rz_patch.decorate_callableWsv 4 % %  N ! !$ ' ' 'K t 5 5 5 5 5 5  5 "Fr"ctdrjStfdg_S)NrcK||5\}}|i|d{VcdddS#1swxYwYdSr<r)r*s r#r!z/_patch.decorate_async_callable..patchedns''(,(022 ;5Kg{!T7:k:::::::: ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s 9==r-r.s``@r#rz_patch.decorate_async_callablehsv 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 ) rrirrrrLKeyErrorr1 _builtinsr/rr)rWtargetr*r|locals r# get_originalz_patch.get_originalys~ 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=TruerKrrr*r/r0zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=Truer[z: as the patch target has already been mocked out. [target=r^r%rr\r])r_namez.Can't pass kwargs to a mock we aren't creatingr!)+r rrr rYrrr4rr6rr/r>r6r rror8r r=r rir r.rurQrboolrr1r temp_originalis_localrr _exit_stackrgrr r__exit__sysexc_info)rWr rrr rYrr|r5inheritKlass_kwargs this_spec not_callableranew_attrr#r%rRs 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 rre__annotations__rf) r;r:rrgr4rirrr0r<r=)rWr?r$s r#r=z_patch.__exit__#s = 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.)rF_active_patchesr,rWr}s r#startz _patch.start8s-!! ##D))) r"c |j|n#t$rYdSwxYw|dddSzStop an active patch.N)rKrrNr=rs r#stopz _patch.stop?s[   ' ' - - - -   44 }}T4...s  ++)rrrrrKrHrrKrrcontextmanagerr&rrr6rFr=rMrPr!r"r#rrsNOAF"&"&"&"&"&J   ,,,    # # #""0PPPd...*/////r"rc |dd\}}n-#tttf$rtd|wxYwt t j||fS)NrIrz,Need a valid target to patch. You supplied: )rsplitrrNrLrpkgutil resolve_name)r4ris r# _get_targetrVKsG"MM#q11 z> 2GGG E6 E EGG GG 7' 0 0) ;;s *Arc 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!r4sr#rLz_patch_object..jsVr"r)r>strrr) r4rir rrrr rrrYrs ` r# _patch_objectr[Tsn$ F||s L L L   ^^^F  3f(L&   r"c tturttj}nfd}|st dt |}|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. cSr<r!rYsr#rLz!_patch_multiple..sr"z=Must supply at least one keyword argument with patch.multiplerrN) r>rZrrTrUrNrmrOrrr r,) r4rrrr rrYrrOrir r this_patchers ` r#_patch_multipler_qs , F||s-v66   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)rVr) r4r rrrr rrrYrris 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_dictdictrBr clear _original)rWrdrBrfrYs r#rHz_patch_dict.__init__s> 6ll  6""" r"ct|tr||Stj|r||S||Sr<r)rWfs r#rKz_patch_dict.__call__sc a   *&&q)) )  &q ) ) 3//22 2%%a(((r"c@tfd}|S)Nc |i|S#wxYwr<rb _unpatch_dictrXrrirWs r#_innerz-_patch_dict.decorate_callable.._inner#sV       %q$~"~~""$$$$""$$$$s 3A rrWriros`` r#rz_patch_dict.decorate_callable"9 q % % % % %  % r"c@tfd}|S)NcK |i|d{V S#wxYwr<rlrns r#roz3_patch_dict.decorate_async_callable.._inner/so       %Q^^^+++++++""$$$$""$$$$s <Arprqs`` r#rz#_patch_dict.decorate_async_callable.rrr"c t|D]}}t||}|tjrLt |dr"/ ==DL,  -||~~HH - - -H - - '   - -  - "  !   + NN6 " " " " " + + + + +%c{  + + + +s$A$$BBB66CCc|j}|j}t| ||dS#t$r|D] }||||<YdSwxYwr<)rdrgrzr rL)rWrdr|rMs r#rmz_patch_dict._unpatch_dictgs,>G - NN8 $ $ $ $ $ - - - - -'}  - - - -s6AAc<|j|dS)zUnpatch the dict.NF)rgrm)rWrXs r#r=z_patch_dict.__exit__ts! > %    ur"cl|}tj||SrJ)rFrrKr,rLs r#rMz_patch_dict.start{s-!!%%d+++ r"c tj|n#t$rYdSwxYw|dddSrO)rrKrrNr=rs r#rPz_patch_dict.stops[   " ) )$ / / / /   44 }}T4...s " 00N)r!F)rrrr rHrKrrrrFrbrmr=rMrPr!r"r#rbrbs8)))       +++8 - - -/////r"rbc |dS#t$rt|}|D]}||=YdSwxYwr<)rfrLrm)rdkeysrMs r#rzrzse  G}}  C    s !==cfttjD]}|dS)z7Stop all active patches. LIFO to unroll nested patches.N)rcrrKrP)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 zDadd 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">rx__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!)rWrXrr9s r#methodz_get_method..methods#tD&4&&&2&&&r")r)r*r9rs ` r#rrs('''''FO Mr"ch|]}d|zS)rr!)r)rs r#r+r+s*    Hv   r"> __aexit__ __anext__ __aenter__ __aiter__>__del__rrHr __prepare__r__instancecheck____subclasscheck__c6t|Sr<)rw__hash__rs r#rLrLsV__T22r"c6t|Sr<)rw__str__rs r#rLrLsFNN400r"c6t|Sr<)rw __sizeof__rs r#rLrLsv0066r"cxt|jd|dt|S)N/)r>rrirArs r#rLrLs;$t**"5^^8O8O8Q8Q^^TVW[T\T\^^r")rrr __fspath__ry?g?) __lt____gt____le____ge____int__r__len__r= __complex__ __float____bool__ __index__rcfd}|S)NcLjj}|tur|S|urdStSNT)__eq__rrNotImplemented)otherret_valrWs r#rz_get_eq..__eq__s1+0 ' ! !N 5==4r"r!)rWrs` r#_get_eqrs# Mr"cfd}|S)NcRjjturtS|urdStSNF)__ne__rrr)rrWs r#rz_get_ne..__ne__s, ; ) 8 8N 5==5r"r!)rWrs` r#_get_ners# Mr"cfd}|S)Ncjjj}|turtgSt|Sr<)__iter__rrrrrWs r#rz_get_iter..__iter__s1-2 g  88OG}}r"r!)rWrs` r# _get_iterr s# Or"cfd}|S)Ncjj}|turtt gStt |Sr<)rrr_AsyncIteratorrrs r#rz"_get_async_iter..__aiter__s@.3 g  !$r((++ +d7mm,,,r"r!)rWrs` r#_get_async_iterrs$----- r")rrrrc&t|t}|tur ||_dSt|}|||}||_dSt |}||||_dSdSr<)_return_valuesrsrr_calculate_return_value_side_effect_methodsr)rDrr*fixedreturn_calculatorr side_effectors r#_set_return_valuer(s   tW - -E G#/33D99$((.. *(,,T22M *]400! r"ceZdZdZdZdS) MagicMixinc|tt|j|i||dSr<)_mock_set_magicsrrrHrWrXrs r#rHzMagicMixin.__init__;sN . J%%.;;;; r"c ttz}|}t|ddX||j}t }||z }|D](}|t |jvrt||)|t t |jz }t |}|D]!}t||t||"dS)Nr)) _magicsrr1 intersectionr)ryr>rrrrg MagicProxy)rW orig_magics these_magics remove_magicsrKrs r#rzMagicMixin._mock_set_magicsAs 44 " 4$ / / ;&33D4FGGLEEM',6M& ) )DJJ///D%((($c$t***=&>&>> T ! ; ;E E5*UD"9"9 : : : : ; ;r"N)rrrrHrr!r"r#rr:s2   ;;;;;r"rceZdZdZddZdS)r z-A version of `MagicMock` that isn't callable.FcZ||||dSr!rrr"s r#r#z"NonCallableMagicMock.mock_add_spec[2 D(+++ r"Nrrrrr r#r!r"r#r r Ys.77      r"r ceZdZdZdS)AsyncMagicMixinc|tt|j|i||dSr<)rrrrHrs r#rHzAsyncMagicMixin.__init__fsN 3 OT**3T@R@@@ r"NrrrrHr!r"r#rres#     r"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_specvrr"Nrrr!r"r#rrks2        r"rc"eZdZdZdZddZdS)rc"||_||_dSr<r*r)rWr*rs r#rHzMagicProxy.__init__s  r"c|j}|j}||||}t|||t ||||S)N)r*rr)r*rr1rgr)rWrKrms r# create_mockzMagicProxy.create_mocksZ   " "/5 # 7 7q!!!&!U+++r"Nc*|Sr<)r)rWr5rs r#rzMagicProxy.__get__s!!!r"r<)rrrrHrrr!r"r#rrsF""""""r"rceZdZedZedZedZfdZdZdZ dZ dZ d Z d Z dd Zd ZfdZxZS)rrrrctj|i|tjj|jd<d|jd<d|jd<t |jd<tt}tj tj ztj z|_ d|_d|_d|_d|_||jd<d |jd <t%|jd <i|jd <d|jd <dS)Nrr_mock_await_count_mock_await_args_mock_await_args_listr)rXrYr8r rrerfrH)superrHrrrrrrr rr2 CO_COROUTINE CO_VARARGSCO_VARKEYWORDSco_flags co_argcount co_varnamesco_posonlyargcountco_kwonlyargcountrn)rWrXrY code_mockr6s r#rHzAsyncMockMixin.__init__s$)&)))*1);)I o&-. )*,0 ()1: -.#X666    !$ %  !"  2 '( $&' #$- j!$/ j!(- n%*, &'+/ '(((r"c`Kt||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)rrrrr,rrArkr StopIterationStopAsyncIterationrrrrr)rWrXrYrrr}s r#rz!AsyncMockMixin._execute_mock_callstVn$/// A ##E***!  V$$ 1 v&& 1-!&\\FF$----,-!((! L!$V,, 1%vt6v66666666000W$$  "' 1 1$ $   '"4#344 ?-T-t>v>>>>>>>>>#4#T4V44 4  s 1BBcT|jdkrd|jpdd}t|dS)zA Assert that the mock was awaited at least once. r Expected rDz to have been awaited.Nrrrrs r#rzAsyncMockMixin.assert_awaiteds?  q Odo7OOOC %% % ! r"cd|jdks$d|jpdd|jd}t|dS)z@ Assert that the mock was awaited exactly once. rrrD$ to have been awaited once. Awaited rNrrs r#rz"AsyncMockMixin.assert_awaited_oncesW1$$9t8&99#/999C %% %%$r"chj)}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_messages"33D&3QQCJr"Tr)rrrrrr/r)rWrXrYrrrrs``` r#rz"AsyncMockMixin.assert_awaited_withs ? "77fEEH !KH!K!K!KLL L       %%eT6N&E&E&EFF##DO44 X   *8Y ? ?IHHTE !1!122 =  r"cz|jdks$d|jpdd|jd}t||j|i|S)zi Assert that the mock was awaited exactly once and with the specified arguments. rrrDr r)rrrrrs r#rz'AsyncMockMixin.assert_awaited_once_withsg 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#rrz3AsyncMockMixin.assert_any_await.. s'FFFA$$$Q''FFFr"z%s await not found)rrr/rrrrrrs` r#rzAsyncMockMixin.assert_any_await s%%eT6N&E&E&EFF&x;;EFFFF1EFFF  HL$8$888">>tVLLO $6 98r"Fc*fd|D}td|Dd}tfdjD}|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#rrz4AsyncMockMixin.assert_has_awaits..# rr"c3DK|]}t|t|VdSr<rrts r#rz3AsyncMockMixin.assert_has_awaits..$ rr"Nc3BK|]}|VdSr<rrs r#rz3AsyncMockMixin.assert_has_awaits..% s1SSt11!44SSSSSSr"zAwaits not found.z,Error processing expected awaits. Errors: {}c@g|]}t|tr|ndSr<rrts r#rrz4AsyncMockMixin.assert_has_awaits..- rr"rz Actual: z not all found in await list) rrrrrrmrrNr,rn) rWrrrr all_awaitsrrrs ` r#rz AsyncMockMixin.assert_has_awaits s:9995999FFFFFMMSSSSd>RSSSSS  z))=1GG ,-3V$7$7-5$7$7$7.8.8%66!*5!1!166#366  F*%%   ' 'D '!!$'''' ' ' '  &&&&& '   49)4D4D4D4DF   s6C  C.-C.cd|jdkr$d|jpdd|jd}t|dS)z9 Assert that the mock was never awaited. rrrDz# to not have been awaited. Awaited rNrrs r#rz!AsyncMockMixin.assert_not_awaitedC sW  q 9t8&99#/999C %% % ! r"c|tj|i|d|_d|_t |_dS)z0 See :func:`.Mock.reset_mock()` rN)rrrrrr)rWrXrYr6s r#rzAsyncMockMixin.reset_mockL sB D+F+++({{r"r)rrrrrrrrHrrrrrrrrr __classcell__)r6s@r#rrs&&}55K%%l33J**+<==O000008&!&!&!P&&&&&&>>>$ 9 9 9   ****X&&&+++++++++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 V s''''r"r c$eZdZdZdZdZdZdS)_ANYz2A helper object that compares equal to everything.cdSrr!rWrs r#rz _ANY.__eq__ str"cdSrr!rs r#rz _ANY.__ne__ sur"cdS)Nzr!rs r#rz _ANY.__repr__ swr"N)rrrr rrrr!r"r#rr sG88r"rcd|z}d}dd|D}dd|D}|r|}|r |r|dz }||z }||zS)Nz%s(%%s)r z, c,g|]}t|Sr!)repr)r)rRs r#rrz*_format_call_signature.. s7773T#YY777r"c"g|] \}}|d| S)=r!)r)rMrs r#rrz*_format_call_signature.. s4#-3333r")rdrO)r*rXrYrformatted_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!r NFTcd}i}t|}|dkr|\}}}n~|dkr<|\} } t| tr| }t| tr| }nD| }nA| | }}n<|dkr6|\}t|tr|}nt|tr|}n|}|rt|||fSt||||fS)Nr!rr)rr/rZrnr) rrr*rr from_kallrXrY_lenfirstseconds r#rz _Call.__new__ s5zz 199!& D$ QYY!ME6%%% -fe,,$!DD#FF$ff QYYFE%%% E5))   6==tVn55 5}}S4v"6777r"c0||_||_||_dSr<)rr_mock_from_kall)rWrr*rrr+s r#rHz_Call.__init__ 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) Nr rrFrr!r*r)rrrr1rr/rnrZ) rWr len_other self_name self_args self_kwargs other_name other_args other_kwargsrr-r.s 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)Nr r/rrrrrs r#rKz_Call.__call__ sN ? ""dF+$777 7%dotV44MMMMr"cn|jt|dS|jd|}t||dS)NF)r*r+rI)r*rr+r:)rWrr*s r#rz_Call.__getattr__ sD ? "de444 4///440$tu====r"cb|tjvrtt||Sr<)rnrrrL__getattribute__)rWrs r#r=z_Call.__getattribute__$ s+ 5> ! ! %%dD111r"cHt|dkr|\}}n|\}}}||fS)Nr)rrs r#_get_call_argumentsz_Call._get_call_arguments* s2 t99>>LD&&!% D$V|r"c6|dSNrr?rs r#rXz _Call.args2 ''))!,,r"c6|dS)NrrBrs r#rYz _Call.kwargs6 rCr"c|js%|jpd}|drd|z}|St|dkrd}|\}}n+|\}}}|sd}n |dsd|z}nd|z}t |||S)Nrr/zcall%srzcall.%s)r0rr(rr)rWr*rXrYs 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.)r0r,rrrc)rWvalsthings r# call_listz_Call.call_listO sW$ # E"""&E$(((r")r!r NFT)r!NNFT)rrrr rrHrrwrrKrr=r?rrXrYrrIr!r"r#rr s$:?8888@>C))))2F2F2Fj]FNNN>>>222 --X---X-:::* ) ) ) ) )r"r)r+c $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"t%| |} |rt'| nt)|| ||| |s | |j|<|d } |r |sd |vrt/||dd| | | _t3|D];}t5|r t7||}n#t8$rY1wxYwd|i}| r&t;| |r|||rd|i}t|t"st=||| ||}|| j|<n{| }t|t"r| j}tA|||}||d<tC|rt}nt}|d||||d|}|| j|<t)|||t|t"rtE| ||=| 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%rrNTrzJInstance can not be True when create_autospec is mocking an async functionr*r )rrrr*rrr/)rar8rrrpr)rr*rr)r`r!)#ror>r/r.rr:rr rr2isdatadescriptorrr rkr rurQrErrrbrrsr rr+rr1rLr0rCrD _must_skiprrg)rrrarr8rrYis_type is_async_funcrBrArrDwrappedrKr|r rr` 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$ &&8dD))  $ d # # #tWh7778(,u%jj!!G;x;N&$@$@+D(T2629;;;T3&3& U     tU++HH    H (#  *ww.. * MMM ) ) )  , (+F(M22 AXxuhGGC),D  & &F$ .. #"488I"+F; "8,, (' ' +(V%5*0(( &((C*-D  & Xsi @ @ @ @ c= ) ) & D% % % % Ks'G88 HHcDt|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. rrF) r/r>r1r6rqrrrsrrJrIrE)rrKrMrr}s r#rLrL s dD ! ! GD*b11 1 15~  ##E733 W    f|[9 : : 55  . . NNN55 Nr"ceZdZ ddZdS)rCFNcZ||_||_||_||_||_||_dSr<)ridsrrrar*)rWrrrr*rTras r#rHz_SpecState.__init__ s0       r")FNNNFrr!r"r#rCrC s.48/4r"rCc|t|trtj|Stj|Sr<)r/bytesioBytesIOStringIO) read_datas r# _to_streamr[% s4)U##&z)$$${9%%%r"r c V t}|dg fd} fd} fd fd fd}tdddl}tt t |jt t |jat2ddl}tt t |j a |tdt }tt  j _ d j_ d j_ d j_ d j_ | j_ d < d  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|SrA) readlinesrrXrY_statehandles r#_readlines_side_effectz)mock_open.._readlines_side_effect; s7   ( 4#0 0"vay"D3F333r"cZjj jjSdj|i|SrA)readrr_s r#_read_side_effectz$mock_open.._read_side_effect@ s4 ; # /;+ +vay~t.v...r"c?VKEd{V dj|i|VNTr)readline)rXrY_iter_side_effectr`s r#_readline_side_effectz(mock_open.._readline_side_effectE sT$$&&&&&&&&& 6$&)$d5f55 5 5 5 6r"c3bKjj jjVdD]}|VdSrg)rhr)liner`ras r#riz$mock_open.._iter_side_effectJ sU ? ' 3 3o2222 31I  DJJJJ  r"c^jj jjStdSrA)rhrr)r`rasr#_next_side_effectz$mock_open.._next_side_effectQ s) ? ' 3?/ /F1Ir"ropen)r*r)rrctd<jjdkrd<dj_tS)Nrr)r[rhrr)rXrYrjr`rarZs r# reset_datazmock_open..reset_dataq sMy))q ? &&) 3 3--//F1I*0)FO 'r")r[ file_spec_iormryr+ TextIOWrapperunionrX open_specrorrFrwriterdrhr^rrr) rDrZ _read_datarbrernrsrqrirjr`ras ` @@@@r#rr, sI&&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"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)rWrYs r#r1zPropertyMock._get_child_mock s""6"""r"Nc|Sr<r!)rWr5obj_types r#rzPropertyMock.__get__ s tvv r"c||dSr<r!)rWr5rSs r#rzPropertyMock.__set__ s S r"r<)rrrr r1rrr!r"r#rr~ sP###r"rc4d|_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) r r+r1rLr/r rrsrCrr)rDrrs r#rr sDD   d##AA    H !_--   a&**400* = =    % % GGG  s + 88ceZdZdZdZdZdS)rz8 Wraps an iterator in an asynchronous iterator. ct||_tt}tj|_||jd<dS)Nrr8)iteratorr rr2CO_ITERABLE_COROUTINErrr)rWrrs r#rHz_AsyncIterator.__init__ s6  #X666 $: $- j!!!r"c^K t|jS#t$rYnwxYwtr<)rrrrrs r#rz_AsyncIterator.__anext__ sA  && &    D   s  %%N)rrrr rHrr!r"r#rr s<... !!!!!r"rr)NFNNN)FFNN)Nr )__all__rrrWr2rr>builtinsrTrtypesrrr unittest.utilr functoolsrr threadingrrrr+r3r rrr6r:r.rArFrRrbr]rkrorurr{rrrwrrrrMISSINGrDELETEDrDrrrmrrrrr rMrHrrr=rrrrrVr[r_rrbrzrremultiplestopallr magic_methodsnumericsrdrPinplaceright _non_defaultsrrr_sync_async_magics _async_magicsrr_rrrrrrrrrrrr rrrrr rrrrnrrr rLrCr>rrErrrvr[rrrrr!r"r#rs5  &  ''''''2222222222######$$$$$$$$CCCCCyCCC I Hcc(mm H H H   @@@222    F # # # #   &&&   6."."."b>>>6))) ) ) ) ) )f ) ) )         9;;         &********(6      6   N <N <N <N <N       :         j        D   ,""""""""$@+@+@+@+@+T@+@+@+F((((((((V     6    dff$$$$v)v)v)v)v)Ev)v)v)r uuCGO*/OOOOOd8         DD     &&&OOOOd4$0!!!!!!!!!!r"