
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!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 )zžFactory 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ƒr–t| 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


"


	


	

	
)