
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    '7`+                     @   s  d dl Z d dlZd dlZd dlmZ d dlZd dlmZmZ d dl	m
Z
 ddlmZmZmZmZmZmZmZmZ zd dlZW n ek
r   dZY nX zd dlZW n ek
r   dZY nX dd Zd	d
 Zejdd Zejdd Zejdd Zejd.ddZdd Z dd Z!dd Z"ejdd Z#ejdd Z$ejdd Zejd d! Z%ejd"d# Z&ejd$d% Z'ejd&d' Z(ejd(d) Z)ejd*d+ Z*ejd,d- Z+dS )/    N)Callable)PY_37isasyncgenfunction)Application   )BaseTestServerRawTestServer
TestClient
TestServerloop_contextsetup_test_loopteardown_test_loopunused_portc                 C   s:   | j ddddd | j dddd	d | j d
dddd d S )N--aiohttp-fast
store_trueFz*run tests faster by disabling extra checks)actiondefaulthelpz--aiohttp-loopZstorepyloopz:run tests with specific loop: pyloop, uvloop, tokio or all--aiohttp-enable-loop-debugzenable event loop debug mode)Z	addoption)parser r   H/opt/alt/python38/lib64/python3.8/site-packages/aiohttp/pytest_plugin.pypytest_addoption!   s$    r   c                    sb   | j  t rdnt r$dndS dd| jkrH|  jd7  _d fdd}|| _ dS )zS
    Allow fixtures to be coroutines. Run coroutine fixtures in an event loop.
    TFNrequestr   c                     sv   |d }r|d= d|j kr$td|d rb| | fdd}||   S  | |S d S )Nr   loopz^Asynchronous fixtures must depend on the 'loop' fixture or be used in tests depending from it.c                      s*   z   W S  tk
r$   Y nX d S N)run_until_complete	__anext__StopAsyncIterationr   _loopgenr   r   	finalizer`   s    z8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer)fixturenames	ExceptionZgetfixturevalueZaddfinalizerr   r   )argskwargsr   r$   funcZis_async_genZstrip_requestr!   r   wrapperK   s    



z%pytest_fixture_setup.<locals>.wrapper)r*   r   asyncioiscoroutinefunctionargnames)Z
fixturedefr+   r   r)   r   pytest_fixture_setup6   s    

 r/   c                 C   s   | j dS )z--fast config optionr   config	getoptionr   r   r   r   fastn   s    r3   c                 C   s   | j dS )z!--enable-loop-debug config optionr   r0   r   r   r   r   
loop_debugt   s    r4   c               	   c   s`   t jddJ} dV  dd | D }|rRtdt|t|dkrBdnd	d
|W 5 Q R X dS )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)recordNc                 S   s"   g | ]}|j tkrd j|dqS )z#{w.filename}:{w.lineno}:{w.message})w)categoryRuntimeWarningformat).0r6   r   r   r   
<listcomp>   s   
z,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}r    s
)warningscatch_warningsRuntimeErrorr9   lenjoin)	_warningsZrwr   r   r   _runtime_warning_contextz   s      rE   Fc                 c   s(   | r| V  nt  } | V  t| |d dS )z{
    setups and tears down a loop unless one is passed in via the loop
    argument when it's passed straight through.
    r3   N)r   r   )r   r3   r   r   r   _passthrough_loop_context   s
    rG   c                 C   s(   |  |r$t|r$t| ||S dS )z/
    Fix pytest collecting for coroutines.
    N)Zfuncnamefilterr,   r-   listZ_genfunctions)Z	collectornameobjr   r   r   pytest_pycollect_makeitem   s    rK   c              
      s    j d}t jr jdp0 jdd}t F t||d.} fdd j	j
D }| jf | W 5 Q R X W 5 Q R X dS dS )	zL
    Run coroutines in an event loop instead of a normal function call.
    r   proactor_loopr   NrF   c                    s   i | ]}| j | qS r   )funcargs)r:   arg
