a
    QIh1                     @  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 rd dl"m#Z#m$Z$ erd 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 s0    Y  W d    n1 s0    Y  W d    n1 s0    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(   O/var/www/html/venv_bot_3.9/lib/python3.9/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sJ | jjdksJ | jjdksJ | jjjjdksJ | jjjjdksJ | jjd	ksJ | jjjd
ksJ | 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 s0    Y  dt|jv sJ 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 s0    Y  dt|jv sJ tt }t fdd W d    n1 s0    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 s0    Y  d}|t|jv sJ ~W d    n1 s0    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sJ | jtksJ 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 )zTest 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sJ |j	j
dksJ t|j	drJ |jjjdksJ |jjj
dksJ |jjjdksJ |   |  |  |   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                    sh  t d} td}td}|| _|| _tj }tj	t dd }t
td| g W d    n1 sb0    Y  |jj|ks|J |jj|ksJ td| g}td}td}||_||_ttt d	dd
d }t
td|g W d    n1 s0    Y  |jj|ks
J |jj|ksJ tj	t dd$}t
td||| g W d    n1 sV0    Y  |jj|ksrJ |jj|ksJ tdt dt dg}	tj	tdd}t
|	 W d    n1 s0    Y  |jj|	u sJ |jjd u sJ td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 snJ tdt dt dtdg}tj	tdd}t
| W d    n1 s0    Y  |jj|u sJ |jjd u sJ tj	tjdd(}t
td|tj g W d    n1 s&0    Y  |j|u s@J |jjd u sRJ |jjd u sdJ d S )NZfoocausecontextr%    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this exc doesn't get reraisedz^$z^Cancelled$)
ValueErrorSyntaxErrorrL   	__cause____context__r1   r2   ri   r-   r.   r   r   rN   r	   r   r   r   KeyboardInterrupt
SystemExit)excr{   r|   	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