Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/aiohttp/__pycache__/
Upload File :
Current 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
r�dZYnXyddlZWnek
r�dZYnXdd�Zd	d
�Zejdd��Zejd
d��Zejdd��Zejddd��Zdd�Zdd�Zdd�Z ejdd��Z!ejdd��Zejdd��Z"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_context�setup_test_loop�teardown_test_loop)�unused_portcCsa|jddddddd�|jddd	dd
dd�|jddddddd
�dS)Nz--aiohttp-fast�action�
store_true�defaultF�helpz*run tests faster by disabling extra checksz--aiohttp-loop�store�pyloopz:run tests with specific loop: pyloop, uvloop, tokio or allz--aiohttp-enable-loop-debugzenable event loop debug mode)Z	addoption)�parser�r�H/opt/alt/python35/lib64/python3.5/site-packages/aiohttp/pytest_plugin.py�pytest_addoptionsrcs�|j�t��rd�ntj��r6d�ndSd�d|jkrd|jd7_d����fdd�}||_dS)zS
    Allow fixtures to be coroutines. Run coroutine fixtures in an event loop.
    TFN�requestcs�|d}�r|d=d|jkr2td��|jd���r��||����fdd�}|j|��j�j��S�j�||��SdS)Nr�loopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.cs0y�j�j��SWntk
r+YnXdS)N)�run_until_complete�	__anext__�StopAsyncIterationr)�_loop�genrr�	finalizerQs
z8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer)�fixturenames�	ExceptionZgetfixturevalueZaddfinalizerrr)�args�kwargsrr)�func�is_async_gen�
strip_request)rrr�wrapper<s
	
z%pytest_fixture_setup.<locals>.wrapper)r)r#r�asyncio�iscoroutinefunction�argnames)Z
fixturedefr&r)r#r$r%r�pytest_fixture_setup's			 r*cCs|jjd�S)z--fast config optionz--aiohttp-fast)�config�	getoption)rrrr�fast_sr-cCs|jjd�S)z!--enable-loop-debug config optionz--aiohttp-enable-loop-debug)r+r,)rrrr�
loop_debugesr.c
cs�tjdd��g}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)�category�RuntimeWarning�format)�.0r0rrr�
<listcomp>us	z,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}r��s�
)�warnings�catch_warnings�RuntimeErrorr3�len�join)�	_warnings�rwrrr�_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
	rAcCs8|j|�r4tj|�r4t|j||��SdS)z/
    Fix pytest collecting for coroutines.
    N)Zfuncnamefilterr'r(�listZ
_genfunctions)�	collector�name�objrrr�pytest_pycollect_makeitem�srFcs��jjd�}tj�j�r��jjdd�}t��Vt|d|��<}�fdd��j	j
D�}|j�j|��WdQRXWdQRXdSdS)zL
    Run coroutines in an event loop instead of a normal function call.
    z--aiohttp-fastrNr-cs i|]}�j||�qSr)�funcargs)r4�arg)�
pyfuncitemrr�
<dictcomp>�s	z&pytest_pyfunc_call.<locals>.<dictcomp>T)
r+r,r'r(�functionrG�getr@rAZ_fixtureinfor)rrE)rIr-Z
existing_looprZtestargsr)rIr�pytest_pyfunc_call�s
$rMcCs.d|jkrdS|jjj}dtji}tdk	rJtj|d<tdk	rctj|d<|dkrud}i}x~|jd�D]m}|j	d�}|j
d	�}||kr�|r�td
|t|j
��f��nq�||||<q�W|jdt|j��dt|j
���dS)N�loop_factoryr�uvloop�tokio�allzpyloop,uvloop?,tokio?�,�?z ?z&Unknown loop '%s', available loops: %sZids)rr+�optionZaiohttp_loopr'Znew_event_looprOrP�split�endswith�strip�
ValueErrorrB�keysZparametrize�values)ZmetafuncZloopsZavail_factoriesZ	factoriesrD�requiredrrr�pytest_generate_tests�s0

	r\c	csEt|d|��}|r(|jd�|VWdQRXtjd�dS)z%Return an instance of the event loop.r-TN)r	Z	set_debugr'Zset_event_loop)rNr-r.rrrrr�s

rcCstjdt�|S)Nz3Deprecated, use aiohttp_unused_port fixture instead)r9�warn�DeprecationWarning)�aiohttp_unused_portrrrr�s	rcCstS)z1Return a port that is unused on the current host.)�_unused_portrrrrr_�sr_c#sLg�dd��fdd�}|V�fdd�}�j|��dS)z^Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    �portNc�s;t|d|�}|jd�|�IdH�j|�|S)Nrar)r�start_server�append)Zapprar"�server)r�serversrr�go�s
zaiohttp_server.<locals>.goc�s&x�r!�j�j�IdHqWdS)N)�pop�closer)rerr�finalize�s	z aiohttp_server.<locals>.finalize)r)rrfrir)rrer�aiohttp_server�s
rjcCstjdt�|S)Nz.Deprecated, use aiohttp_server fixture instead)r9r]r^)rjrrr�test_server�s	rkc#sLg�dd��fdd�}|V�fdd�}�j|��dS)zpFactory to create a RawTestServer instance, given a web handler.

    aiohttp_raw_server(handler, **kwargs)
    raNc�s;t|d|�}|jd�|�IdH�j|�|S)Nrar)rrbrc)�handlerrar"rd)rrerrrfs
zaiohttp_raw_server.<locals>.goc�s&x�r!�j�j�IdHqWdS)N)rgrhr)rerrri
s	z$aiohttp_raw_server.<locals>.finalize)r)rrfrir)rrer�aiohttp_raw_server�s
rmcCstjdt�|S)Nz2Deprecated, use aiohttp_raw_server fixture instead)r9r]r^)rmrrr�raw_test_servers	rnc#sLg�dd��fdd�}|V�fdd�}�j|��dS)z�Factory to create a TestClient instance.

    aiohttp_client(app, **kwargs)
    aiohttp_client(server, **kwargs)
    aiohttp_client(raw_server, **kwargs)
    �
server_kwargsNc�s�t|tj�rCt|ttf�rC|�||�}i}n|sVtd��t|t�r�|pni}t|d�|�}t|d�|�}n=t|t�r�t|d�|�}ntdt	|���|j
�IdH�j|�|S)Nzargs should be emptyrzUnknown argument type: %r)�
isinstance�collections�Callablerr�AssertionErrorrrrX�typerbrc)Z__paramror!r"rd�client)�clientsrrrrf%s	
zaiohttp_client.<locals>.goc�s&x�r!�j�j�IdHqWdS)N)rgrhr)rvrrri=s	z aiohttp_client.<locals>.finalize)r)rrfrir)rvrr�aiohttp_clients
rwcCstjdt�|S)Nz.Deprecated, use aiohttp_client fixture instead)r9r]r^)rwrrr�test_clientDs	rx))r'rq�
contextlibr9�pytestZaiohttp.helpersrZaiohttp.webrZ
test_utilsrrrrr	r
rrr`rO�ImportErrorrPrr*Zfixturer-r.�contextmanagerr@rArFrMr\rr_rjrkrmrnrwrxrrrr�<module>sF4

8!
)