a
    Of
                     @  sn  U d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZmZmZmZ d dlZd dlZddlmZmZ dd	lmZ dad
ed< daded< d adddddZeddddddZdddddZdddddd Zejd!d"ddddd#d$d%Zejd!d"dd&d'd(d)Z ej!d*e d+ddd,d-d.Z"ej!ddd/d0d1Z#ej!ddd/d2d3Z$dS )4    )annotations)Iterator)	ExitStackcontextmanager)isasyncgenfunctioniscoroutinefunction)AnyDictTuplecastN   )get_all_backendsget_async_backend)
TestRunnerzTestRunner | None_current_runnerzExitStack | None_runner_stackobjectztuple[str, dict[str, Any]])backendreturnc                 C  sj   t | tr| i fS t | tr^t| dkr^t | d tr^t | d tr^ttttttf f | S t	dd S )N   r   r   z@anyio_backend must be either a string or tuple of (string, dict))

isinstancestrtuplelendictr   r
   r	   r   	TypeError)r    r   L/var/www/ai-form-bot/venv/lib/python3.9/site-packages/anyio/pytest_plugin.pyextract_backend_and_options   s    
r   r   zdict[str, Any]zIterator[TestRunner])backend_namebackend_optionsr   c                 c  s   t d u rZt| }t atjd d u rBtj| }ttjj	| |pHi }t
||a td7 az2t V  W td8 atstd usJ t  d  aa n*td8 atstd usJ t  d  aa 0 d S Nr   )r   r   r   r   sniffioZcurrent_async_library_cvargetsetcallbackresetenter_contextZcreate_test_runner_runner_leasesclose)r   r    Zasynclibtokenr   r   r   
get_runner   s.    
r+   r   None)configr   c                 C  s   |  dd d S )NmarkerszManyio: mark the (coroutine function) test to be run asynchronously via anyio.)Zaddinivalue_line)r-   r   r   r   pytest_configure;   s    r/   )
fixturedefrequestr   c                   sT    fdd}| j  t s$t rPd|jv rPd| jv || _ sP|  jd7  _d S )Nc                 ?  sp   t | \}}r| |d< t||:}t r@| |E d H  n| |V  W d    n1 sb0    Y  d S )Nanyio_backend)r   r+   r   Zrun_asyncgen_fixtureZrun_fixture)r2   argskwargsr   r    runnerfuncZhas_backend_argr   r   wrapperD   s    z%pytest_fixture_setup.<locals>.wrapperr2   r2   )r7   r   r   Zfixturenamesargnames)r0   r1   r8   r   r6   r   pytest_fixture_setupC   s    

r;   T)Ztryfirst)	collectornameobjr   c                 C  sj   |  ||rft|dr|jjn|}t|rf| d}t|dd}|sVtdd |D rftj	
d| d S )N
hypothesisanyioZ
pytestmarkr   c                 s  s   | ]}|j d kV  qdS )r@   N)r=   ).0markerr   r   r   	<genexpr>a       z,pytest_pycollect_makeitem.<locals>.<genexpr>r2   )Zistestfunctionhasattrr?   
inner_testr   Zget_closest_markergetattranypytestmarkZusefixtures)r<   r=   r>   Z
inner_funcrB   Zown_markersr   r   r   pytest_pycollect_makeitemZ   s    
rK   zbool | None)
pyfuncitemr   c                   s   ddd fdd}| j d}|rt|\ t| jdrl| jjjj|jkrhtrh|| jj_d S t| jr| j fdd	| j	j
D }t }|| j| W d    n1 s0    Y  d
S d S )Nr   r,   )r4   r   c                    s:   t  }||  W d    n1 s,0    Y  d S N)r+   run_test)r4   r5   )r   r    original_funcr   r   run_with_hypothesisg   s    z/pytest_pyfunc_call.<locals>.run_with_hypothesisr2   r?   c                   s   i | ]}| | qS r   r   )rA   arg)funcargsr   r   
<dictcomp>z   rD   z&pytest_pyfunc_call.<locals>.<dictcomp>T)rR   r#   r   rE   r>   r?   rF   __qualname__r   Z_fixtureinfor:   r+   rN   )rL   rP   r   Ztestargsr5   r   )r   r    rR   rO   r   pytest_pyfunc_calle   s"    


,rU   module)scopeparams)r1   r   c                 C  s   | j S rM   )param)r1   r   r   r   r2      s    r2   )r2   r   c                 C  s   t | tr| S | d S d S )Nr   r   r   r9   r   r   r   anyio_backend_name   s    
r[   c                 C  s   t | tri S | d S d S r!   rZ   r9   r   r   r   anyio_backend_options   s    
r\   )%
__future__r   collections.abcr   
contextlibr   r   inspectr   r   typingr   r	   r
   r   rI   r"   Z_core._eventloopr   r   abcr   r   __annotations__r   r(   r   r+   r/   r;   ZhookimplrK   rU   Zfixturer2   r[   r\   r   r   r   r   <module>   s4   



