
­­­­­­­­­­­­­­­­­­
<!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-loop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    

 r0   c                 C   s   | j dS )z--fast config optionr   config	getoptionr   r   r   r   fastn   s    r4   c                 C   s   | j dS )z!--enable-loop-debug config optionr   r1   r   r   r   r   
loop_debugt   s    r5   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).0r7   r   r   r   
<listcomp>   s   
z,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}r    s
)warningscatch_warningsRuntimeErrorr:   lenjoin)	_warningsrwr   r   r   _runtime_warning_contextz   s      rG   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.
    r4   N)r   r   )r   r4   r   r   r   _passthrough_loop_context   s
    rI   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    rM   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   NrH   c                    s   i | ]}| j | qS r   )funcargs)r;   arg
pyfuncitemr   r   
<dictcomp>   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)r2   r3   r-   r.   functionrO   getrG   rI   Z_fixtureinfor/   r   rL   )rR   r4   Zexisting_loopr#   Ztestargsr   rQ   r   pytest_pyfunc_call   s    
&rV   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&   r2   optionZaiohttp_loopr-   ZDefaultEventLoopPolicyrX   ZEventLoopPolicyrY   splitendswithstrip
ValueErrorrJ   keysZparametrizevalues)ZmetafuncZloopsZavail_factoriesZ	factoriesrK   requiredr   r   r   pytest_generate_tests   s8    





 
 
re   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.rH   TN)r-   set_event_loop_policyr   Z	set_debugset_event_loop)rW   r4   r5   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WindowsProactorEventLoopPolicyrf   r   Znew_event_looprg   )rh   r#   r   r   r   rN      s    


rN   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   ro     s    ro   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 Nrq   r   )r
   start_serverappend)Zapprr   r)   serverr   serversr   r   go  s    
zaiohttp_server.<locals>.goc                      s    r    I d H  q d S r   popcloser   rx   r   r   finalize  s    z aiohttp_server.<locals>.finalizer   r   ry   r~   r   rw   r   aiohttp_server	  s
    r   c                 C   s   t jdtdd | S )Nz.Deprecated, use aiohttp_server fixture insteadri   rj   rl   )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)
    Nrq   c                   s4   t | |d}|jf d i|I d H  | |S rs   )r   rt   ru   )handlerrr   r)   rv   rw   r   r   ry   2  s    
zaiohttp_raw_server.<locals>.goc                      s    r    I d H  q d S r   rz   r   r}   r   r   r~   :  s    z$aiohttp_raw_server.<locals>.finalizer   r   r   rw   r   aiohttp_raw_server*  s
    r   c                 C   s   t jdtdd | S )Nz2Deprecated, use aiohttp_raw_server fixture insteadri   rj   rl   )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	   ra   typert   ru   )Z__paramr   r(   r)   rv   Zclientclientsr   r   r   ry   U  s"     


zaiohttp_client.<locals>.goc                      s    r    I d H  q d S r   rz   r   )r   r   r   r~   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 insteadri   rj   rl   )r   r   r   r   test_clientu  s    r   )F),r-   
contextlibr@   collections.abcr   pytestZaiohttp.helpersr   r   Zaiohttp.webr   Z
test_utilsr   r   r	   r
   r   r   r   r   rp   rX   ImportErrorrY   r   r0   Zfixturer4   r5   contextmanagerrG   rI   rM   rV   re   r   rN   ro   r   r   r   r   r   r   r   r   r   r   <module>   s`   (

8


"


	


	

	
)