a
    (ñ»jŽ1  ã                   @  sx  d dl mZ d dlZd dlZd dlmZmZ erDd dl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dlmZmZ dd	lmZmZmZmZmZmZmZmZmZ dd
lm Z  ej!dk rÒd dl"m#Z#m$Z$ erâd dlmZ edƒZ%ddœdd„Z&ddœdd„Z'ddœdd„Z(ej) *d¡ddœdd„ƒZ+ddœdd„Z,ddœdd„Z-ddœdd„Z.ddœd d!„Z/ddœd"d#„Z0dS )$é    )ÚannotationsN)ÚTYPE_CHECKINGÚTypeVar)ÚAsyncGeneratorÚ	CoroutineÚ	Generator)ÚMatcherÚRaisesGroupé   )Ú_core)Ú!create_asyncio_future_in_new_loopÚ'ignore_coroutine_never_awaited_warnings)	ÚConflictDetectorÚMultipleExceptionErrorÚNoPublicConstructorÚcoroutine_or_errorÚfinalÚfixup_module_metadataÚgeneric_functionÚis_main_threadÚ!raise_single_exception_from_group©Úwait_all_tasks_blocked©é   é   )ÚBaseExceptionGroupÚExceptionGroup)r   ÚTÚNone©Úreturnc               
   ƒ  st  t dƒ‰ t dƒ} ˆ �< | � tdƒ W d   ƒ n1 s80    Y  W d   ƒ n1 sV0    Y  tjtjdd��X ˆ �4 ˆ � W d   ƒ n1 s’0    Y  W d   ƒ n1 s°0    Y  W d   ƒ n1 sÎ0    Y  ddœ‡ fdd„}tttjdƒƒ�d t ¡ 4 I d H š,}| 	|¡ | 	|¡ W d   ƒI d H  �qP1 I d H �sF0    Y  W d   ƒ n1 �sf0    Y  d S )	NÚul1Úul2Úok©Úmatchr   r    c                   “  s4   ˆ � t ƒ I d H  W d   ƒ n1 s&0    Y  d S ©Nr   © ©r"   r(   ú;E:\soccer\ml_env\Lib\site-packages\trio/_tests/test_util.pyÚwait_with_ul16   s    z,test_ConflictDetector.<locals>.wait_with_ul1)
