o
    dTi/                     @  sF  d dl mZ d dlZd dlZd dlmZmZ er"d 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 dd
lmZ ej dk rgd dl!m"Z"m#Z# erod dlmZ edZ$d"ddZ%d"ddZ&d"ddZ'ej()dd"ddZ*d"ddZ+d"ddZ,d"ddZ-d"d d!Z.d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is_main_thread!raise_single_exception_from_groupwait_all_tasks_blocked      )BaseExceptionGroupExceptionGroup)r   TreturnNonec               
     s~  t d t d}   |  td W d    n1 sw   Y  W d    n1 s,w   Y  tjtjdd,     W d    n1 sJw   Y  W d    n1 sYw   Y  W d    n1 shw   Y  d	 fdd}tttjd9 t 4 I d H }|	| |	| W d   I d H  n1 I d H sw   Y  W d    d S W d    d S 1 sw   Y  d S )
Nul1ul2okmatchr   r   c                     s8     t  I d H  W d    d S 1 sw   Y  d S Nr    r    r&   Q/home/air/sos-pdf/back/venv/lib/python3.10/site-packages/trio/_tests/test_util.pywait_with_ul15   s   "z,test_ConflictDetector.<locals>.wait_with_ul1r   r   )
r   printpytestraisesr   BusyResourceErrorr	   r   open_nursery
start_soon)r!   r)   nurseryr&   r'   r(   test_ConflictDetector(   s6   

