a
    8öje2  ã                   @   sZ  d dl Z d dlZd dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZmZ d dlZddlmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZ zd dlZW n e y¾   dZY n0 G dd„ deƒZ!G d	d
„ d
eƒZ"G dd„ deƒZ#dd„ Z$dd„ Z%ej&dd„ ƒZ'ej&dd„ ƒZ(ej)dd„ ƒZ*ej)d8dd„ƒZ+dd„ Z,dd„ Z-dd„ Z.ej&eg e j/f e0e0e	e j/ d œd!d"„ƒZ1ej&e	e j/ d#œd$d%„ƒZ2ej&eg e3f eg e3f d&œd'd(„ƒZej&eg e3f d#œd)d*„ƒZ4ej&e j/e	e" d+œd,d-„ƒZ5ej&d.d/„ ƒZ6ej&e j/e	e# d+œd0d1„ƒZ7ej&d2d3„ ƒZ8ej&e j/e	e! d+œd4d5„ƒZ9ej&d6d7„ ƒZ:dS )9é    N)	ÚAnyÚ	AwaitableÚCallableÚDictÚIteratorÚOptionalÚProtocolÚUnionÚoverloadé   )ÚBaseTestServerÚRawTestServerÚ
TestClientÚ
TestServerÚloop_contextÚsetup_test_loopÚteardown_test_loopÚunused_port)ÚApplicationÚBaseRequestÚRequest)Ú_RequestHandlerc                   @   sp   e Zd Zeddœeeeeef  ee	e
ef dœdd„ƒZeddœeeeeef  ee	edf dœdd„ƒZdS )ÚAiohttpClientN©Úserver_kwargs)Ú_AiohttpClient__paramr   ÚkwargsÚreturnc                Ë   s   d S ©N© ©Úselfr   r   r   r   r   úT/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/aiohttp/pytest_plugin.pyÚ__call__'   s    zAiohttpClient.__call__c                Ë   s   d S r   r   r    r   r   r"   r#   /   s    )Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   Ústrr   r   r   r#   r   r   r   r   r   r"   r   &   s    ü
úü
úr   c                   @   s.   e Zd Zddœeee eee dœdd„Z	dS )ÚAiohttpServerN©Úport)Úappr*   r   r   c                K   s   d S r   r   )r!   r+   r*   r   r   r   r"   r#   :   s    zAiohttpServer.__call__)
r$   r%   r&   r   r   Úintr   r   r   r#   r   r   r   r"   r(   9   s
   ÿ
þr(   c                   @   s.   e Zd Zddœeee eee dœdd„Z	dS )ÚAiohttpRawServerNr)   ©Úhandlerr*   r   r   c                K   s   d S r   r   )r!   r/   r*   r   r   r   r"   r#   @   s    zAiohttpRawServer.__call__)
r$   r%   r&   r   r   r,   r   r   r   r#   r   r   r   r"   r-   ?   s
   ÿ
þr-   c                 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Úpyloopz3run tests with specific loop: pyloop, uvloop or allú--aiohttp-enable-loop-debugzenable event loop debug mode)Z	addoption)Úparserr   r   r"   Úpytest_addoptionE   s$    üüür9   c                    sd   | j ‰ t ˆ ¡rd‰nt ˆ ¡r&d‰ndS d‰d| jvrJ|  jd7  _d‰‡ ‡‡fdd„}|| _ dS )zjSet up pytest fixture.

    Allow fixtures to be coroutines. Run coroutine fixtures in an event loop.
    TFNÚrequest©r:   c                     s~   |d }ˆr|d= d|j vr$tdƒ‚| d¡‰ ˆrfˆ| i |¤Ž‰‡ ‡fdd„}| |¡ ˆ  ˆ ¡ ¡S ˆ  ˆ| i |¤Ž¡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y"   Y n0 d S r   )Úrun_until_completeÚ	__anext__ÚStopAsyncIterationr   ©Ú_loopÚgenr   r"   Ú	finalizer…   s    z8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer)ÚfixturenamesÚ	ExceptionZgetfixturevalueZaddfinalizerr=   r>   )Úargsr   r:   rC   ©ÚfuncZis_async_genZstrip_requestr@   r"   Úwrapperp   s    
ÿ

