o
    Þ­jç1  ã                   @  s(  U d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
mZ d dlmZmZmZ d dlmZmZ d dlZd dlmZmZ d dlmZ d d	lmZ d d
lmZ ddlmZ ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ej(dk r~d dl)m*Z* da+de,d< da-de,d< d a.dXdd„Z/edYd!d"„ƒZ0dZd&d'„Z1d[d*d+„Z2ej3d,d-�d\d2d3„ƒZ4ej3d,d4�d]d9d:„ƒZ5d^d=d>„Z6ej3d,d4�d_dAdB„ƒZ7ej8dCeƒ dD�d`dEdF„ƒZ9ej8dadGdH„ƒZ:ej8dbdIdJ„ƒZ;G dKdL„ dLƒZ<ej8d;dM�dcdNdO„ƒZ=ej8d;dM�dcdPdQ„ƒZ>ej8dddTdU„ƒZ?ej8dedVdW„ƒZ@dS )fé    )ÚannotationsN)ÚCallableÚ	GeneratorÚIterator)Ú	ExitStackÚcontextmanager)ÚisasyncgenfunctionÚiscoroutinefunctionÚismethod)ÚAnyÚcast)ÚFuncFixtureInfoÚ
SubRequest)ÚExit)Ú	CallSpec2)ÚScopeé   )Úget_available_backends)Úcurrent_async_libraryÚget_async_backendÚreset_current_async_libraryÚset_current_async_library)Úiterate_exceptions)Ú
TestRunner)é   é   )ÚExceptionGroupz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   Ú	TypeError)r   © r*   úP/var/www/html/CropPilot/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ƒ d u rt| ƒ}t t|¡ |pi }t | 	|¡¡a t
d7 a
zt V  W t
d8 a
t
sFtd us<J ‚t ¡  d  aa d S d S t
d8 a
t
s\td usTJ ‚t ¡  d  aa w ©Nr   )r   r   r   r   r   r   Úcallbackr   Úenter_contextÚcreate_test_runnerÚ_runner_leasesÚclose)r-   r.   ÚasynclibÚtokenr*   r*   r+   Ú
get_runner-   s2   €
ÿýÿ
r9   Úparserúpytest.ParserÚNonec                 C  s   | j dddd� d S )NÚ
anyio_modeÚstrictz-AnyIO plugin mode (either "strict" or "auto"))ÚdefaultÚhelp)Úaddini)r:   r*   r*   r+   Úpytest_addoptionK   s
   
ýrB   Úconfigúpytest.Configc                 C  sV   |   dd¡ |  d¡dkr%| j d¡r'|  d¡dkr)|  t d¡d¡ d S d S d S d S )	NÚmarkerszManyio: mark the (coroutine function) test to be run asynchronously via anyio.r=   ÚautoÚasyncioÚasyncio_modezlAnyIO auto mode has been enabled together with pytest-asyncio auto mode. This may cause unexpected behavior.r   )Úaddinivalue_lineÚgetiniÚpluginmanagerÚ
has_pluginÚissue_config_time_warningÚpytestÚPytestConfigWarning)rC   r*   r*   r+   Úpytest_configureS   s    þ
ÿÿûürP   T)ÚhookwrapperÚ
fixturedefr   ÚrequestúGenerator[Any]c                 #  s¢   � d‡ ‡‡fdd„}| j ‰ tˆ ƒstˆ ƒrNd|jv rN|| _ | j}d| jv  ‰s.|  jd	7  _d| jv  ‰s<|  jd
7  _z
d V W ˆ | _ || _S ˆ | _ || _w d V S )NÚanyio_backendr   rS   r   Úkwargsr!   c                 ;  sÆ   � |j rtˆ ƒrtˆ jƒt|j ƒu rˆ j |j ¡}nˆ }t| ƒ\}}ˆr(| |d< ˆr.||d< t||ƒ�&}t|ƒrB| 	||¡E d H  n| 
||¡V  W d   ƒ d S W d   ƒ d S 1 s\w   Y  d S )NrU   rS   )Úinstancer
   ÚtypeÚ__self__Ú__func__Ú__get__r,   r9   r   Úrun_asyncgen_fixtureÚrun_fixture)rU   rS   rV   Ú
