wceU-ddlZddlZddlZddlmZmZmZmZmZm Z m Z m Z ddl Z ddl mZddlmZddlmZmZmZmZmZmZmZmZ ddlZee eefgeefZeegeefZeegeefZdZ dZ!e jDd Z#e jDd Z$ejJd Z&ejJdd Z'd Z(dZ)dZ*e jDdZ+e jDdZ,e jDdege-fdege-ffdZe jDdege-ffdZ.e jDdej^deefdZ0e jDdZ1e jDdej^deefdZ2e jDdZ3e jDdej^deefdZ4e jDdZ5y#e$rdZYwxYw)N)Any AwaitableCallableDictIteratorOptionalTypeUnion)isasyncgenfunction) Application)BaseTestServer RawTestServer TestClient TestServer loop_contextsetup_test_loopteardown_test_loop unused_portc|jdddd|jdddd |jd ddd y) N--aiohttp-fast store_trueFz*run tests faster by disabling extra checks)actiondefaulthelpz--aiohttp-loopstorepyloopz3run tests with specific loop: pyloop, uvloop or all--aiohttp-enable-loop-debugzenable event loop debug mode) addoption)parsers 7/usr/lib/python3/dist-packages/aiohttp/pytest_plugin.pypytest_addoptionr" sc  9    B   % + c|jtrdntjrdnydd|jvr|xjdz c_dfd}||_y)zjSet up pytest fixture. Allow fixtures to be coroutines. Run coroutine fixtures in an event loop. TFNrequestr%c|d}r|d=d|jvr td|jdr>|i|fd}|j|j j Sj |i|S)Nr%loopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.cb jjS#t$rYywxYwN)run_until_complete __anext__StopAsyncIteration)_loopgensr! finalizerz8pytest_fixture_setup..wrapper..finalizer`s1 33CMMODD)s " ..) fixturenames Exceptiongetfixturevalue addfinalizerr+r,) argskwargsr%r0r.r/func is_async_gen strip_requests @@r!wrapperz%pytest_fixture_setup..wrapperKs# y! -- -6  ''/ ''C    +++CMMO< <++D$,A&,AB Br#)r7r asyncioiscoroutinefunctionargnames) fixturedefr:r7r8r9s @@@r!pytest_fixture_setupr?5sl ??D$  $ $T *  M +++|+ C@JOr#c8|jjdS)z--fast config optionrconfig getoptionr&s r!fastrDns >> # #$4 55r#c8|jjdS)z!--enable-loop-debug config optionrrAr&s r! loop_debugrFts >> # #$A BBr#c #fKtjd5}d|Dcgc]'}|jtk(rdj |)}}|rDt dj t |t |dk(rdnd d j| dddycc}w#1swYyxYww) 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)recordNz#{w.filename}:{w.lineno}:{w.message})wz{} Runtime Warning{}, {}r s )warningscatch_warningscategoryRuntimeWarningformat RuntimeErrorlenjoin) _warningsrIrws r!_runtime_warning_contextrWzs   -   zz^+ 2 8 81 8 =  +22G3r7a%'*E*Ec*JI++D#677+K%r#c |jjd}tj|jr|j j dxs|j j dd}t5t||5}|jjDcic]}||j |}}|j|jdi|ddddddyycc}w#1swYxYw#1swYyxYw)zBRun coroutines in an event loop instead of a normal function call.r proactor_loopr(NrYT) rBrCr;r<functionfuncargsgetrWrZ _fixtureinfor=r+ra) pyfuncitemrD existing_loopr.argtestargss r!pytest_pyfunc_callrns    & &'7 8D"":#6#67"++//  3  $ $VT 2 & ' E*=tD E *66??,,S11(()C()CD  E E8  E E Es6>D C6%C1<#C6D1C66C? ;DD c .d|jvry|jjj}dtj i}t t j|d<|dk(rd}i}|jdD]\}|jd }|jd}||vr+|r(td |d t|jU||||<^|jdt|jt|j y) N loop_factoryruvloopallzpyloop,uvloop?,?z ?zUnknown loop 'z', available loops: )ids)r1rBoption aiohttp_loopr;DefaultEventLoopPolicyrqEventLoopPolicysplitendswithstrip ValueErrorr]keys parametrizevalues)metafuncloopsavail_factories factoriesr`requireds r!pytest_generate_testsrs X222 OO " " / /E!?!?@O $*$:$:! ~ I C 0}}S))zz$  & T).."235 )$/ $ 0 Y--/0d9>>;K6Lr#c#K|}tj|t|5}|r|jdtj||dddy#1swYyxYww)z%Return an instance of the event loop.rYTN)r;set_event_loop_policyr set_debugset_event_loop)rprDrFpolicyr.s r!r(r(s]^F !!&) 4 E  OOD !u% s)A--A! A-!A*&A-c#Ktj}tj|t|j5}tj ||dddy#1swYyxYwwr*)r;WindowsProactorEventLoopPolicyrrnew_event_loopr)rr.s r!rdrdsY  3 3 5F !!&) f++ ,u% s?A0A$ A0$A-)A0aiohttp_unused_portreturnc>tjdtd|S)Nz3Deprecated, use aiohttp_unused_port fixture instead stacklevelrMwarnDeprecationWarning)rs r!rrs MM= r#ctS)z1Return a port that is unused on the current host.) _unused_portrer#r!rrs  r#r(c#fKgddfd }|dfd }j|yw)z^Factory to create a TestServer instance, given an app. aiohttp_server(app, **kwargs) NportcKt||}|jddi|d{j||S7wNrr(re)r start_serverappend)apprr6serverr(serverss r!gozaiohttp_server..go sGCd+!f!!6t6v666v  7%AAAcjKr*jjd{r)yy7 wr*popclosersr!finalizez aiohttp_server..finalize*++-%%' ' ' '$3133rNr+r(rrrs` @r!aiohttp_serverrs4 G" H( HJ'-1c>tjdtd|S)Nz.Deprecated, use aiohttp_server fixture insteadrrr)rs r! test_serverr MM8 r#c#fKgddfd }|dfd }j|yw)zpFactory to create a RawTestServer instance, given a web handler. aiohttp_raw_server(handler, **kwargs) NrcKt||}|jddi|d{j||S7wr)rrr)handlerrr6rr(rs r!rzaiohttp_raw_server..go*sGwT2!f!!6t6v666v  7rcjKr*jjd{r)yy7 wr*rrsr!rz$aiohttp_raw_server..finalize2rrrrrs` @r!aiohttp_raw_serverr"s4 G"& H( HJ'rc>tjdtd|S)Nz2Deprecated, use aiohttp_raw_server fixture insteadrrr)rs r!raw_test_serverr9s! MM< r#c #Kgdddtttfdtdtt t tfdtdtf fd}|d fd }j|yw) 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|i|}i}n |rJdt|tr#|xsi}t |fdi|}t |fdi|}n6t|trt |fdi|}nt dt|z|jd{j||S7w)Nzargs should be emptyr(zUnknown argument type: %r) isinstancerr rrrr}typerr)rrr5r6rclientclientsr(s r!rzaiohttp_client..goQs gx ( k>22 d4T4V4GF 33 38 g{ +)/RMDdDmDFC?CcjKr*jjd{r)yy7 wr*r)rsr!rz aiohttp_client..finalizeorrr) r r rrrrstrrr+)r(rrrs` @r!aiohttp_clientrEs{G 37{N23 S#X/   8 H( HJ'sA-A1c>tjdtd|S)Nz.Deprecated, use aiohttp_client fixture insteadrrr)rs r! test_clientrvrr#)F)6r; contextlibrMtypingrrrrrrr r pytestaiohttp.helpersr aiohttp.webr test_utilsrrrrrrrrrrq ImportError AiohttpClientAiohttpRawServer AiohttpServerr"r?fixturerDrFcontextmanagerrWrZrbrnrr(rdintrAbstractEventLooprrrrrrrer#r!rsRRR .#   % ^ ;<=y?TTU 9]+CCD+ *(==> *6r66 CC  .  , , 8 $@Xb#g%68BG;LXb#g. (22(x 7N((,(W66(8DT;U((,-(  # #-( m-(-(`  FsG GG