
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!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 )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	   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


"


	


	

	
)