z%pytest_fixture_setup.<locals>.wrapper)rH   ÚinspectÚisasyncgenfunctionÚiscoroutinefunctionÚargnames)Z
fixturedefrI   r   rG   r"   Úpytest_fixture_setupZ   s    


 rN   c                 C   s   | j  d¡S )z--fast config optionr0   ©ÚconfigÚ	getoptionr;   r   r   r"   Úfast“   s    rR   c                 C   s   | j  d¡S )z!--enable-loop-debug config optionr7   rO   r;   r   r   r"   Ú
loop_debug™   s    rS   c               	   c   st   t jdd��T} dV  dd„ | D ƒ}|rRtd t|ƒt|ƒdkrBdnd	d
 |¡¡ƒ‚W d  ƒ n1 sf0    Y  dS )záContext manager which checks for RuntimeWarnings.

    This exists 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)Ú.0rU   r   r   r"   Ú
<listcomp>ª   s   
þz,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}r   Ú ÚsÚ
)ÚwarningsÚcatch_warningsÚRuntimeErrorrX   ÚlenÚjoin)Ú	_warningsÚrwr   r   r"   Ú_runtime_warning_contextŸ   s    	þ ÿÿre   Fc                 c   s(   | r| V  nt ƒ } | V  t| |d� dS )z–Passthrough loop context.

    Sets up and tears down a loop unless one is passed in via the loop
    argument when it's passed straight through.
    ©rR   N)r   r   )r<   rR   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funcnamefilterrJ   rL   ÚlistZ_genfunctions)Ú	collectorÚnameÚobjr   r   r"   Úpytest_pycollect_makeitemÈ   s    rl   c              	      sÐ   ˆ j  d¡}t ˆ j¡rÌˆ j d¡pHˆ j d¡pHˆ j d¡pHˆ j dd¡}tƒ �h t||d��<}‡ fdd	„ˆ j	j
D ƒ}| ˆ jf i |¤Ž¡ W d  ƒ n1 s 0    Y  W d  ƒ n1 s¾0    Y  d
S dS )zBRun coroutines in an event loop instead of a normal function call.r0   Úproactor_loopZselector_loopZuvloop_loopr<   Nrf   c                    s   i | ]}|ˆ j | “qS r   )Úfuncargs)rY   Úarg©Ú
pyfuncitemr   r"   Ú
<dictcomp>Û   s   ÿz&pytest_pyfunc_call.<locals>.<dictcomp>T)rP   rQ   rJ   rL   Úfunctionrn   Úgetre   rg   Z_fixtureinforM   r=   rk   )rq   rR   Zexisting_looprA   Ztestargsr   rp   r"   Úpytest_pyfunc_callÎ   s     
ÿ
þü
þRru   c                 C   sÂ   d| j vrd S | jjj}dtji}td ur4tj|d< |dkr@d}i }| d¡D ]N}| d¡ }| 	d¡}||vr�|rNt
d	|t| ¡ ƒf ƒ‚nqN|| ||< qN| jdt| ¡ ƒt| ¡ ƒd
� d S )NÚloop_factoryr6   ÚuvloopÚallzpyloop,uvloop?ú,ú?z ?z&Unknown loop '%s', available loops: %s)Zids)rD   rP   ÚoptionZaiohttp_loopÚasyncioZnew_event_looprw   ÚsplitÚendswithÚstripÚ
ValueErrorrh   ÚkeysZparametrizeÚvalues)ZmetafuncZloopsZavail_factoriesZ	factoriesrj   Úrequiredr   r   r"   Úpytest_generate_testsä   s0    




ÿÿÿr„   )rv   rR   rS   r   c                 c   sN   t | |d��.}|r| d¡ t |¡ |V  W d  ƒ n1 s@0    Y  dS )z%Return an instance of the event loop.rf   TN)r   Z	set_debugr|   Úset_event_loop)rv   rR   rS   rA   r   r   r"   r<     s
    

r<   ©r   c                  c   sB   t j} t| ƒ� }t  |¡ |V  W d   ƒ n1 s40    Y  d S r   )r|   ZProactorEventLoopr   r…   )ÚfactoryrA   r   r   r"   rm     s    