local_funcr-   r.   Úrunner©ÚfuncÚhas_backend_argÚhas_request_argr*   r+   Úwrapperh   s(   €ÿþü"þz%pytest_fixture_setup.<locals>.wrapper©rU   ©rS   )rU   r   rS   r   rV   r   r!   r   )ra   r   r	   ÚfixturenamesÚargnames)rR   rS   rd   Úoriginal_argnamer*   r`   r+   Úpytest_fixture_setupf   s$   €
ÿrj   )ÚtryfirstÚ	collectorúpytest.Module | pytest.ClassÚnameÚobjc                 C  sŠ   |   ||¡r?t|dƒr|jjn|}t|ƒrA| j d¡dk}|  d¡}t|ddƒ}|s5|s5t	dd„ |D ƒƒrCt
j d	¡|ƒ d S d S d S d S )
NÚ
hypothesisr=   rF   ÚanyioÚ
pytestmarkr*   c                 s  s   � | ]}|j d kV  qdS )rq   N©rn   )Ú.0Úmarkerr*   r*   r+   Ú	<genexpr>¤   s   € z,pytest_pycollect_makeitem.<locals>.<genexpr>rU   )ÚistestfunctionÚhasattrrp   Ú
inner_testr	   rC   rJ   Úget_closest_markerÚgetattrÚanyrN   ÚmarkÚusefixtures)rl   rn   ro   Ú
inner_funcÚanyio_auto_moderu   Úown_markersr*   r*   r+   Úpytest_pycollect_makeitem—   s    
ÿþýõr‚   Úsessionúpytest.Sessionc                 C  sl  t tt| jƒƒƒD ]ª\}}t|tjƒr³t|jƒr³| 	d¡d ur³d|j
vr³g }zdd„ t t¡D ƒ}W n ty>   tƒ }Y nw ttƒ ƒD ]e\}}d|v r^td|id|idtji|gg d�}nti d|id|idtji|gg d�}|j}t|jƒ}	d|	vr�|	 d¡ t|j|j|	|jd�}
tjj|j|j› d	|› d
�||j|
|j|jd�}| |¡ qD|| j||d …< q	d S )Nrq   rU   c                 S  s   h | ]}|j ’qS r*   rs   )rt   Úfr*   r*   r+   Ú	<setcomp>³   s    z+pytest_collection_finish.<locals>.<setcomp>Ú
_arg2scope)ÚparamsÚindicesr‡   Ú_idlistÚmarks)Úfuncargsrˆ   r‰   Ú	arg2scopeÚidlistr‹   )rh   ÚinitialnamesÚnames_closureÚname2fixturedefsú[ú])rn   ÚcallspecÚcallobjÚfixtureinfoÚkeywordsÚoriginalnamer   )ÚreversedÚlistÚ	enumerateÚitemsr$   rN   ÚFunctionr	   Úfunctionrz   rg   ÚdataclassesÚfieldsr   r)   Úsetr   r   ÚModuleÚ_fixtureinfor�   Úappendr   rh   r�   r‘   Úfrom_parentÚparentr˜   ro   r—   )rƒ   ÚiÚitemÚ	new_itemsÚ	cs_fieldsÚparam_indexr   r”   ÚfiÚnew_names_closureÚnew_fixtureinfoÚnew_itemr*   r*   r+   Úpytest_collection_finish©   sj   
ÿþ

ÿûú	

üù	€Êr°   Ú
pyfuncitemúbool | Nonec                   s  d‡ ‡‡fdd„}| j  d¡}|r‡t|ƒ\‰ ‰t| jdƒr3| jjj‰ˆj|jkr1tˆƒr1|| jj_d S t| jƒr‡| j ‰‡fd	d
„| j	j
D ƒ}tˆ ˆƒ�2}z	| | j|¡ W n tyt } zt|ƒD ]}t|tttfƒrn||‚qa‚ d }~ww W d   ƒ dS 1 s€w   Y  dS d S )NrV   r   r!   r<   c                    s<   t ˆ ˆƒ�}| ˆ| ¡ W d   ƒ d S 1 sw   Y  d S ©N)r9   Úrun_test)rV   r_   )r-   r.   Úoriginal_funcr*   r+   Úrun_with_hypothesiså   s   "ÿz/pytest_pyfunc_call.<locals>.run_with_hypothesisrU   rp   c                   s   i | ]}|ˆ | “qS r*   r*   )rt   Úarg)rŒ   r*   r+   Ú
<dictcomp>ø   s    z&pytest_pyfunc_call.<locals>.<dictcomp>T)rV   r   r!   r<   )rŒ   Úgetr,   rx   ro   rp   ry   Ú__qualname__r	   r£   rh   r9   r´   r   r   r$   r   ÚKeyboardInterruptÚ
SystemExit)r±   r¶   r   Útestargsr_   ÚexcgrpÚexcr*   )r-   r.   rŒ   rµ   r+   Úpytest_pyfunc_callã   s<   


