U
    ;gE/                     @   s,  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 ddlmZ zd dlZW n ek
r   dZY nX 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'd7ddZ)dd Z*dd Z+dd Z,ej$d d! Z-ej$d"d# Z.ej$eg e/f eg e/f d$d%d&Zej$eg e/f d'd(d)Z0ej$e j1e	e  d*d+d,Z2ej$d-d. Z3ej$e j1e	e! d*d/d0Z4ej$d1d2 Z5ej$e j1e	e d*d3d4Z6ej$d5d6 Z7dS )8    N)	Any	AwaitableCallableDictIteratorOptionalProtocolTypeUnion   )BaseTestServerRawTestServer
TestClient
TestServerloop_contextsetup_test_loopteardown_test_loopunused_port)Application)_RequestHandlerc                   @   s>   e Zd Zddeeef eeee	f  e	e
e dddZdS )AiohttpClientNserver_kwargs)_AiohttpClient__paramr   kwargsreturnc                K   s   d S N )selfr   r   r   r   r   U/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/aiohttp/pytest_plugin.py__call__'   s    zAiohttpClient.__call__)__name__
__module____qualname__r
   r   r   r   r   strr   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    1   s    zAiohttpServer.__call__)
r!   r"   r#   r   r   intr   r   r   r    r   r   r   r   r%   0   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    7   s    zAiohttpRawServer.__call__)
r!   r"   r#   r   r   r*   r   r   r   r    r   r   r   r   r+   6   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_addoption<   s$    r7   c                    sd   | j  t rdnt r&dndS dd| jk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r8   c                     sv   |d }r|d= d|j kr$td|d rb| | fdd}||   S  | |S d S )Nr8   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 r   )run_until_complete	__anext__StopAsyncIterationr   _loopgenr   r   	finalizer|   s    z8pytest_fixture_setup.<locals>.wrapper.<locals>.finalizer)fixturenames	ExceptionZgetfixturevalueZaddfinalizerr;   r<   )argsr   r8   rA   funcZis_async_genZstrip_requestr>   r   wrapperg   s    



z%pytest_fixture_setup.<locals>.wrapper)rF   inspectisasyncgenfunctionasyncioiscoroutinefunctionargnames)Z
fixturedefrG   r   rE   r   pytest_fixture_setupQ   s    


 rM   c                 C   s   | j dS )z--fast config optionr.   config	getoptionr9   r   r   r   fast   s    rQ   c                 C   s   | j dS )z!--enable-loop-debug config optionr5   rN   r9   r   r   r   
loop_debug   s    rR   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 )zContext 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).0rT   r   r   r   
<listcomp>   s   
z,_runtime_warning_context.<locals>.<listcomp>z{} Runtime Warning{},
{}r    s
)warningscatch_warningsRuntimeErrorrW   lenjoin)	_warningsrwr   r   r   _runtime_warning_context   s    	  rd   Fc                 c   s(   | r| V  nt  } | V  t| |d dS )zPassthrough loop context.

    Sets up and tears down a loop unless one is passed in via the loop
    argument when it's passed straight through.
    rQ   N)r   r   )r:   rQ   r   r   r   _passthrough_loop_context   s
    rf   c                 C   s(   |  |r$t|r$t| ||S dS )z%Fix pytest collecting for coroutines.N)ZfuncnamefilterrJ   rK   listZ_genfunctions)	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 )	zBRun coroutines in an event loop instead of a normal function call.r.   proactor_loopr:   Nre   c                    s   i | ]}| j | qS r   )funcargs)rX   arg
pyfuncitemr   r   
<dictcomp>   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)rO   rP   rJ   rK   functionrm   getrd   rf   Z_fixtureinforL   r;   rj   )rp   rQ   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< |dkr@d}i }|dD ]N}|	d }|
d}||kr|rNtd	|t| f nqN|| ||< qN| jdt| t| d
 d S )Nloop_factoryr4   uvloopallzpyloop,uvloop?,?z ?z&Unknown loop '%s', available loops: %s)Zids)rB   rO   optionZaiohttp_looprJ   ZDefaultEventLoopPolicyrv   ZEventLoopPolicysplitendswithstrip
ValueErrorrg   keysZparametrizevalues)ZmetafuncZloopsZavail_factoriesZ	factoriesri   requiredr   r   r   pytest_generate_tests   s4    




 
 
r   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.re   TN)rJ   set_event_loop_policyr   Z	set_debugset_event_loop)ru   rQ   rR   policyr?   r   r   r   r:      s    


r:   c               	   c   s<   t  } t |  t| j}t | |V  W 5 Q R X d S r   )rJ   ZWindowsProactorEventLoopPolicyr   r   Znew_event_loopr   )r   r?   r   r   r   rl     s
    

rl   )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   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                 #   sP   g dd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)
    Nr&   r(   c                   s4   t | |d}|jf d i|I d H  | |S Nr&   r:   )r   start_serverappend)r)   r'   r   serverr:   serversr   r   go%  s    
zaiohttp_server.<locals>.gor   c                      s    r    I d H  q d S r   popcloser   r   r   r   finalize/  s    z aiohttp_server.<locals>.finalize)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_server6  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 r   )r   r   r   )r-   r'   r   r   r   r   r   r   H  s    
zaiohttp_raw_server.<locals>.gor   c                      s    r    I d H  q d S r   r   r   r   r   r   r   R  s    z$aiohttp_raw_server.<locals>.finalize)r   r   r*   r   r   r;   r   r   r   r   aiohttp_raw_server@  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_serverY  s    r   c                 #   sb   g  ddt ttf tttttf  ttd fdd}|V  dd fdd}|  dS )	zFactory to create a TestClient instance.

    aiohttp_client(app, **kwargs)
    aiohttp_client(server, **kwargs)
    aiohttp_client(raw_server, **kwargs)
    Nr   )__paramrD   r   r   r   c                   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~   typer   r   )r   r   rD   r   r   clientclientsr:   r   r   r   q  s"     


zaiohttp_client.<locals>.gor   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   aiohttp_cliente  s    

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)8rJ   
contextlibrH   r]   typingr   r   r   r   r   r   r   r	   r
   ZpytestZ
test_utilsr   r   r   r   r   r   r   r   r   Zwebr   Zweb_protocolr   rv   ImportErrorr   r%   r+   r7   rM   ZfixturerQ   rR   contextmanagerrd   rf   rk   rt   r   r:   rl   r*   r   ZAbstractEventLoopr   r   r   r   r   r   r   r   r   r   <module>   sd   ,(


9


 

	"	
	
0