r   ÚprintÚpytestÚraisesr   ZBusyResourceErrorr	   r   Úopen_nurseryZ
start_soon)r#   r+   Znurseryr(   r)   r*   Útest_ConflictDetector)   s    DZ
r0   c                  C  s  dd l } dd l} | jjdks J ‚| jjdks0J ‚| jjjdksBJ ‚| jjjdksTJ ‚| j	j
jdksfJ ‚| jjjjdkszJ ‚| jjjjdksŽJ ‚| jjdksžJ ‚| jjdks®J ‚| jjjjdksÂJ ‚| jjjjdksÖJ ‚| jjd	ksæJ ‚| jjjd
ksøJ ‚| jjjd
k�sJ ‚d S )Nr   Útrioztrio.abcztrio.lowlevelztrio.testingÚ	CancelledÚsend_allzSendStream.send_allztrio.to_threadÚrun_sync)r1   Útrio.testingr2   Ú
__module__r/   ÚabcZStreamZlowlevelZwait_task_rescheduledÚtestingZ	trio_testZ
ParkingLotÚ__init__r3   Ú__name__Ú__qualname__Z
SendStreamÚ	to_threadr4   )r1   r(   r(   r*   Ú test_module_metadata_is_fixed_up@   s     r=   c                  Ã  s.   t ƒ s
J ‚ddœdd„} tj | ¡I d H  d S )Nr   r    c                   S  s   t ƒ r
J ‚d S r'   )r   r(   r(   r(   r*   Únot_main_thread[   s    z,test_is_main_thread.<locals>.not_main_thread)r   r1   r<   r4   )r>   r(   r(   r*   Útest_is_main_threadX   s    
r?   z(ignore:.*@coroutine.*:DeprecationWarningc               	     sÞ  G dd„ dƒ‰ t ƒ ��² ddœdd„} t t¡�}t| ƒ ƒ W d   ƒ n1 sP0    Y  dt|jƒv slJ ‚dd l‰tj	d	k rÜˆj
d
dœ‡fdd„ƒ}t t¡�}t|ƒ ƒ W d   ƒ n1 sÀ0    Y  dt|jƒv sÜJ ‚t t¡�}ttƒ ƒ W d   ƒ n1 �s0    Y  dt|jƒv �s&J ‚t t¡�}ttƒ W d   ƒ n1 �sP0    Y  dt|jƒv �snJ ‚t t¡�}tˆ ƒ ƒ W d   ƒ n1 �sš0    Y  dt|jƒv �s¸J ‚t t¡� }t‡ fdd„ƒ W d   ƒ n1 �sê0    Y  dt|jƒv �sJ ‚t t¡� }ttg d¢gƒ W d   ƒ n1 �s:0    Y  dt|jƒv �sXJ ‚dddœdd„}t t¡�}t|dgƒ W d   ƒ n1 �s–0    Y  d}|t|jƒv �s¸J ‚~W d   ƒ n1 �sÐ0    Y  d S )Nc                   @  s   e Zd ZdZdS )z)test_coroutine_or_error.<locals>.DeferredzJust kiddingN)r:   r6   r;   Ú__doc__r(   r(   r(   r*   ÚDeferredd   s   rA   r   r    c                   Ó  s   d S r'   r(   r(   r(   r(   r*   Úfi   s    z"test_coroutine_or_error.<locals>.fzexpecting an async functionr   r   z2Generator[Coroutine[None, None, None], None, None]c                   3  s   ˆ   d¡E d H  d S )Né   )Úsleepr(   )Úasyncior(   r*   Úgenerator_based_corot   s    z5test_coroutine_or_error.<locals>.generator_based_cororE   Ztwistedc                     s   ˆ ƒ S r'   r(   r(   )rA   r(   r*   Ú<lambda>Œ   ó    z)test_coroutine_or_error.<locals>.<lambda>)rC   r
   r   zappears to be synchronousÚobjectzAsyncGenerator[None, None])Ú_r!   c                 S s
   d V  d S r'   r(   )rJ   r(   r(   r*   Ú	async_gen”   s    z*test_coroutine_or_error.<locals>.async_genz5expected an async function but got an async generator)r   r-   r.   Ú	TypeErrorr   ÚstrÚvaluerE   ÚsysÚversion_infoÚ	coroutiner   Úlen)rB   ÚexcinforF   rK   Úmsgr(   )rA   rE   r*   Útest_coroutine_or_errorb   sD    
(
(*(*00,rU   c                  C  sœ   t dddœdd„ƒ} | | t   u r4| ttf u s:n J ‚| dƒ| t dƒ  krZdks`n J ‚| jdksnJ ‚| jdks|J ‚| jdksŠJ ‚| jtks˜J ‚d S )Nr   )Úargr!   c                 S  s   | S )úLook, a docstring!r(   )rV   r(   r(   r*   Ú	test_func£   s    z(test_generic_function.<locals>.test_funcé*   rW   rX   )r   ÚintrM   r@   r;   r:   r6   )rX   r(   r(   r*   Útest_generic_function¢   s    &&r[   c                  C  sP   t G dd„ dƒƒ} t t¡�  G dd„ d| ƒ}W d  ƒ n1 sB0    Y  dS )zËTest that subclassing a @final-annotated class is not allowed.

    This checks both runtime results, and verifies that type checkers detect
    the error statically through the type-ignore comment.
    c                   @  s   e Zd ZdS )z(test_final_decorator.<locals>.FinalClassN©r:   r6   r;   r(   r(   r(   r*   Ú
FinalClass·   s   r]   c                   @  s   e Zd ZdS )z&test_final_decorator.<locals>.SubClassNr\   r(   r(   r(   r*   ÚSubClass½   s   r^   N)r   r-   r.   rL   )r]   r^   r(   r(   r*   Útest_final_decorator°   s    r_   c                  C  sb   G dd„ dt d�} t t¡� | ddƒ W d  ƒ n1 s<0    Y  t| jddd�| ƒs^J ‚dS )zLThe NoPublicConstructor metaclass prevents calling the constructor directly.c                   @  s   e Zd Zddddœdd„ZdS )z:test_no_public_constructor_metaclass.<locals>.SpecialClassrZ   Úfloatr   )ÚaÚbr!   c                 S  s   |dksJ ‚|dksJ ‚dS )z*Check arguments can be passed to __init__.é   ç333333	@Nr(   )Úselfra   rb   r(   r(   r*   r9   Å   s    zCtest_no_public_constructor_metaclass.<locals>.SpecialClass.__init__N)r:   r6   r;   r9   r(   r(   r(   r*   ÚSpecialClassÄ   s   rf   )Ú	metaclassrc   rd   N)rb   )r   r-   r.   rL   Ú
isinstanceÚ_create)rf   r(   r(   r*   Ú$test_no_public_constructor_metaclassÁ   s    (rj   c                  C  s  t  d¡} dd„ | _d| j_d| j_t| jt| ƒƒ | jjdksDJ ‚| jjdksTJ ‚t  d¡}dd„ |_d|j_d|j_t  ¡ |_d|j_t  ¡ |_	d|j	_
d	|j	_d
d„ |_d|j_
d |j_|j_tdddd„ dd„ dœƒ|_|j|j_tdt|ƒƒ |jjdk�sJ ‚|jj
dk�sJ ‚|jjdk�s0J ‚|jjdk�sBJ ‚|jjdk�sTJ ‚|jj
dk�sfJ ‚|jjdk�sxJ ‚|j	jdk�sŠJ ‚|j	j
dk�sœJ ‚t|j	dƒ�r®J ‚|jjjdk�sÂJ ‚|jjj
dk�sÖJ ‚|jjjdk�sêJ ‚|  ¡  | ¡  | ¡  | ¡  ¡  d S )NZnot_trioc                   S  s   d S r'   r(   r(   r(   r(   r*   rG   Ô   rH   z,test_fixup_module_metadata.<locals>.<lambda>Ú	some_funcztrio._somemodule_implc                   S  s   d S r'   r(   r(   r(   r(   r*   rG   ß   rH   Z_something_elseÚnot_funclikeZ	only_namec                   S  s   d S r'   r(   r(   r(   r(   r*   rG   í   rH   Ú_privateÚ	SomeClassr(   c                 S  s   d S r'   r(   ©re   r(   r(   r*   rG   ö   rH   c                 S  s   d S r'   r(   ro   r(   r(   r*   rG   ÷   rH   )r9   Úmethodztrio.somemoduleÚonly_has_namer;   rp   zSomeClass.method)ÚtypesÚ
ModuleTyperk   r:   r;   r   ÚvarsÚSimpleNamespacerl   rq   r6   rm   Útypern   Ú	recursionÚhasattrrp   )Znon_trio_moduleÚmodr(   r(   r*   Útest_fixup_module_metadataÑ   sZ    






þý	
rz   c                  Ã  s~  t dƒ} tdƒ}tdƒ}|| _|| _tjjdd�}tj	t dd�� }t
td| gƒƒ W d   ƒ n1 sf0    Y  |jj|ks€J ‚|jj|ks�J ‚td| gƒ}td	ƒ}td
ƒ}||_||_ttt dd�dd�� }t
td|gƒƒ W d   ƒ n1 sò0    Y  |jj|k�sJ ‚|jj|k�s J ‚tj	t dd��$}t
td||| gƒƒ W d   ƒ n1 �sZ0    Y  |jj|k�svJ ‚|jj|k�sˆJ ‚tdt dƒt dƒgƒ}	tj	tdd��}t
|	ƒ W d   ƒ n1 �sÌ0    Y  |jj|	u �sèJ ‚|jjd u �súJ ‚tdt dƒt dƒtdƒgƒ}
tj	tdd��}t
|
ƒ W d   ƒ n1 �sD0    Y  |jj|
u �s`J ‚|jjd u �srJ ‚tdt dƒt dƒtdƒgƒ}t 	t¡�}t
|ƒ W d   ƒ n1 �s¸0    Y  |jjdk�sÔJ ‚|jj|u �sæJ ‚|jjd u �søJ ‚tj	tjdd��,}t
td|tjjdd�gƒƒ W d   ƒ n1 �s<0    Y  |j|u �sVJ ‚|jjd u �shJ ‚|jjd u �szJ ‚d S )NZfooÚcauseÚcontextÚdeadline)Úsourcer%   Ú zinner egzinner eg causezinner eg contextz^foo$z
^inner eg$Úbarzy^Attempted to unwrap exceptiongroup with multiple non-cancelled exceptions. This is often caused by a bug in the caller.$zpreserve error msgz^preserve error msg$r
   z^cancelled due to deadline$Úexplicit)Ú
ValueErrorÚSyntaxErrorrL   Ú	__cause__Ú__context__r1   r2   ri   r-   r.   r   r   rN   r	   r   r   r   ÚKeyboardInterruptÚ
SystemExitÚcode)Úexcr{   r|   Z	cancelledrS   Zinner_egZinner_causeZinner_contextZeginfoÚegZeg_kiZsystemexit_kir(   r(   r*   Ú&test_raise_single_exception_from_group  sŒ    ..ÿ$þ(ýþþ(ýþ	(ÿÿ$r‹   )1Ú
__future__r   rO   rr   Útypingr   r   Úcollections.abcr   r   r   r-   r1   r5   r   r	   r   r   Z_core._tests.tutilr   r   Z_utilr   r   r   r   r   r   r   r   r   r8   r   rP   Zexceptiongroupr   r   r   r0   r=   r?   ÚmarkÚfilterwarningsrU   r[   r_   rj   rz   r‹   r(   r(   r(   r*   Ú<module>   s6   ,


?D