Viewing File: /opt/alt/python35/lib64/python3.5/site-packages/aiohttp/__pycache__/pytest_plugin.cpython-35.pyc



Z-&@sJddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZmZmZddl	mZyddlZWnek
rdZYnXyddlZWnek
rdZYnXddZd	d
ZejddZejd
dZejddZejdddZddZddZddZ ejddZ!ejddZejddZ"ejd d!Z#ejd"d#Z$ejd$d%Z%ejd&d'Z&ejd(d)Z'ejd*d+Z(dS),N)isasyncgenfunction)Application)BaseTestServer
RawTestServer
TestClient
TestServerloop_contextsetup_test_loopteardown_test_loop)unused_portcCsa|jddddddd|jddd	dd
dd|jddddddd
dS)Nz--aiohttp-fastaction
store_truedefaultFhelpz*run tests faster by disabling extra checksz--aiohttp-loopZstorepyloopz:run tests with specific loop: pyloop, uvloop, tokio or allz--aiohttp-enable-loop-debugzenable event loop debug mode)Z	addoption)parserr/pytest_plugin.pypytest_addoptionsrcs|jtrdntjr6dndSdd|jkrd|jd7_dfdd}||_dS)zS
    Allow fixtures to be coroutines. Run coroutine fixtures in an event loop.
    TFNrequestcs|d}r|d=d|jkr2td|jdr||fdd}|j|jjSj||SdS)Nrloopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.cs0yjjSWntk
r+YnXdS)N)run_until_complete	__anext__StopAsyncIterationr)_loopgenrr	finalizerQs
z8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer)fixturenames	ExceptionZgetfixturevalueZaddfinalizerrr)argskwargsrr)funcis_async_gen
strip_request)rrrwrapper<s
	
z%pytest_fixture_setup.<locals>.wrapper)r)r"rasyncioiscoroutinefunctionargnames)Z
fixturedefr%r)r"r#r$rpytest_fixture_setup's			 r)cCs|jjdS)z--fast config optionz--aiohttp-fast)config	getoption)rrrrfast_sr,cCs|jjdS)z!--enable-loop-debug config optionz--aiohttp-enable-loop-debug)r*r+)rrrr
loop_debugesr-c
cstjddg}dVdd|D}|rutdjt|t|dkr]dnd	d
j|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.
    recordTNcSs1g|]'}|jtkrdjd|qS)z#{w.filename}:{w.lineno}:{w.message}w)categoryRuntimeWarningformat).0r/rrr
<listcomp>us	z,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}rs
)warningscatch_warningsRuntimeErrorr2lenjoin)	_warningsrwrrr_runtime_warning_contextks	
		r?Fccs0|r|Vnt}|Vt|d|dS)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
	r@cCs8|j|r4tj|r4t|j||SdS)z/
    Fix pytest collecting for coroutines.
    N)Zfuncnamefilterr&r'listZ
_genfunctions)Z	collectornameobjrrrpytest_pycollect_makeitemsrDcsjjd}tjjrjjdd}tVt|d|<}fddj	j
D}|jj|WdQRXWdQRXdSdS)zL
    Run coroutines in an event loop instead of a normal function call.
    z--aiohttp-fastrNr,cs i|]}j||qSr)funcargs)r3arg)
pyfuncitemrr
<dictcomp>s	z&pytest_pyfunc_call.<locals>.<dictcomp>T)
r*r+r&r'functionrEgetr?r@Z_fixtureinfor(rrC)rGr,Z
existing_looprZtestargsr)rGrpytest_pyfunc_calls
$rKcCs.d|jkrdS|jjj}dtji}tdk	rJtj|d<tdk	rctj|d<|dkrud}i}x~|jdD]m}|j	d}|j
d	}||kr|rtd
|t|j
fnq||||<qW|jdt|jdt|j
dS)Nloop_factoryruvlooptokioallzpyloop,uvloop?,tokio?,?z ?z&Unknown loop '%s', available loops: %sZids)rr*ZoptionZaiohttp_loopr&Znew_event_looprMrNsplitendswithstrip
ValueErrorrAkeysZparametrizevalues)ZmetafuncZloopsZavail_factoriesZ	factoriesrBZrequiredrrrpytest_generate_testss0

	rXc	csEt|d|}|r(|jd|VWdQRXtjddS)z%Return an instance of the event loop.r,TN)r	Z	set_debugr&Zset_event_loop)rLr,r-rrrrrs

rcCstjdt|S)Nz3Deprecated, use aiohttp_unused_port fixture instead)r8warnDeprecationWarning)aiohttp_unused_portrrrrs	rcCstS)z1Return a port that is unused on the current host.)_unused_portrrrrr[sr[c#sLgddfdd}|Vfdd}j|dS)z^Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    portNcs;t|d|}|jd|IdHj||S)Nr]r)rstart_serverappend)Zappr]r!server)rserversrrgos
zaiohttp_server.<locals>.gocs&xr!jjIdHqWdS)N)popcloser)rarrfinalizes	z aiohttp_server.<locals>.finalize)r)rrbrer)rraraiohttp_servers
rfcCstjdt|S)Nz.Deprecated, use aiohttp_server fixture instead)r8rYrZ)rfrrrtest_servers	rgc#sLgddfdd}|Vfdd}j|dS)zpFactory to create a RawTestServer instance, given a web handler.

    aiohttp_raw_server(handler, **kwargs)
    r]Ncs;t|d|}|jd|IdHj||S)Nr]r)rr^r_)handlerr]r!r`)rrarrrbs
zaiohttp_raw_server.<locals>.gocs&xr!jjIdHqWdS)N)rcrdr)rarrre
s	z$aiohttp_raw_server.<locals>.finalize)r)rrbrer)rraraiohttp_raw_servers
ricCstjdt|S)Nz2Deprecated, use aiohttp_raw_server fixture instead)r8rYrZ)rirrrraw_test_servers	rjc#sLgddfdd}|Vfdd}j|dS)zFactory to create a TestClient instance.

    aiohttp_client(app, **kwargs)
    aiohttp_client(server, **kwargs)
    aiohttp_client(raw_server, **kwargs)
    
server_kwargsNcst|tjrCt|ttfrC|||}i}n|sVtdt|tr|pni}t|d|}t|d|}n=t|trt|d|}ntdt	||j
IdHj||S)Nzargs should be emptyrzUnknown argument type: %r)
isinstancecollectionsCallablerrAssertionErrorrrrUtyper^r_)Z__paramrkr r!r`client)clientsrrrrb%s	
zaiohttp_client.<locals>.gocs&xr!jjIdHqWdS)N)rcrdr)rrrrre=s	z aiohttp_client.<locals>.finalize)r)rrbrer)rrrraiohttp_clients
rscCstjdt|S)Nz.Deprecated, use aiohttp_client fixture instead)r8rYrZ)rsrrrtest_clientDs	rt))r&rm
contextlibr8ZpytestZaiohttp.helpersrZaiohttp.webrZ
test_utilsrrrrr	r
rrr\rMImportErrorrNrr)Zfixturer,r-contextmanagerr?r@rDrKrXrr[rfrgrirjrsrtrrrr<module>sF4

8!
)
Back to Directory File Manager