a
    ø£BeÓ  ã                   @  sZ  U d dl mZ 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 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d(eƒ d)�ddd*œd+d,„ƒZejddd-œd.d/„ƒZ ejddd-œd0d1„ƒZ!dS )2é    )Úannotations)ÚIterator)Úcontextmanager)ÚisasyncgenfunctionÚiscoroutinefunction)ÚAnyÚDictÚTupleÚcastNé   )Úget_all_backendsÚget_async_backend)Ú
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   úV/home/yuhw/wc/wire-cell-python/wcpy/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 rt V  d S t| ƒ}d }tj d ¡d u r6tj | ¡}zT|p>i }| |¡�}|a |V  W d   ƒ n1 sj0    Y  W d a |r¢tj |¡ nd a |r tj |¡ 0 d S ©N)r   r   ÚsniffioZcurrent_async_library_cvarÚgetÚsetZcreate_test_runnerÚreset)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_configure6   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)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,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_makeitemU   s    
rE   zbool | None)Ú
pyfuncitemr   c                   sÒ   dddœ‡ ‡‡fdd„}| j  d¡}|rÎt|ƒ\‰ ‰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 sÀ0    Y  d
S d S )Nr   r'   )r/   r   c                    s:   t ˆ ˆƒ�}| ˆ| ¡ W d   ƒ n1 s,0    Y  d S r   )r&   Úrun_test)r/   r%   )r   r   Úoriginal_funcr   r   Úrun_with_hypothesisb   s    z/pytest_pyfunc_call.<locals>.run_with_hypothesisr-   r9   c                   s   i | ]}|ˆ | “qS r   r   )r;   Úarg)Úfuncargsr   r   Ú
<dictcomp>u   r>   z&pytest_pyfunc_call.<locals>.<dictcomp>T)rK   r!   r   r?   r8   r9   r@   Ú__qualname__r   Z_fixtureinfor4   r&   rG   )rF   rI   r   Ztestargsr%   r   )r   r   rK   rH   r   Úpytest_pyfunc_call`   s"    


,rN   Úmodule)ÚscopeÚ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    
rT   c                 C  s   t | tƒri S | d S d S )Nr   rS   r3   r   r   r   Úanyio_backend_options‹   s    
rU   )"Ú
__future__r   Úcollections.abcr   Ú
contextlibr   Úinspectr   r   Útypingr   r   r	   r
   rC   r    Z_core._eventloopr   r   Úabcr   r   Ú__annotations__r   r&   r*   r5   ZhookimplrE   rN   Zfixturer-   rT   rU   r   r   r   r   Ú<module>   s0   



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