pyfuncitemr   r   
<dictcomp>   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)r1   r2   r,   r-   functionrM   getrE   rG   Z_fixtureinfor.   r   rJ   )rP   r3   Zexisting_loopr"   Ztestargsr   rO   r   pytest_pyfunc_call   s    
&rT   c                 C   s   d| j krd S | jjj}dtji}td k	r4tj|d< td k	rFtj|d< |dkrRd}i }|	dD ]N}|
d }|d	}||kr|r`td
|t| f nq`|| ||< q`| jdt| t| d d S )Nloop_factoryr   uvlooptokioallzpyloop,uvloop?,tokio?,?z ?z&Unknown loop '%s', available loops: %s)Zids)r%   r1   ZoptionZaiohttp_loopr,   ZDefaultEventLoopPolicyrV   ZEventLoopPolicyrW   splitendswithstrip
ValueErrorrH   keysZparametrizevalues)ZmetafuncZloopsZavail_factoriesZ	factoriesrI   Zrequiredr   r   r   pytest_generate_tests   s8    





 
 
ra   c              	   c   sH   |  }t | t|d$}|r*|d t | |V  W 5 Q R X dS )z%Return an instance of the event loop.rF   TN)r,   set_event_loop_policyr   Z	set_debugset_event_loop)rU   r3   r4   policyr"   r   r   r   r      s    


r   c               	   c   sR   t st } tj| _nt } t|  t| j}t	| |V  W 5 Q R X d S r   )
r   r,   Zget_event_loop_policyZProactorEventLoopZ_loop_factoryZWindowsProactorEventLoopPolicyrb   r   Znew_event_looprc   )rd   r"   r   r   r   rL      s    


rL   c                 C   s   t jdtdd | S )Nz3Deprecated, use aiohttp_unused_port fixture instead   
stacklevelr?   warnDeprecationWarning)aiohttp_unused_portr   r   r   r      s    r   c                   C   s   t S )z1Return a port that is unused on the current host.)_unused_portr   r   r   r   rk     s    rk   c                 #   s:   g dd fdd
}|V  fdd}  |  dS )z^Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    Nportc                   s4   t | |d}|jf d i|I d H  | |S Nrm   r   )r
   start_serverappend)Zapprn   r(   serverr   serversr   r   go  s    
zaiohttp_server.<locals>.goc                      s    r    I d H  q d S r   popcloser   rt   r   r   finalize  s    z aiohttp_server.<locals>.finalizer   r   ru   rz   r   rs   r   aiohttp_server	  s
    r}   c                 C   s   t jdtdd | S )Nz.Deprecated, use aiohttp_server fixture insteadre   rf   rh   )r}   r   r   r   test_server   s    r~   c                 #   s:   g dd fdd
}|V  fdd}  |  dS )zpFactory to create a RawTestServer instance, given a web handler.

    aiohttp_raw_server(handler, **kwargs)
    Nrm   c                   s4   t | |d}|jf d i|I d H  | |S ro   )r   rp   rq   )handlerrn   r(   rr   rs   r   r   ru   2  s    
zaiohttp_raw_server.<locals>.goc                      s    r    I d H  q d S r   rv   r   ry   r   r   rz   :  s    z$aiohttp_raw_server.<locals>.finalizer{   r|   r   rs   r   aiohttp_raw_server*  s
    r   c                 C   s   t jdtdd | S )Nz2Deprecated, use aiohttp_raw_server fixture insteadre   rf   rh   )r   r   r   r   raw_test_serverA  s    r   c                 #   s:   g  dd fdd
}|V   fdd} |  dS )zFactory to create a TestClient instance.

    aiohttp_client(app, **kwargs)
    aiohttp_client(server, **kwargs)
    aiohttp_client(raw_server, **kwargs)
    N)server_kwargsc                   s   t | tr.t | ttfs.| f||} i }n|r:tdt | trv|pJi }t| fdi|}t|fdi|}n0t | trt| fdi|}ntdt|  |	 I d H   
| |S )Nzargs should be emptyr   zUnknown argument type: %r)
isinstancer   r   r   AssertionErrorr
   r	   r^   typerp   rq   )Z__paramr   r'   r(   rr   Zclientclientsr   r   r   ru   U  s"     


zaiohttp_client.<locals>.goc                      s    r    I d H  q d S r   rv   r   )r   r   r   rz   n  s    z aiohttp_client.<locals>.finalizer{   r|   r   r   r   aiohttp_clientK  s
    r   c                 C   s   t jdtdd | S )Nz.Deprecated, use aiohttp_client fixture insteadre   rf   rh   )r   r   r   r   test_clientu  s    r   )F),r,   
contextlibr?   collections.abcr   ZpytestZaiohttp.helpersr   r   Zaiohttp.webr   Z
test_utilsr   r   r	   r
   r   r   r   r   rl   rV   ImportErrorrW   r   r/   Zfixturer3   r4   contextmanagerrE   rG   rK   rT   ra   r   rL   rk   r}   r~   r   r   r   r   r   r   r   r   <module>   s`   (

8


"


	


	

	
)