id-ddlZddlZddlZddlmZddlmZmZmZmZm Z m Z m Z ddl Z ddl mZmZddlmZddlmZmZmZmZmZmZmZmZ ddlZn #e$rdZYnwxYw ddlZn #e$rdZYnwxYwee eefgeefZdZ d Z!e j"d Z#e j"d Z$ej%d Z&ej%ddZ'dZ(dZ)dZ*e j"dZ+e j"dZ,e j"dZe j"dZ-e j"dZ.e j"dZ/e j"dZ0e j"dZ1e j"dej2de eddffdZ3e j"dZ4dS)N)Callable)Any AwaitablerDict GeneratorOptionalUnion)PY_37isasyncgenfunction) Application)BaseTestServer RawTestServer TestClient TestServer loop_contextsetup_test_loopteardown_test_loop unused_portc|dddd|dddd |d ddd dS) N--aiohttp-fast store_trueFz*run tests faster by disabling extra checks)actiondefaulthelpz--aiohttp-loopstorepyloopz:run tests with specific loop: pyloop, uvloop, tokio or all--aiohttp-enable-loop-debugzenable event loop debug mode) addoption)parsers J/opt/cloudlinux/venv/lib/python3.11/site-packages/aiohttp/pytest_plugin.pypytest_addoptionr"$s  9    I   % + c|jtrdntjrdndSdd|jvr|xjdz c_dfd}||_dS)zjSet up pytest fixture. Allow fixtures to be coroutines. Run coroutine fixtures in an event loop. TFNrequestr%cJ|d}r|d=d|jvrtd|drJ|i|fd}||S|i|S)Nr%loopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.cv S#t$rYdSwxYwN)run_until_complete __anext__StopAsyncIteration)_loopgensr! finalizerz8pytest_fixture_setup..wrapper..finalizerdsF 33CMMOODDD)DDs &* 88) fixturenames Exceptiongetfixturevalue addfinalizerr+r,) argskwargsr%r0r.r/func is_async_gen strip_requests @@r!wrapperz%pytest_fixture_setup..wrapperOs#  "y! - - -6  ''//  C$'''C         + + +++CMMOO<< <++DD$,A&,A,ABB Br#)r7r asyncioiscoroutinefunctionargnames) fixturedefr:r7r8r9s @@@r!pytest_fixture_setupr?9s ?D$  $T * *  M +++|+ CCCCCCC@JOOOr#c6|jdS)z--fast config optionrconfig getoptionr&s r!fastrDrs > # #$4 5 55r#c6|jdS)z!--enable-loop-debug config optionrrAr&s r! loop_debugrFxs > # #$A B BBr#c #>Ktjd5}dVd|D}|rYtdt |t |dkrdndd | ddddS#1swxYwYdS) zContext manager which checks for RuntimeWarnings. This exists specifically to avoid "coroutine 'X' was never awaited" warnings being missed. If RuntimeWarnings occur in the context a RuntimeError is raised. T)recordNcZg|](}|jtkd|)S)z#{w.filename}:{w.lineno}:{w.message})w)categoryRuntimeWarningformat).0rJs r! z,_runtime_warning_context..s@   z^++ 2 8 81 8 = =+++r#z{} Runtime Warning{}, {}r s )warningscatch_warnings RuntimeErrorrMlenjoin) _warningsrws r!_runtime_warning_contextrZ~s   - - -         +22GG3r77a<z&pytest_pyfunc_call..s3,S1r#Tri) rBrCr;r<functionrjgetrZr] _fixtureinfor=r+rd)rlrD existing_loopr.testargss` r!pytest_pyfunc_callrss   & &'7 8 8D":#677 "+//   3  $ $VT 2 2 & ' ' E E*=tDDD E)6?(()C)C()C)CDDD  E E E E E E E E E E E E E E E E E E E E E E E E E E E E E Et  s68C& 9C C&C C&C C&&C*-C*c d|jvrdS|jjj}dtji}t t j|d<ttj|d<|dkrd}i}| dD]s}| d }| d }||vr7|r4td |d t|h||||<t|dt|t| dS) N loop_factoryruvlooptokioallzpyloop,uvloop?,tokio?,?z ?zUnknown loop 'z', available loops: )ids)r1rBoption aiohttp_loopr;DefaultEventLoopPolicyrvEventLoopPolicyrwsplitendswithstrip ValueErrorr`keys parametrizevalues)metafuncloopsavail_factories factoriesrcrequireds r!pytest_generate_testsrs[X222 O " /E!?@O $*$:! #(#8  ~~'I C  0 0}}S)))zz$  & &  jttT).."2"23335 )$/ $ Y--//00d9>>;K;K6L6Lr#c#K|}tj|t|5}|r|dtj||VddddS#1swxYwYdS)z%Return an instance of the event loop.r\TN)r;set_event_loop_policyr set_debugset_event_loop)rurDrFpolicyr.s r!r(r(s\^^F !&))) 4 E  " OOD ! ! !u%%% s0A..A25A2c#:Kts%tj}tj|_n'tj}tj|t|j5}tj ||VddddS#1swxYwYdSr*) r r;get_event_loop_policyProactorEventLoop _loop_factoryWindowsProactorEventLoopPolicyrrnew_event_loopr)rr.s r!rgrgs ..00&8799%f--- f+ , ,u%%% s*BBBc>tjdtd|S)Nz3Deprecated, use aiohttp_unused_port fixture instead stacklevelrSwarnDeprecationWarning)aiohttp_unused_ports r!rrs, M= r#ctS)z1Return a port that is unused on the current host.) _unused_portrir#r!rrs  r#c#rKgddfd }|Vdfd }|dS)z^Factory to create a TestServer instance, given an app. aiohttp_server(app, **kwargs) NportcKt||}|jddi|d{V||SNrr(ri)r start_serverappend)apprr6serverr(serverss r!gozaiohttp_server..gos`Cd+++!f!66t6v666666666v r#returncpKr0d{V.dSdSr*popclosersr!finalizez aiohttp_server..finalizeY (++--%%'' ' ' ' ' ' ' ' ( ( ( ( (r#rNr+r(rrrs` @r!aiohttp_serverr s G" HHH(((((( HHJJ'''''r#c>tjdtd|S)Nz.Deprecated, use aiohttp_server fixture insteadrrr)rs r! test_serverr", M8 r#c#rKgddfd }|Vdfd }|dS)zpFactory to create a RawTestServer instance, given a web handler. aiohttp_raw_server(handler, **kwargs) NrcKt||}|jddi|d{V||Sr)rrr)handlerrr6rr(rs r!rzaiohttp_raw_server..go4s`wT222!f!66t6v666666666v r#rcpKr0d{V.dSdSr*rrsr!rz$aiohttp_raw_server..finalize<rr#rrrs` @r!aiohttp_raw_serverr,s G"& HHH(((((( HHJJ'''''r#c>tjdtd|S)Nz2Deprecated, use aiohttp_raw_server fixture insteadrrr)rs r!raw_test_serverrCs. M< r#r(rc #Kgdddtttfdtdtt t tfdtdtf fd}|Vd fd }|dS) zFactory to create a TestClient instance. aiohttp_client(app, **kwargs) aiohttp_client(server, **kwargs) aiohttp_client(raw_server, **kwargs) N) server_kwargs__paramr5rr6rcKt|tr*t|ttfs|g|Ri|}i}t|tr#|pi}t |fdi|}t |fdi|}nDt|trt |fdi|}nt dt|z|d{V ||S)Nr(zUnknown argument type: %r) isinstancerr rrrrtyperr)rrr5r6rclientclientsr(s r!rzaiohttp_client..go[s5 gx ( ( 4 k>22 2  4gd4T444V44GF g{ + + J)/RMDDdDmDDF<.finalizeyrr#r) r r rrrrstrrr+)r(rrrs` @r!aiohttp_clientrOsG 37{N23 S#X/   8 HHH(((((( HHJJ'''''r#c>tjdtd|S)Nz.Deprecated, use aiohttp_client fixture insteadrrr)rs r! test_clientrrr#)F)5r; contextlibrScollections.abcrtypingrrrrrr pytestaiohttp.helpersr r aiohttp.webr test_utilsrrrrrrrrrrv ImportErrorrw AiohttpClientr"r?fixturerDrFcontextmanagerrZr]rersrr(rgrrrrrAbstractEventLooprrrir#r!rs$$$$$$MMMMMMMMMMMMMMMMMM 55555555######                    MMMM FFFLLLL EEE% ^ ;<=y?TTU *666r666 CCC  .  , , , , 888 $D    (((,(((,-(  #-(}dD()-(-(-(-(`s$ AAAA$$A.-A.