o
     d                  
   @   s  U 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
mZmZ d dlZd dlZd dlmZ ddlmZmZ ddlmZ erEd d	lmZ dae
e ed
< dedeeeeef f fddZededeeef de	eedf fddZd,ddZdededdfddZej dddedededdfd d!Z!ej ddd"ede
e" fd#d$Z#ej$e d%dedefd&d'Z%ej$d'edefd(d)Z&ej$d'edeeef fd*d+Z'dS )-    )contextmanager)isasyncgenfunctioniscoroutinefunction)TYPE_CHECKINGAnyDict	GeneratorOptionalTuplecastN)FixtureRequest   )get_all_backendsget_asynclib)
TestRunner)Config_current_runnerbackendreturnc                 C   sf   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)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   >/usr/local/lib/python3.10/dist-packages/anyio/pytest_plugin.pyextract_backend_and_options   s   
r   backend_namebackend_optionsc              	   c   s    t rt V  d S t| }d }tjd d u rtj| }z0|p i }|jdi |}|a |V  W d    n1 s9w   Y  W d a |rKtj| d S d S d a |rXtj| w w )Nr   )r   r   sniffiocurrent_async_library_cvargetsetr   reset)r   r    asynclibtokenrunnerr   r   r   
get_runner   s.   r)   configr   c                 C   s   |  dd d S )NmarkerszManyio: mark the (coroutine function) test to be run asynchronously via anyio.)addinivalue_line)r*   r   r   r   pytest_configure6   s   r-   
fixturedefrequestc                    s`    fdd}| j  t st r,d|jv r*d| jv || _ s.|  jd7  _d S d S d S d S )Nc                 ?   s    t | \}}r| |d< t||&}t r!| |E d H  n| |V  W d    d S W d    d S 1 s;w   Y  d S )Nanyio_backend)r   r)   r   run_asyncgen_fixturerun_fixture)r0   argskwargsr   r    r(   funchas_backend_argr   r   wrapper?   s   "z%pytest_fixture_setup.<locals>.wrapperr0   r0   )r6   r   r   fixturenamesargnames)r.   r/   r8   r   r5   r   pytest_fixture_setup>   s   

r<   T)tryfirst	collectornameobjc                 C   sv   |  ||r5t|dr|jjn|}t|r7| d}t|dd}|s+tdd |D r9tj	
d| d S d S d S d S )N
hypothesisanyio
pytestmarkr   c                 s   s    | ]}|j d kV  qdS )rB   N)r?   ).0markerr   r   r   	<genexpr>\   s    z,pytest_pycollect_makeitem.<locals>.<genexpr>r0   )istestfunctionhasattrrA   
inner_testr   get_closest_markergetattranypytestmarkusefixtures)r>   r?   r@   
inner_funcrE   own_markersr   r   r   pytest_pycollect_makeitemU   s   
rR   
pyfuncitemc                    s   dt dd f fdd}| jd}|rit|\ t| jdr7| jjjj|jkr5t	r5|| jj_d S t	| jri| jfdd| j
jD }t }|| j| W d    d	S 1 sbw   Y  d	S d S )
Nr4   r   c                     s<   t  }||  W d    d S 1 sw   Y  d S N)r)   run_test)r4   r(   )r   r    original_funcr   r   run_with_hypothesisb   s   "z/pytest_pyfunc_call.<locals>.run_with_hypothesisr0   rA   c                    s   i | ]}| | qS r   r   )rD   arg)funcargsr   r   
<dictcomp>u   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)r   rY   r#   r   rH   r@   rA   rI   __qualname__r   _fixtureinfor;   r)   rU   )rS   rW   r   testargsr(   r   )r   r    rY   rV   r   pytest_pyfunc_call`   s(   



r^   )paramsc                 C   s   | j S rT   )param)r/   r   r   r   r0   ~   s   r0   c                 C   s   t | tr| S | d S )Nr   r   r   r9   r   r   r   anyio_backend_name      
rb   c                 C   s   t | tri S | d S )Nr   ra   r9   r   r   r   anyio_backend_options   rc   rd   )r*   r   r   N)(
contextlibr   inspectr   r   typingr   r   r   r   r	   r
   r   rM   r!   _pytest.fixturesr   _core._eventloopr   r   abcr   _pytest.configr   r   __annotations__objectr   r   r)   r-   r<   hookimplrR   boolr^   fixturer0   rb   rd   r   r   r   r   <module>   s@    $"





 