ÿ€ûÿ
þ
ö
rÀ   Úmodule)Úscoperˆ   c                 C  ó   | j S r³   )Úparamrf   r*   r*   r+   rU     ó   rU   c                 C  s   t | tƒr| S | d S )Nr   ©r$   r%   re   r*   r*   r+   Úanyio_backend_name  ó   
rÇ   c                 C  s   t | tƒri S | d S r1   rÆ   re   r*   r*   r+   Úanyio_backend_options  rÈ   rÉ   c                   @  s4   e Zd ZdZddd„Zeddd	„ƒZdddd„Zd
S )ÚFreePortFactoryaO  
    Manages port generation based on specified socket kind, ensuring no duplicate
    ports are generated.

    This class provides functionality for generating available free ports on the
    system. It is initialized with a specific socket kind and can generate ports
    for given address families while avoiding reuse of previously generated ports.

    Users should not instantiate this class directly, but use the
    ``free_tcp_port_factory`` and ``free_udp_port_factory`` fixtures instead. For simple
    uses cases, ``free_tcp_port`` and ``free_udp_port`` can be used instead.
    Úkindúsocket.SocketKindr!   r<   c                 C  s   || _ tt ƒ | _d S r³   )Ú_kindr¡   ÚintÚ
_generated)ÚselfrË   r*   r*   r+   Ú__init__+  s   zFreePortFactory.__init__c                 C  rÃ   )z¦
        The type of socket connection (e.g., :data:`~socket.SOCK_STREAM` or
        :data:`~socket.SOCK_DGRAM`) used to bind for checking port availability

        )rÍ   )rÐ   r*   r*   r+   rË   /  s   zFreePortFactory.kindNÚfamilyúsocket.AddressFamily | NonerÎ   c              
   C  sè   |dur|g}nt jg}t jr| t j¡ 	 d}tƒ �P}|D ]1}| t   || j¡¡}|t jkr1dnd}z	| ||f¡ W n
 t	yF   Y  nw |sO| 
¡ d }q|| jvrd| j |¡ |W  d  ƒ S W d  ƒ n1 snw   Y  q)zµ
        Return an unbound port for the given address family.

        :param family: if omitted, both IPv4 and IPv6 addresses will be tried
        :return: a port number

        NTr   z::1z	127.0.0.1r   )ÚsocketÚAF_INETÚhas_ipv6r¤   ÚAF_INET6r   r3   rÍ   ÚbindÚOSErrorÚgetsocknamerÏ   Úadd)rÐ   rÒ   ÚfamiliesÚportÚstackÚsockÚaddrr*   r*   r+   Ú__call__8  s4   ÿ€
ò€ þzFreePortFactory.__call__)rË   rÌ   r!   r<   )r!   rÌ   r³   )rÒ   rÓ   r!   rÎ   )Ú__name__Ú
__module__rº   Ú__doc__rÑ   ÚpropertyrË   rá   r*   r*   r*   r+   rÊ     s    
rÊ   )rÂ   c                   C  ó
   t tjƒS r³   )rÊ   rÔ   ÚSOCK_STREAMr*   r*   r*   r+   Úfree_tcp_port_factoryZ  ó   
rè   c                   C  ræ   r³   )rÊ   rÔ   Ú
SOCK_DGRAMr*   r*   r*   r+   Úfree_udp_port_factory_  ré   rë   úCallable[[], int]rÎ   c                 C  ó   | ƒ S r³   r*   )rè   r*   r*   r+   Úfree_tcp_portd  rÅ   rî   c                 C  rí   r³   r*   )rë   r*   r*   r+   Úfree_udp_porti  rÅ   rï   )r   r    r!   r"   )r-   r%   r.   r/   r!   r0   )r:   r;   r!   r<   )rC   rD   r!   r<   )rR   r   rS   r   r!   rT   )rl   rm   rn   r%   ro   r    r!   r<   )rƒ   r„   r!   r<   )r±   r   r!   r²   )rS   r   r!   r   )rU   r   r!   r%   )rU   r   r!   r/   )r!   rÊ   )rè   rì   r!   rÎ   )rë   rì   r!   rÎ   )AÚ
__future__r   rŸ   rÔ   ÚsysÚcollections.abcr   r   r   Ú
contextlibr   r   Úinspectr   r	   r
   Útypingr   r   rN   Ú_pytest.fixturesr   r   Ú_pytest.outcomesr   Ú_pytest.pythonr   Ú_pytest.scoper   Ú r   Ú_core._eventloopr   r   r   r   Ú_core._exceptionsr   Úabcr   Úversion_infoÚexceptiongroupr   r   Ú__annotations__r   r5   r,   r9   rB   rP   Úhookimplrj   r‚   r°   rÀ   ÚfixturerU   rÇ   rÉ   rÊ   rè   rë   rî   rï   r*   r*   r*   r+   Ú<module>   sb    






0

:$
=