*"r2   c                  C  s  dd l } dd l} | 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 | j	j
jdks3J | jjjjdks=J | jjjjdksGJ | jjdksOJ | jjdksWJ | jjjjdksaJ | jjjjdkskJ | jjd	kssJ | jjjd
ks|J | jjjd
ksJ d S )Nr   trioztrio.abcztrio.lowlevelztrio.testing	Cancelledsend_allzSendStream.send_allztrio.to_threadrun_sync)r3   trio.testingr4   
__module__r/   abcStreamlowlevelwait_task_rescheduledtesting	trio_test
ParkingLot__init__r5   __name____qualname__
SendStream	to_threadr6   )r3   r&   r&   r(    test_module_metadata_is_fixed_up?   s    rE   c                    s,   t  sJ 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_threadZ   s   z,test_is_main_thread.<locals>.not_main_threadr*   )r   r3   rD   r6   )rF   r&   r&   r(   test_is_main_threadW   s   

rG   z(ignore:.*@coroutine.*:DeprecationWarningc               	     s  G dd d t  K ddd} tt}t|   W d    n1 s&w   Y  dt|jv s4J dd ltj	d	k rjj
dfdd}tt}t|  W d    n1 s\w   Y  dt|jv sjJ tt}tt  W d    n1 sw   Y  dt|jv sJ tt}tt W d    n1 sw   Y  dt|jv sJ tt}t   W d    n1 sw   Y  dt|jv sJ tt}t fdd W d    n1 sw   Y  dt|jv sJ tt}ttg dg W d    n	1 sw   Y  dt|jv s J ddd}tt}t|dg W d    n	1 s<w   Y  d}|t|jv sMJ ~W d    d S 1 sZw   Y  d S )Nc                   @  s   e Zd ZdZdS )z)test_coroutine_or_error.<locals>.DeferredzJust kiddingN)rA   r8   rB   __doc__r&   r&   r&   r(   Deferredc   s    rI   r   r   c                     s   d S r%   r&   r&   r&   r&   r(   fh   s   z"test_coroutine_or_error.<locals>.fzexpecting an async functionr   r   2Generator[Coroutine[None, None, None], None, None]c                   3  s      dE d H  d S )N   )sleepr&   )asyncior&   r(   generator_based_coros   s   z5test_coroutine_or_error.<locals>.generator_based_cororN   twistedc                     s     S r%   r&   r&   )rI   r&   r(   <lambda>   s    z)test_coroutine_or_error.<locals>.<lambda>)rL   r
   r   zappears to be synchronous_objectAsyncGenerator[None, None]c                 S s   d V  d S r%   r&   )rR   r&   r&   r(   	async_gen   s   
z*test_coroutine_or_error.<locals>.async_genz5expected an async function but got an async generatorr*   )r   rK   )rR   rS   r   rT   )r   r,   r-   	TypeErrorr   strvaluerN   sysversion_info	coroutiner   len)rJ   excinforO   rU   msgr&   )rI   rN   r(   test_coroutine_or_errora   sV   




$r_   c                  C  sR   t G dd d} tt G dd d| }W d   dS 1 s"w   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                   @     e Zd ZdS )z(test_final_decorator.<locals>.FinalClassNrA   r8   rB   r&   r&   r&   r(   
FinalClass   s    rb   c                   @  r`   )z&test_final_decorator.<locals>.SubClassNra   r&   r&   r&   r(   SubClass   s    rc   N)r   r,   r-   rV   )rb   rc   r&   r&   r(   test_final_decorator   s
   "rd   c                  C  sb   G dd dt d} tt | dd W d   n1 sw   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Zd	S )z:test_no_public_constructor_metaclass.<locals>.SpecialClassaintbfloatr   r   c                 S  s   |dksJ |dksJ dS )z*Check arguments can be passed to __init__.   333333	@Nr&   )selfre   rg   r&   r&   r(   r@      s   zCtest_no_public_constructor_metaclass.<locals>.SpecialClass.__init__N)re   rf   rg   rh   r   r   )rA   r8   rB   r@   r&   r&   r&   r(   SpecialClass   s    rl   )	metaclassri   rj   N)rg   )r   r,   r-   rV   
isinstance_create)rl   r&   r&   r(   $test_no_public_constructor_metaclass   s
   rp   c                  C  s  t d} dd | _d| j_d| j_t| jt|  | jjdks"J | jjdks*J 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sJ |jj
dksJ |jjdksJ |jjdksJ |jjdksJ |jj
dksJ |jjdksJ |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 )Nnot_trioc                   S     d S r%   r&   r&   r&   r&   r(   rQ          z,test_fixup_module_metadata.<locals>.<lambda>	some_funcztrio._somemodule_implc                   S  rr   r%   r&   r&   r&   r&   r(   rQ      rs   _something_elsenot_funclike	only_namec                   S  rr   r%   r&   r&   r&   r&   r(   rQ      rs   _private	SomeClassr&   c                 S  rr   r%   r&   rk   r&   r&   r(   rQ      rs   c                 S  rr   r%   r&   rz   r&   r&   r(   rQ      rs   )r@   methodztrio.somemoduleonly_has_namerB   r{   zSomeClass.method)types
ModuleTypert   rA   rB   r   varsSimpleNamespacerv   r|   r8   rx   typery   	recursionhasattrr{   )non_trio_modulemodr&   r&   r(   test_fixup_module_metadata   sZ   







	r   c                    sp  t d} td}td}|| _|| _tjjdd}tj	t dd}t
td| g W d    n1 s4w   Y  |jj|ksAJ |jj|ksIJ td| g}td	}td
}||_||_ttt dddd}t
td|g W d    n1 szw   Y  |jj|ksJ |jj|ksJ tj	t dd}t
td||| g W d    n1 sw   Y  |jj|ksJ |jj|ksJ tdt dt dg}	tj	tdd}t
|	 W d    n1 sw   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w   Y  |jj|
u s)J |jjd u s2J tdt dt dtdg}t	t}t
| W d    n	1 sUw   Y  |jjdkscJ |jj|u slJ |jjd u suJ tj	tjdd}t
td|tjjddg W d    n	1 sw   Y  |j|u sJ |jjd u sJ |jjd u sJ d S )N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SyntaxErrorrV   	__cause____context__r3   r4   ro   r,   r-   r   r   rX   r	   r   r   r   KeyboardInterrupt
SystemExitcode)excr   r   	cancelledr]   inner_eginner_causeinner_contexteginfoegeg_kisystemexit_kir&   r&   r(   &test_raise_single_exception_from_group  s   

	
r   r*   )/
__future__r   rY   r}   typingr   r   collections.abcr   r   r   r,   r3   r7   r   r	   r   r   _core._tests.tutilr   r   _utilr   r   r   r   r   r   r   r   r=   r   rZ   exceptiongroupr   r   r   r2   rE   rG   markfilterwarningsr_   rd   rp   r   r   r&   r&   r&   r(   <module>   s6    (







?

D