U
    &%e                     @  sP  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	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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e d'ddd(d)d*Zejddd+d,d-Zejddd+d.d/Z dS )0    )annotations)contextmanager)isasyncgenfunctioniscoroutinefunction)AnyDict	GeneratorTuplecastN   )get_all_backendsget_asynclib)
TestRunnerzTestRunner | None_current_runner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   R/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/anyio/pytest_plugin.pyextract_backend_and_options   s    
r   r   zdict[str, Any]z#Generator[TestRunner, object, None])backend_namebackend_optionsr   c              	   c  s   t rt V  d S t| }d }tjd d kr6tj| }z.|p>i }|jf |}|a |V  W 5 Q R X W 5 d a |rztj| X d S N)r   r   sniffioZcurrent_async_library_cvargetsetresetr   )r   r   Zasynclibtokenrunnerr   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_configure4   s    r*   )
fixturedefrequestr   c                   sT    fdd}| j  t s$t rPd|jkrPd| jk|| _ sP|  jd7  _d S )Nc              	   ?  s\   t | \}}r| |d< t||0}t r@| |E d H  n| |V  W 5 Q R X d S )Nanyio_backend)r   r&   r   Zrun_asyncgen_fixtureZrun_fixture)r-   argskwargsr   r   r%   funcZhas_backend_argr   r   wrapper=   s    z%pytest_fixture_setup.<locals>.wrapperr-   r-   )r1   r   r   Zfixturenamesargnames)r+   r,   r2   r   r0   r   pytest_fixture_setup<   s    

r5   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)r7   ).0markerr   r   r   	<genexpr>Z   s     z,pytest_pycollect_makeitem.<locals>.<genexpr>r-   )Zistestfunctionhasattrr9   
inner_testr   Zget_closest_markergetattranypytestmarkZusefixtures)r6   r7   r8   Z
inner_funcr<   Zown_markersr   r   r   pytest_pycollect_makeitemS   s    
rD   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 5 Q R X d
S d S )Nr   r'   )r/   r   c               	     s&   t  }||  W 5 Q R X d S r   )r&   run_test)r/   r%   )r   r   original_funcr   r   run_with_hypothesis`   s    z/pytest_pyfunc_call.<locals>.run_with_hypothesisr-   r9   c                   s   i | ]}| | qS r   r   )r;   arg)funcargsr   r   
<dictcomp>s   s      z&pytest_pyfunc_call.<locals>.<dictcomp>T)rJ   r!   r   r>   r8   r9   r?   __qualname__r   Z_fixtureinfor4   r&   rF   )rE   rH   r   Ztestargsr%   r   )r   r   rJ   rG   r   pytest_pyfunc_call^   s"    


rM   )params)r,   r   c                 C  s   | j S r   )param)r,   r   r   r   r-   |   s    r-   )r-   r   c                 C  s   t | tr| S | d S d S )Nr   r   r   r3   r   r   r   anyio_backend_name   s    
rQ   c                 C  s   t | tri S | d S d S )Nr   rP   r3   r   r   r   anyio_backend_options   s    
rR   )!
__future__r   
contextlibr   inspectr   r   typingr   r   r   r	   r
   rB   r    Z_core._eventloopr   r   abcr   r   __annotations__r   r&   r*   r5   ZhookimplrD   rM   Zfixturer-   rQ   rR   r   r   r   r   <module>   s0    