rm   )Úaiohttp_unused_portr   c                 C   s   t jdtdd� | S )Nz3Deprecated, use aiohttp_unused_port fixture insteadé   ©Ú
stacklevel©r^   ÚwarnÚDeprecationWarning)rˆ   r   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"   rˆ   %  s    rˆ   )r<   r   c                 #   sT   g ‰dddœt ttt ttdœ‡ ‡fdd„}|V  ddœ‡fdd	„}ˆ  |ƒ ¡ dS )
z^Factory to create a TestServer instance, given an app.

    aiohttp_server(app, **kwargs)
    z	127.0.0.1N©Úhostr*   )r+   r‘   r*   r   r   c                ›   s6   t | ||d�}|jf dˆ i|¤ŽI d H  ˆ |¡ |S )Nr�   r<   )r   Ústart_serverÚappend)r+   r‘   r*   r   Úserver©r<   Úserversr   r"   Úgo3  s    
zaiohttp_server.<locals>.gor†   c                   “   s   ˆ rˆ   ¡  ¡ I d H  q d S r   ©ÚpopÚcloser   ©r–   r   r"   ÚfinalizeA  s    z aiohttp_server.<locals>.finalize)r   r'   r   r,   r   r   r=   ©r<   r—   rœ   r   r•   r"   Úaiohttp_server+  s    üúrž   c                 C   s   t jdtdd� | S )Nz.Deprecated, use aiohttp_server fixture insteadr‰   rŠ   rŒ   )rž   r   r   r"   Útest_serverH  s    ýrŸ   c                 #   sP   g ‰ddœt tt ttdœ‡ ‡fdd„}|V  ddœ‡fdd„}ˆ  |ƒ ¡ dS )	zpFactory to create a RawTestServer instance, given a web handler.

    aiohttp_raw_server(handler, **kwargs)
    Nr)   r.   c                ›   s4   t | |d�}|jf dˆ i|¤ŽI d H  ˆ |¡ |S )Nr)   r<   )r   r’   r“   )r/   r*   r   r”   r•   r   r"   r—   Z  s    
zaiohttp_raw_server.<locals>.gor†   c                   “   s   ˆ rˆ   ¡  ¡ I d H  q d S r   r˜   r   r›   r   r"   rœ   d  s    z$aiohttp_raw_server.<locals>.finalize)r   r   r,   r   r   r=   r�   r   r•   r"   Úaiohttp_raw_serverR  s    ÿ
þr    c                 C   s   t jdtdd� | S )Nz2Deprecated, use aiohttp_raw_server fixture insteadr‰   rŠ   rŒ   )r    r   r   r"   Úraw_test_serverk  s    ýr¡   c                 #   sÎ   g ‰ t ddœtttttf  ttttf dœdd„ƒ}t ddœtttttf  ttt	df dœdd„ƒ}ddœt
ttf tttttf  ttttf dœ‡ ‡fdd„}|V  dd	œ‡ 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)
    Nr   )Ú__paramr   r   r   c                Û   s   d S r   r   ©r¢   r   r   r   r   r"   r—   �  s    zaiohttp_client.<locals>.goc                Û   s   d S r   r   r£   r   r   r"   r—   ‰  s    )r¢   rF   r   r   r   c                Ÿ   sÈ   t | tƒr4t | ttfƒs4| ˆg|¢R i |¤Ž} i }n|r@J dƒ‚t | tƒr||pPi }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   r   r   r€   Útyper’   r“   )r¢   r   rF   r   r”   Úclient©Úclientsr<   r   r"   r—   ‘  s     ÿ


r†   c                   “   s   ˆ rˆ   ¡  ¡ I d H  q d S r   r˜   r   )r¨   r   r"   rœ   ®  s    z aiohttp_client.<locals>.finalize)r
   r   r   r   r'   r   r   r   r   r   r	   r=   r�   r   r§   r"   Úaiohttp_clientw  s8    ý
ûý
û
ý

ûr©   c                 C   s   t jdtdd� | S )Nz.Deprecated, use aiohttp_client fixture insteadr‰   rŠ   rŒ   )r©   r   r   r"   Útest_clientµ  s    ýrª   )F);r|   Ú
contextlibrJ   r^   Útypingr   r   r   r   r   r   r   r	   r
   ZpytestZ
test_utilsr   r   r   r   r   r   r   r   r�   Zwebr   r   r   Zweb_protocolr   rw   ÚImportErrorr   r(   r-   r9   rN   ZfixturerR   rS   Úcontextmanagerre   rg   rl   ru   r„   ZAbstractEventLoopÚboolr<   rm   r,   rˆ   rž   rŸ   r    r¡   r©   rª   r   r   r   r"   Ú<module>   sh   ,(

9


 ü"	
	
=