o
    ACe%                     @   s   d dl Z d dlZd dlZd dlmZmZ d dlZd dl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dZdd
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 )    N)AnyTypeVar   )_core)!create_asyncio_future_in_new_loop'ignore_coroutine_never_awaited_warnings)ConflictDetectorNoPublicConstructorcoroutine_or_errorfinalfixup_module_metadatageneric_functionis_main_threadsignal_raisewait_all_tasks_blockedTreturnc               
      sn   g  dt dtdd f fdd} ttj| }zttj W ttj| nttj| w  tjgks5J d S )Nsignum_r   c                    s     |  d S N)append)r   r   record 9usr/lib/python3.10/site-packages/trio/_tests/test_util.pyhandler!      z"test_signal_raise.<locals>.handler)intobjectsignalSIGFPEr   )r   oldr   r   r   test_signal_raise   s    r#   c               
      s  t d t d}   |  td W d    n1 sw   Y  W d    n1 s,w   Y  ttj,}    W d    n1 sHw   Y  W d    n1 sWw   Y  W d    n1 sfw   Y  dt|jv stJ d fdd}ttj0}t 4 I d H }|	| |	| W d   I d H  n1 I d H sw   Y  W d    n1 sw   Y  dt|jv sJ d S )Nul1ul2okr   c                      s8     t  I d H  W d    d S 1 sw   Y  d S r   r   r   r$   r   r   wait_with_ul1:   s   "z,test_ConflictDetector.<locals>.wait_with_ul1r   N)
r   printpytestraisesr   ZBusyResourceErrorstrvalueopen_nurseryZ
start_soon)r%   excinfor(   Znurseryr   r'   r   test_ConflictDetector,   s8   

(r1   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)r2   Ztrio.testingr3   
__module__r/   abcZStreamZlowlevelZwait_task_rescheduledtestingZ	trio_testZ
ParkingLot__init__r4   __name____qualname__Z
SendStream	to_threadr5   )r2   r   r   r    test_module_metadata_is_fixed_upE   s    r=   c                     s,   t  sJ ddd} tj| I d H  d S )Nr   c                   S   s   t  rJ d S r   )r   r   r   r   r   not_main_thread`   r   z,test_is_main_thread.<locals>.not_main_threadr)   )r   r2   r<   r5   )r>   r   r   r   test_is_main_thread]   s   

r?   z(ignore:.*@coroutine.*:DeprecationWarningc               	      s  G dd d t  Q 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 rlj
dtffd	d
}tt}t|  W d    n1 s^w   Y  dt|jv slJ tt}tt  W d    n1 sw   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tdtfdd}tt}t|dg W d    n	1 sBw   Y  d}|t|jv sSJ ~W d    d S 1 s`w   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   Deferredi   s    rA   r   c                      s   d S r   r   r   r   r   r   fn   s   z"test_coroutine_or_error.<locals>.fzexpecting an async functionr   )      c                   3   s      dE d H  d S )N   )sleepr   )asyncior   r   generator_based_coroy   s   z5test_coroutine_or_error.<locals>.generator_based_cororG   Ztwistedc                      s     S r   r   r   )rA   r   r   <lambda>   s    z)test_coroutine_or_error.<locals>.<lambda>)rE   r   rC   zappears to be synchronousr   c                 S  s   d V  d S r   r   )r   r   r   r   	async_gen   s   
z*test_coroutine_or_error.<locals>.async_genz5expected an async function but got an async generatorr)   )r   r+   r,   	TypeErrorr
   r-   r.   rG   sysversion_info	coroutiner   r   lenr   )rB   r0   rH   rJ   msgr   )rA   rG   r   test_coroutine_or_errorg   sV   



$rQ   c                  C   s   t dtdtfdd} | | t   u r| ttf u sJ  J | d| t d  kr0dks3J  J | jdks:J | jdksAJ | jdksHJ | jtksOJ d S )Nargr   c                 S   s   | S )Look, a docstring!r   )rR   r   r   r   	test_func   s   z(test_generic_function.<locals>.test_func*   rS   rT   )r   r   r   r-   r@   r;   r:   r6   )rT   r   r   r   test_generic_function   s   ((rV   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r:   r6   r;   r   r   r   r   
FinalClass   s    rY   c                   @   rW   )z&test_final_decorator.<locals>.SubClassNrX   r   r   r   r   SubClass   s    rZ   N)r   r+   r,   rK   )rY   rZ   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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ededdfddZdS )z:test_no_public_constructor_metaclass.<locals>.SpecialClassabr   Nc                 S   s   |dksJ |dksJ dS )z*Check arguments can be passed to __init__.   Q	@Nr   )selfr\   r]   r   r   r   r9      s   zCtest_no_public_constructor_metaclass.<locals>.SpecialClass.__init__)r:   r6   r;   r   floatr9   r   r   r   r   SpecialClass   s    rb   )	metaclassr^   r_   N)r]   )r	   r+   r,   rK   
isinstance_create)rb   r   r   r   $test_no_public_constructor_metaclass   s
   rf   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 )NZnot_trioc                   S      d S r   r   r   r   r   r   rI          z,test_fixup_module_metadata.<locals>.<lambda>	some_funcztrio._somemodule_implc                   S   rg   r   r   r   r   r   r   rI      rh   Z_something_elsenot_funclikeZ	only_namec                   S   rg   r   r   r   r   r   r   rI      rh   _private	SomeClassr   c                 S   rg   r   r   r`   r   r   r   rI      rh   c                 S   rg   r   r   rm   r   r   r   rI      rh   )r9   methodztrio.somemoduleonly_has_namer;   rn   zSomeClass.method)types
ModuleTyperi   r:   r;   r   varsSimpleNamespacerj   ro   r6   rk   typerl   Z	recursionhasattrrn   )Znon_trio_modulemodr   r   r   test_fixup_module_metadata   sZ   







	rw   r)   )$r    rL   rp   typingr   r   r+   r2    r   Z_core._tests.tutilr   r   Z_utilr   r	   r
   r   r   r   r   r   r8   r   r   r#   r1   r=   r?   ZmarkfilterwarningsrQ   rV   r[   rf   rw   r   r   r   r   <module>   s*    (







<

