o
    f
                     @  s0  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d7ddZed8ddZd9ddZd:d"d#Zejd$d%d;d)d*Zejd$d%d<d-d.Z ej!d/e d0d=d1d2Z"ej!d>d3d4Z#ej!d?d5d6Z$dS )@    )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backendobjectreturntuple[str, dict[str, Any]]c                 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   K/var/www/NoticeGen/venv/lib/python3.10/site-packages/anyio/pytest_plugin.pyextract_backend_and_options   s   
r   backend_namer   backend_optionsdict[str, Any]Iterator[TestRunner]c                 c  s    t d u r.t| }t atjd d u r"tj| }ttjj	| |p%i }t
||a td7 azt V  W td8 atsMtd usCJ t  d  aa d S d S td8 atsctd us[J t  d  aa w Nr   )r   r   r   r   sniffiocurrent_async_library_cvargetsetcallbackresetenter_contextcreate_test_runner_runner_leasesclose)r    r!   asynclibtokenr   r   r   
get_runner   s2   
r1   configr   Nonec                 C  s   |  dd d S )NmarkerszManyio: mark the (coroutine function) test to be run asynchronously via anyio.)addinivalue_line)r2   r   r   r   pytest_configure;   s   r6   
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   r1   r   run_asyncgen_fixturerun_fixture)r9   argskwargsr    r!   runnerfunchas_backend_argr   r   wrapperD   s   "z%pytest_fixture_setup.<locals>.wrapperr9   r9   )r@   r   r   fixturenamesargnames)r7   r8   rB   r   r?   r   pytest_fixture_setupC   s   

rF   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 )rL   N)rI   ).0markerr   r   r   	<genexpr>a   s    z,pytest_pycollect_makeitem.<locals>.<genexpr>r9   )istestfunctionhasattrrK   
inner_testr   get_closest_markergetattranypytestmarkusefixtures)rH   rI   rJ   
inner_funcrO   own_markersr   r   r   pytest_pycollect_makeitemZ   s   
r\   
pyfuncitembool | Nonec                   s   d fdd}| j d}|ret|\ t| jdr3| jjjj|jkr1tr1|| jj_d S t| jre| j fd	d
| j	j
D }t }|| j| W d    dS 1 s^w   Y  dS d S )Nr=   r   r   r3   c                    s<   t  }||  W d    d S 1 sw   Y  d S N)r1   run_test)r=   r>   )r    r!   original_funcr   r   run_with_hypothesisg   s   "z/pytest_pyfunc_call.<locals>.run_with_hypothesisr9   rK   c                   s   i | ]}| | qS r   r   )rN   arg)funcargsr   r   
<dictcomp>z   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)r=   r   r   r3   )rd   r'   r   rR   rJ   rK   rS   __qualname__r   _fixtureinforE   r1   r`   )r]   rb   r   testargsr>   r   )r    r!   rd   ra   r   pytest_pyfunc_calle   s(   



ri   module)scopeparamsc                 C  s   | j S r_   )param)r8   r   r   r   r9      s   r9   c                 C  s   t | tr| S | d S )Nr   r   r   rC   r   r   r   anyio_backend_name      
ro   c                 C  s   t | tri S | d S r$   rn   rC   r   r   r   anyio_backend_options   rp   rq   )r   r   r   r   )r    r   r!   r"   r   r#   )r2   r   r   r3   )r7   r   r8   r   r   r3   )rH   r   rI   r   rJ   r   r   r3   )r]   r   r   r^   )r8   r   r   r   )r9   r   r   r   )r9   r   r   r"   )%
__future__r   collections.abcr   
contextlibr   r   inspectr   r   typingr   r	   r
   r   rW   r%   _core._eventloopr   r   abcr   r   __annotations__r   r-   r   r1   r6   rF   hookimplr\   ri   fixturer9   ro   rq   r   r   r   r   <module>   s6    






