B `+@sddlZddlZddlZddlmZddlZddlmZmZddl m Z ddl m Z m Z mZmZmZmZmZmZy ddlZWnek rdZYnXy ddlZWnek rdZYnXddZd d Zejd d Zejd dZejddZejd.ddZddZ ddZ!ddZ"ejddZ#ejddZ$ejddZejd d!Z%ejd"d#Z&ejd$d%Z'ejd&d'Z(ejd(d)Z)ejd*d+Z*ejd,d-Z+dS)/N)Callable)PY_37isasyncgenfunction) Application)BaseTestServer RawTestServer TestClient TestServer loop_contextsetup_test_loopteardown_test_loop unused_portcCs:|jddddd|jdddd d|jd ddd ddS) Nz--aiohttp-fast store_trueFz*run tests faster by disabling extra checks)actiondefaulthelpz--aiohttp-loopstorepyloopz:run tests with specific loop: pyloop, uvloop, tokio or allz--aiohttp-enable-loop-debugzenable event loop debug mode)Z addoption)parserrp/private/var/folders/7j/8686xlfs15q3tgljmghtvg0r0000gn/T/pip-target-isidps9b/lib/python/aiohttp/pytest_plugin.pypytest_addoption!srcsb|jtrdntr$dndSdd|jkrH|jd7_dfdd}||_dS)zS Allow fixtures to be coroutines. Run coroutine fixtures in an event loop. TFNrequest)rcsv|d}r|d=d|jkr$td|drb||fdd}||S||SdS)Nrloopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.cs(yStk r"YnXdS)N)run_until_complete __anext__StopAsyncIterationr)_loopgenrr finalizer`sz8pytest_fixture_setup..wrapper..finalizer) fixturenames ExceptionZgetfixturevalueZ addfinalizerrr)argskwargsrr )func is_async_gen strip_request)rrrwrapperKs    z%pytest_fixture_setup..wrapper)r%rasyncioiscoroutinefunctionargnames)Z fixturedefr(r)r%r&r'rpytest_fixture_setup6s   r,cCs |jdS)z--fast config optionz--aiohttp-fast)config getoption)rrrrfastnsr/cCs |jdS)z!--enable-loop-debug config optionz--aiohttp-enable-loop-debug)r-r.)rrrr loop_debugtsr0c cs`tjddJ}dVdd|D}|rRtdt|t|dkrBdnd d |WdQRXdS) z Context manager which checks for RuntimeWarnings, specifically to avoid "coroutine 'X' was never awaited" warnings being missed. If RuntimeWarnings occur in the context a RuntimeError is raised. T)recordNcSs"g|]}|jtkrdj|dqS)z#{w.filename}:{w.lineno}:{w.message})w)categoryRuntimeWarningformat).0r2rrr sz,_runtime_warning_context..z{} Runtime Warning{}, {}rs )warningscatch_warnings RuntimeErrorr5lenjoin) _warningsrwrrr_runtime_warning_contextzsrBFccs(|r |Vnt}|Vt||ddS)z{ setups and tears down a loop unless one is passed in via the loop argument when it's passed straight through. )r/N)r r )rr/rrr_passthrough_loop_contexts rCcCs(||r$t|r$t|||SdS)z/ Fix pytest collecting for coroutines. N)Zfuncnamefilterr)r*listZ _genfunctions) collectornameobjrrrpytest_pycollect_makeitemsrHc sjd}tjrjdp0jdd}tFt||d.}fddj j D}| j f|WdQRXWdQRXdSdS) zL Run coroutines in an event loop instead of a normal function call. z--aiohttp-fast proactor_looprN)r/csi|]}j||qSr)funcargs)r6arg) pyfuncitemrr sz&pytest_pyfunc_call..T) r-r.r)r*functionrJgetrBrCZ _fixtureinfor+rrG)rLr/Z existing_looprZtestargsr)rLrpytest_pyfunc_calls    &rPcCsd|jkrdS|jjj}dtji}tdk r4tj|d<tdk rFtj|d<|dkrRd}i}x\| dD]N}| d }| d }||kr|rbt d |t |fnqb||||<qbW|jdt |t |d dS) N loop_factoryruvlooptokioallzpyloop,uvloop?,tokio?,?z ?z&Unknown loop '%s', available loops: %s)ids)r!r-optionZ aiohttp_loopr)ZDefaultEventLoopPolicyrRZEventLoopPolicyrSsplitendswithstrip ValueErrorrDkeysZ parametrizevalues)ZmetafuncZloopsZavail_factoriesZ factoriesrFrequiredrrrpytest_generate_testss.       r`c csH|}t|t|d$}|r*|dt||VWdQRXdS)z%Return an instance of the event loop.)r/TN)r)set_event_loop_policyr Z set_debugset_event_loop)rQr/r0policyrrrrrs    rc csRtst}tj|_nt}t|t|j}t ||VWdQRXdS)N) rr)Zget_event_loop_policyZProactorEventLoopZ _loop_factoryZWindowsProactorEventLoopPolicyrar Znew_event_looprb)rcrrrrrIs    rIcCstjdtdd|S)Nz3Deprecated, use aiohttp_unused_port fixture instead) stacklevel)r;warnDeprecationWarning)aiohttp_unused_portrrrrs rcCstS)z1Return a port that is unused on the current host.) _unused_portrrrrrhsrhc#s:gddfdd }|Vfdd}|dS)z^Factory to create a TestServer instance, given an app. aiohttp_server(app, **kwargs) N)portcs4t||d}|jfdi|IdH||S)N)rjr)r start_serverappend)Zapprjr$server)rserversrrgos  zaiohttp_server..gocs xrIdHqWdS)N)popcloser)rnrrfinalizesz aiohttp_server..finalize)r)rrorrr)rrnraiohttp_server s  rscCstjdtdd|S)Nz.Deprecated, use aiohttp_server fixture insteadrd)re)r;rfrg)rsrrr test_server s rtc#s:gddfdd }|Vfdd}|dS)zpFactory to create a RawTestServer instance, given a web handler. aiohttp_raw_server(handler, **kwargs) N)rjcs4t||d}|jfdi|IdH||S)N)rjr)rrkrl)handlerrjr$rm)rrnrrro2s  zaiohttp_raw_server..gocs xrIdHqWdS)N)rprqr)rnrrrr:sz$aiohttp_raw_server..finalize)r)rrorrr)rrnraiohttp_raw_server*s  rvcCstjdtdd|S)Nz2Deprecated, use aiohttp_raw_server fixture insteadrd)re)r;rfrg)rvrrrraw_test_serverAs rwc#s:gddfdd }|Vfdd}|dS)zFactory to create a TestClient instance. aiohttp_client(app, **kwargs) aiohttp_client(server, **kwargs) aiohttp_client(raw_server, **kwargs) N) server_kwargscst|tr.t|ttfs.|f||}i}n |r:tdt|trv|pJi}t|fdi|}t|fdi|}n0t|trt|fdi|}ntdt|| IdH ||S)Nzargs should be emptyrzUnknown argument type: %r) isinstancerrrAssertionErrorr r r\typerkrl)Z__paramrxr#r$rmclient)clientsrrrroUs      zaiohttp_client..gocs xrIdHqWdS)N)rprqr)r}rrrrnsz aiohttp_client..finalize)r)rrorrr)r}rraiohttp_clientKs  r~cCstjdtdd|S)Nz.Deprecated, use aiohttp_client fixture insteadrd)re)r;rfrg)r~rrr test_clientus r)F),r) contextlibr;collections.abcrZpytestZaiohttp.helpersrrZ aiohttp.webrZ test_utilsrrr r r r r rrirR ImportErrorrSrr,Zfixturer/r0contextmanagerrBrCrHrPr`rrIrhrsrtrvrwr~rrrrrsF  (     8 "    *