o
    ~îj!„  ã                   @   sä  d dl Z d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	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mZmZ d dlmZ zd dlZW n eye   dZY nw d dlZejrud d	lmZm Z  G d
d„ deƒZ!G dd„ deƒZ"G dd„ deƒZ#G dd„ deƒZ$G dd„ deƒZ%G dd„ deƒZ&G dd„ deƒZ'G dd„ deƒZ(G dd„ deƒZ)G dd„ deƒZ*G dd„ deƒZ+edurÖe ,d ¡Z-e	 .edu d!¡G d"d#„ d#eƒƒZ/e0d$krðe	 1¡  dS dS )%é    N)Úfutures)ÚFuture)Úapp_log)ÚAsyncHTTPTestCaseÚAsyncTestCaseÚ	ExpectLogÚgen_test)ÚskipNotCPython)ÚApplicationÚRequestHandlerÚ	HTTPError)Úgen)ÚListÚOptionalc                   @   s,  e Zd Zejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd„ ƒZd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd „ ƒZed!d"„ ƒZed#d$„ ƒZed%d&„ ƒZed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Z d7d8„ Z!d9d:„ Z"d;S )<ÚGenBasicTestc                 c   s"   � t |ƒD ]}tjV  qt |¡‚)z0Returns arg after a number of IOLoop iterations.)Úranger   ÚmomentÚReturn)ÚselfÚ
iterationsÚargÚi© r   ú_/raid/bulk_storage/M2HATS/real-image-venv/lib/python3.10/site-packages/tornado/test/gen_test.pyÚdelay   s   €

zGenBasicTest.delayc                 c   s   � t jV  |S ©N©r   r   ©r   Úresultr   r   r   Úasync_future&   ó   €zGenBasicTest.async_futurec                 c   s   � t jV  |‚r   r   )r   Úer   r   r   Úasync_exception+   r    zGenBasicTest.async_exceptionc                 c   s   � t jV  t  |d ¡‚©Né   ©r   r   r   ©r   Úxr   r   r   Úadd_one_async0   s   €zGenBasicTest.add_one_asyncc                 C   ó   t jdd„ ƒ}| j |¡ d S )Nc                   S   ó   d S r   r   r   r   r   r   Úf6   ó   z%GenBasicTest.test_no_yield.<locals>.f©r   Ú	coroutineÚio_loopÚrun_sync©r   r+   r   r   r   Útest_no_yield5   ó   
zGenBasicTest.test_no_yieldc                 C   ó$   t jdd„ ƒ}|  t| jj|¡ d S )Nc                   S   ó   dd  d S ©Nr$   r   r   r   r   r   r   r+   =   ó   z-GenBasicTest.test_exception_phase1.<locals>.f©r   r.   ÚassertRaisesÚZeroDivisionErrorr/   r0   r1   r   r   r   Útest_exception_phase1<   s   
z"GenBasicTest.test_exception_phase1c                 C   r4   )Nc                   s   ó   � t jV  dd  d S r6   r   r   r   r   r   r+   D   ó   €z-GenBasicTest.test_exception_phase2.<locals>.fr8   r1   r   r   r   Útest_exception_phase2C   s   
z"GenBasicTest.test_exception_phase2c                 C   ó&   t jdd„ ƒ}|  t j| jj|¡ d S )Nc                   s   ó   � dV  d S ©Né*   r   r   r   r   r   r+   L   ó   €
z(GenBasicTest.test_bogus_yield.<locals>.f©r   r.   r9   ÚBadYieldErrorr/   r0   r1   r   r   r   Útest_bogus_yieldK   ó   
zGenBasicTest.test_bogus_yieldc                 C   r?   )Nc                   s   r@   ©N©r$   é   r   r   r   r   r   r+   S   rC   z.GenBasicTest.test_bogus_yield_tuple.<locals>.frD   r1   r   r   r   Útest_bogus_yield_tupleR   rG   z#GenBasicTest.test_bogus_yield_tuplec                 C   s*   t jdd„ ƒ}| j |¡ | j |¡ d S )Nc                   s   ó   � t jV  d S r   r   r   r   r   r   r+   Z   ó   €z"GenBasicTest.test_reuse.<locals>.fr-   r1   r   r   r   Ú
test_reuseY   s   
zGenBasicTest.test_reusec                 C   r)   )Nc                   s   s   � d V  d S r   r   r   r   r   r   r+   b   rC   z!GenBasicTest.test_none.<locals>.fr-   r1   r   r   r   Ú	test_nonea   r3   zGenBasicTest.test_nonec                    ó"   t j‡ fdd„ƒ}ˆ j |¡ d S )Nc                  3   s,   � ˆ   d¡ˆ   d¡gV } ˆ  | ddg¡ d S )Nr$   rJ   é   )r(   ÚassertEqual©Úresults©r   r   r   r+   i   ó   €z"GenBasicTest.test_multi.<locals>.fr-   r1   r   rU   r   Ú
test_multih   ó   zGenBasicTest.test_multic                    rP   )Nc                  3   s4   � t ˆ  d¡ˆ  d¡d�V } ˆ  | t ddd�¡ d S )Nr$   rJ   ©ÚfooÚbarrQ   )Údictr(   rR   rS   rU   r   r   r+   q   ó   €z'GenBasicTest.test_multi_dict.<locals>.fr-   r1   r   rU   r   Útest_multi_dictp   rX   zGenBasicTest.test_multi_dictc                    rP   )Nc                  3   s6   � t  ˆ  dd¡ˆ  dd¡g¡V } ˆ  | ddg¡ d S )NrQ   Úv1r$   Úv2)r   Úmulti_futurer   rR   ©Ú	responsesrU   r   r   r+   y   s
   €ÿz*GenBasicTest.test_multi_delayed.<locals>.fr-   r1   r   rU   r   Útest_multi_delayedx   ó   zGenBasicTest.test_multi_delayedc                    rP   )Nc                  3   s>   � t  tˆ  dd¡ˆ  dd¡d�¡V } ˆ  | tddd�¡ d S )NrQ   r_   r$   r`   rY   )r   ra   r\   r   rR   rb   rU   r   r   r+   „   s
   €ÿz/GenBasicTest.test_multi_dict_delayed.<locals>.fr-   r1   r   rU   r   Útest_multi_dict_delayedƒ   re   z$GenBasicTest.test_multi_dict_delayedc                 c   s:   � t   ¡ }dd„ tdƒD ƒV  t   ¡ }|  || d¡ d S )Nc                 S   s   g | ]}t j‘qS r   r   )Ú.0r   r   r   r   Ú
<listcomp>”   s    z7GenBasicTest.test_multi_performance.<locals>.<listcomp>iÐ  g      ð?)Útimer   Ú
assertLess)r   ÚstartÚendr   r   r   Útest_multi_performanceŽ   s
   €z#GenBasicTest.test_multi_performancec                 c   s2   � g V }|   t|tƒ¡ i V }|   t|tƒ¡ d S r   )Ú
assertTrueÚ
isinstanceÚlistr\   )r   r'   Úyr   r   r   Útest_multi_empty˜   s
   €zGenBasicTest.test_multi_emptyc                 c   s   � |   d¡V }|  |d¡ d S r#   ©r   rR   r   r   r   r   Útest_future    s   €zGenBasicTest.test_futurec                 c   s,   � |   d¡|   d¡gV }|  |ddg¡ d S )Nr$   rJ   rs   ©r   rT   r   r   r   Útest_multi_future¥   rV   zGenBasicTest.test_multi_futurec                 c   s:   � |   d¡}|   d¡||   d¡|gV }|  |g d¢¡ d S )NrJ   r$   rQ   )r$   rJ   rQ   rJ   rs   )r   r+   rT   r   r   r   Útest_multi_future_duplicateª   s   €
z(GenBasicTest.test_multi_future_duplicatec                 c   s4   � t |  d¡|  d¡d�V }|  |t ddd�¡ d S )Nr$   rJ   rY   )r\   r   rR   ru   r   r   r   Útest_multi_dict_future²   r]   z#GenBasicTest.test_multi_dict_futurec              	   c   s.  � t tdƒ�/ |  t¡�}t |  tdƒ¡|  tdƒ¡g¡V  W d   ƒ n1 s)w   Y  W d   ƒ n1 s8w   Y  |  t|j	ƒd¡ |  t¡� t |  tdƒ¡|  
d¡g¡V  W d   ƒ n1 sfw   Y  |  t¡� tj|  tdƒ¡|  tdƒ¡gtd�V  W d   ƒ d S 1 s�w   Y  d S ©Nz!Multiple exceptions in yield listzerror 1zerror 2rJ   )Úquiet_exceptions)r   r   r9   ÚRuntimeErrorr   ÚMultir"   rR   ÚstrÚ	exceptionr   ©r   Úcmr   r   r   Útest_multi_exceptions·   s2   €þÿÿ€ÿÿÿþ
û"ÿz"GenBasicTest.test_multi_exceptionsc              	   c   s"  � t tdƒ�, |  t¡�}|  tdƒ¡|  tdƒ¡gV  W d   ƒ n1 s&w   Y  W d   ƒ n1 s5w   Y  |  t|jƒd¡ |  t¡� |  tdƒ¡|  d¡gV  W d   ƒ n1 s`w   Y  |  t¡� t	j
|  tdƒ¡|  tdƒ¡gtd�V  W d   ƒ d S 1 sŠw   Y  d S ry   )r   r   r9   r{   r"   rR   r}   r~   r   r   ra   r   r   r   r   Útest_multi_future_exceptionsÓ   s*   €þÿ€ÿÿþ
û"ÿz)GenBasicTest.test_multi_future_exceptionsc                 C   r)   )Nc                   S   s   t  ¡ ‚r   ©r   r   r   r   r   r   r+   ì   ó   z.GenBasicTest.test_sync_raise_return.<locals>.fr-   r1   r   r   r   Útest_sync_raise_returnë   r3   z#GenBasicTest.test_sync_raise_returnc                 C   r)   )Nc                   s   s   � t jV  t  ¡ ‚r   r%   r   r   r   r   r+   ó   ó   €z/GenBasicTest.test_async_raise_return.<locals>.fr-   r1   r   r   r   Útest_async_raise_returnò   s   
z$GenBasicTest.test_async_raise_returnc                 C   ó&   t jdd„ ƒ}|  d| j |¡¡ d S )Nc                   S   ó
   t  d¡‚rA   rƒ   r   r   r   r   r+   û   ó   
z4GenBasicTest.test_sync_raise_return_value.<locals>.frB   ©r   r.   rR   r/   r0   r1   r   r   r   Útest_sync_raise_return_valueú   rG   z)GenBasicTest.test_sync_raise_return_valuec                 C   rˆ   )Nc                   S   r‰   rH   rƒ   r   r   r   r   r+     rŠ   z:GenBasicTest.test_sync_raise_return_value_tuple.<locals>.frI   r‹   r1   r   r   r   Ú"test_sync_raise_return_value_tuple  rG   z/GenBasicTest.test_sync_raise_return_value_tuplec                 C   rˆ   )Nc                   s   ó   � t jV  t  d¡‚rA   r%   r   r   r   r   r+   	  ó   €
z5GenBasicTest.test_async_raise_return_value.<locals>.frB   r‹   r1   r   r   r   Útest_async_raise_return_value  ó   
z*GenBasicTest.test_async_raise_return_valuec                 C   rˆ   )Nc                   s   rŽ   rH   r%   r   r   r   r   r+     r�   z;GenBasicTest.test_async_raise_return_value_tuple.<locals>.frI   r‹   r1   r   r   r   Ú#test_async_raise_return_value_tuple  r‘   z0GenBasicTest.test_async_raise_return_value_tupleN)#Ú__name__Ú
__module__Ú__qualname__r   r.   r   r   r"   r(   r2   r;   r>   rF   rK   rN   rO   rW   r^   rd   rf   r   rm   rr   rt   rv   rw   rx   r�   r‚   r…   r‡   rŒ   r�   r�   r’   r   r   r   r   r      sT    




	






r   c                       s0  e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd „ ƒZed!d"„ ƒZed#d$„ ƒZed%d&„ ƒZed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZd/d0„ Zed1d2„ ƒZ‡  ZS )3ÚGenCoroutineTestc                    s   d| _ tƒ  ¡  d S )NF)ÚfinishedÚsuperÚsetUprU   ©Ú	__class__r   r   r™     s   zGenCoroutineTest.setUpc                    s   t ƒ  ¡  | js
J ‚d S r   )r˜   ÚtearDownr—   rU   rš   r   r   rœ   !  s   
zGenCoroutineTest.tearDownc                 C   sJ   d| _ dd„ }t |¡}|  |j|j¡ |  |j|j¡ |  |j|¡ d S )NTc                   s   rL   r   r   r   r   r   r   r+   (  ó   €z+GenCoroutineTest.test_attributes.<locals>.f)r—   r   r.   rR   r“   r”   ÚassertIsÚ__wrapped__©r   r+   Úcoror   r   r   Útest_attributes%  s   
z GenCoroutineTest.test_attributesc                 C   sN   d| _ dd„ }t |¡}|  t |¡¡ |  t |¡¡ |  t |ƒ ¡¡ d S )NTc                   s   rL   r   r   r   r   r   r   r+   3  r�   z6GenCoroutineTest.test_is_coroutine_function.<locals>.f)r—   r   r.   ÚassertFalseÚis_coroutine_functionrn   r    r   r   r   Útest_is_coroutine_function0  s   
z+GenCoroutineTest.test_is_coroutine_functionc                 c   ó.   � t jdd„ ƒ}|ƒ V }|  |d¡ d| _d S )Nc                   S   r‰   rA   rƒ   r   r   r   r   r+   =  rŠ   z0GenCoroutineTest.test_sync_gen_return.<locals>.frB   T©r   r.   rR   r—   ©r   r+   r   r   r   r   Útest_sync_gen_return;  ó   €

z%GenCoroutineTest.test_sync_gen_returnc                 c   r¦   )Nc                   s   rŽ   rA   r%   r   r   r   r   r+   G  r�   z1GenCoroutineTest.test_async_gen_return.<locals>.frB   Tr§   r¨   r   r   r   Útest_async_gen_returnE  ó   €

z&GenCoroutineTest.test_async_gen_returnc                 c   r¦   )Nc                   S   s   dS rA   r   r   r   r   r   r+   R  r,   z,GenCoroutineTest.test_sync_return.<locals>.frB   Tr§   r¨   r   r   r   Útest_sync_returnP  rª   z!GenCoroutineTest.test_sync_returnc                 c   r¦   )Nc                   s   s   � t jV  dS rA   r   r   r   r   r   r+   \  r    z-GenCoroutineTest.test_async_return.<locals>.frB   Tr§   r¨   r   r   r   Útest_async_returnZ  r¬   z"GenCoroutineTest.test_async_returnc                 #   s2   � t j‡ fdd„ƒ}|ƒ V }ˆ  |d¡ dˆ _d S )Nc                   3   s   � 	 dS )NTrB   )r   ÚTaskr/   Úadd_callbackr   rU   r   r   r+   j  s   €z3GenCoroutineTest.test_async_early_return.<locals>.frB   Tr§   r¨   r   rU   r   Útest_async_early_returne  s   €
z(GenCoroutineTest.test_async_early_returnc                 #   s:   � t jdd„ ƒ‰ ‡ fdd„}|ƒ V }|  |d¡ d| _d S )Nc                   s   rŽ   rA   r%   r   r   r   r   Úf1v  r�   z-GenCoroutineTest.test_async_await.<locals>.f1c                  “   s   �ˆ ƒ I d H } | S r   r   ©r   ©r²   r   r   Úf2~  ó   €z-GenCoroutineTest.test_async_await.<locals>.f2rB   Tr§   ©r   rµ   r   r   r´   r   Útest_async_awaitt  s   €

z!GenCoroutineTest.test_async_awaitc                 c   s(   � dd„ }|ƒ V }|   |d¡ d| _d S )Nc                  Ó   s   �dd l } |  d¡I d H  dS )Nr   rB   )ÚasyncioÚsleep)r¹   r   r   r   r+   Š  s   €z3GenCoroutineTest.test_asyncio_sleep_zero.<locals>.frB   T)rR   r—   r¨   r   r   r   Útest_asyncio_sleep_zero†  s
   €
z(GenCoroutineTest.test_asyncio_sleep_zeroc                 #   sR   � t jdd„ ƒ‰ ‡ fdd„}t jdd„ ƒ}|ƒ |ƒ gV }|  |ddg¡ d	| _d S )
Nc                   s   rL   r   r   r   r   r   r   r²   –  rM   zGGenCoroutineTest.test_async_await_mixed_multi_native_future.<locals>.f1c                   “   s   �ˆ ƒ I d H  dS rA   r   r   r´   r   r   rµ   š  r¶   zGGenCoroutineTest.test_async_await_mixed_multi_native_future.<locals>.f2c                   s   rŽ   )Né+   r%   r   r   r   r   Úf3ž  r�   zGGenCoroutineTest.test_async_await_mixed_multi_native_future.<locals>.f3rB   r¼   Tr§   )r   rµ   r½   rT   r   r´   r   Ú*test_async_await_mixed_multi_native_future”  s   €


z;GenCoroutineTest.test_async_await_mixed_multi_native_futurec                 c   s8   � dd„ }t  tjdd�|ƒ ¡V }|  |d¡ d| _d S )Nc                   Ó   s   �dS rA   r   r   r   r   r   r²   ©  s   €z4GenCoroutineTest.test_async_with_timeout.<locals>.f1r$   )ÚhoursrB   T)r   Úwith_timeoutÚdatetimeÚ	timedeltarR   r—   )r   r²   r   r   r   r   Útest_async_with_timeout§  s
   €
z(GenCoroutineTest.test_async_with_timeoutc                 c   ó,   � t jdd„ ƒ}|ƒ V }|  |¡ d| _d S )Nc                   S   r*   r   r   r   r   r   r   r+   ²  r,   z5GenCoroutineTest.test_sync_return_no_value.<locals>.fT©r   r.   ÚassertIsNoner—   r¨   r   r   r   Útest_sync_return_no_value°  s   €


z*GenCoroutineTest.test_sync_return_no_valuec                 c   rÄ   )Nc                   s   rL   r   r   r   r   r   r   r+   ¼  r    z6GenCoroutineTest.test_async_return_no_value.<locals>.fTrÅ   r¨   r   r   r   Útest_async_return_no_valueº  s   €


z+GenCoroutineTest.test_async_return_no_valuec                 c   óP   � t jdd„ ƒ}|ƒ }|  t¡� |V  W d   ƒ n1 sw   Y  d| _d S )Nc                   S   r5   r6   r   r   r   r   r   r+   Ç  r7   z+GenCoroutineTest.test_sync_raise.<locals>.fT©r   r.   r9   r:   r—   ©r   r+   Úfuturer   r   r   Útest_sync_raiseÅ  s   €
ÿ
z GenCoroutineTest.test_sync_raisec                 c   rÉ   )Nc                   s   r<   r6   r   r   r   r   r   r+   Õ  r=   z,GenCoroutineTest.test_async_raise.<locals>.fTrÊ   rË   r   r   r   Útest_async_raiseÓ  s   €
ÿ
z!GenCoroutineTest.test_async_raisec                 #   sb   � t jdd„ ƒ‰ t j‡ fdd„ƒ}|ƒ }|  t¡� |V  W d   ƒ n1 s'w   Y  d| _d S )Nc                   S   r5   r6   r   r   r   r   r   r²   ã  r7   z>GenCoroutineTest.test_replace_yieldpoint_exception.<locals>.f1c                   3   s&   � zˆ ƒ V  W d S  t y   tƒ ‚w r   )r:   ÚKeyErrorr   r´   r   r   rµ   ç  ó   €ÿz>GenCoroutineTest.test_replace_yieldpoint_exception.<locals>.f2T)r   r.   r9   rÏ   r—   )r   rµ   rÌ   r   r´   r   Ú!test_replace_yieldpoint_exceptionß  s   €
ÿ
z2GenCoroutineTest.test_replace_yieldpoint_exceptionc                 #   s@   � t jdd„ ƒ‰ t j‡ fdd„ƒ}|ƒ V }|  |d¡ d| _d S )Nc                   S   r5   r6   r   r   r   r   r   r²   ÷  r7   z>GenCoroutineTest.test_swallow_yieldpoint_exception.<locals>.f1c                   3   s*   � zˆ ƒ V  W d S  t y   t d¡‚w rA   )r:   r   r   r   r´   r   r   rµ   û  s   €
ÿz>GenCoroutineTest.test_swallow_yieldpoint_exception.<locals>.f2rB   Tr§   r·   r   r´   r   Ú!test_swallow_yieldpoint_exceptionó  s   €

z2GenCoroutineTest.test_swallow_yieldpoint_exceptionc                 #   s¸   � g ‰ t j‡ fdd„ƒ}tƒ }| d ¡ |d|ƒ|d|ƒgV  |  d ˆ ¡d¡ g ‰ |dt jƒ|dt jƒgV  |  d ˆ ¡d¡ d| _g ‰ |dt jƒ|d|ƒgV  |  d ˆ ¡d	¡ d S )
Nc                 3   s$   � t dƒD ]
}ˆ  | ¡ |V  qd S )Né   )r   Úappend)ÚnameÚ	yieldabler   ©Úcallsr   r   r+   
  s
   €
þz'GenCoroutineTest.test_moment.<locals>.fÚaÚbÚ Ú
aaaaabbbbbÚ
abababababTÚ
abbbbbaaaa)r   r.   r   Ú
set_resultrR   Újoinr   r—   )r   r+   Ú	immediater   r×   r   Útest_moment  s   €
zGenCoroutineTest.test_momentc                 c   s   � t  d¡V  d| _d S )Nç{®Gáz„?T)r   rº   r—   rU   r   r   r   Ú
test_sleep!  s   €
zGenCoroutineTest.test_sleepc              
   #   sÎ   � G dd„ dt ƒ‰ tj‡ fdd„ƒ}z|dƒV  W n  ˆ y9 } z|  t|ƒd¡ |  |j¡ W Y d }~nd }~ww z|dƒV  W n  ˆ ya } z|  t|ƒd¡ |  |j¡ W Y d }~nd }~ww d	| _d S )
Nc                   @   ó   e Zd ZdS )zIGenCoroutineTest.test_py3_leak_exception_context.<locals>.LeakedExceptionN©r“   r”   r•   r   r   r   r   ÚLeakedException(  ó    rç   c                    s   ˆ | ƒ‚r   r   )Ú	iteration©rç   r   r   Úinner+  r„   z?GenCoroutineTest.test_py3_leak_exception_context.<locals>.innerr$   Ú1rJ   Ú2T)Ú	Exceptionr   r.   rR   r}   rÆ   Ú__context__r—   )r   rë   r!   r   rê   r   Útest_py3_leak_exception_context&  s&   €€þ€þ
z0GenCoroutineTest.test_py3_leak_exception_contextc                    sL   t j‡fdd„ƒ‰ t j‡ fdd„ƒ}ˆjj|dd� ˆ ˆ ¡ ¡ dˆ_d S )Nc                  3   s@   � G dd„ dƒ} | ƒ }t  |¡ˆ _dd„ }t |¡ƒ V  tdƒ‚)Nc                   @   rå   )zGGenCoroutineTest.test_coroutine_refcounting.<locals>.inner.<locals>.FooNræ   r   r   r   r   ÚFooC  rè   rñ   c                   S   r*   r   r   r   r   r   r   ÚdummyI  ó   zIGenCoroutineTest.test_coroutine_refcounting.<locals>.inner.<locals>.dummyz
Some error)ÚweakrefÚrefÚ	local_refr   r.   Ú
ValueError)rñ   Ú	local_varrò   rU   r   r   rë   A  s   €z:GenCoroutineTest.test_coroutine_refcounting.<locals>.innerc                   3   s&   � zˆ ƒ V  W d S  t y   Y d S w r   )r÷   r   )rë   r   r   Úinner2O  rÐ   z;GenCoroutineTest.test_coroutine_refcounting.<locals>.inner2rQ   )ÚtimeoutT)r   r.   r/   r0   rÆ   rö   r—   )r   rù   r   )rë   r   r   Útest_coroutine_refcounting=  s   
z+GenCoroutineTest.test_coroutine_refcountingc                 C   sx   d| _ t ¡ }|  |j| ¡ ¡ | d¡ dd„ }t |¡ƒ }|  |tj	¡ dt
|jjd f }t|ƒ}|  ||¡ d S )NTc                   s   rL   r   r   r   r   r   r   r+   b  r�   z:GenCoroutineTest.test_asyncio_future_debug_info.<locals>.fzcreated at %s:%drQ   )r—   r¹   Úget_event_loopÚ
addCleanupÚ	set_debugÚ	get_debugr   r.   ÚassertIsInstancer   Ú__file__Ú__code__Úco_firstlinenoÚreprÚassertIn)r   Úasyncio_loopr+   r¡   ÚexpectedÚactualr   r   r   Útest_asyncio_future_debug_info[  s   
z/GenCoroutineTest.test_asyncio_future_debug_infoc                 c   s<   � t jdd„ ƒ}t |ƒ |ƒ ¡V }|  |ddg¡ d| _d S )Nc                   s   rŽ   r#   r%   r   r   r   r   r+   q  r�   z/GenCoroutineTest.test_asyncio_gather.<locals>.fr$   T)r   r.   r¹   ÚgatherrR   r—   )r   r+   Úretr   r   r   Útest_asyncio_gatherm  s   €

z$GenCoroutineTest.test_asyncio_gather)r“   r”   r•   r™   rœ   r¢   r¥   r   r©   r«   r­   r®   r±   r¸   r»   r¾   rÃ   rÇ   rÈ   rÍ   rÎ   rÑ   rÒ   râ   rä   rð   r	   rû   r	  r  Ú__classcell__r   r   rš   r   r–     s\    
	


	







	









r–   c                   @   ó   e Zd Zejdd„ ƒZdS )ÚGenCoroutineSequenceHandlerc                 c   s<   � t jV  |  d¡ t jV  |  d¡ t jV  |  d¡ d S ©Nrì   rí   Ú3)r   r   ÚwriteÚfinishrU   r   r   r   Úget|  s   €

zGenCoroutineSequenceHandler.getN©r“   r”   r•   r   r.   r  r   r   r   r   r  {  ó    r  c                   @   r  )Ú%GenCoroutineUnfinishedSequenceHandlerc                 c   s<   � t jV  |  d¡ t jV  |  d¡ t jV  |  d¡ d S r  )r   r   r  rU   r   r   r   r  ‡  s   €

z)GenCoroutineUnfinishedSequenceHandler.getNr  r   r   r   r   r  †  r  r  c                   @   s(   e Zd Zejdd„ ƒZejdd„ ƒZdS )ÚUndecoratedCoroutinesHandlerc                 c   s    � g | _ tjV  | j  d¡ d S )Nrì   )Úchunksr   r   rÔ   rU   r   r   r   Úprepare”  s   €z$UndecoratedCoroutinesHandler.preparec                 c   s@   � | j  d¡ tjV  | j  d¡ tjV  |  d | j ¡¡ d S )Nrí   r  rÛ   )r  rÔ   r   r   r  rà   rU   r   r   r   r  š  s   €z UndecoratedCoroutinesHandler.getN©r“   r”   r•   r   r.   r  r  r   r   r   r   r  “  s
    
r  c                   @   s"   e Zd Zejdd„ ƒZdd„ ZdS )ÚAsyncPrepareErrorHandlerc                 c   s   � t jV  tdƒ‚)Né“  )r   r   r   rU   r   r   r   r  ¤  r†   z AsyncPrepareErrorHandler.preparec                 C   s   |   d¡ d S )NÚok)r  rU   r   r   r   r  ©  s   zAsyncPrepareErrorHandler.getNr  r   r   r   r   r  £  s    
r  c                   @   s   e Zd Zdd„ ZdS )ÚNativeCoroutineHandlerc                 Ã   s    �t  d¡I d H  |  d¡ d S )Nr   r  )r¹   rº   r  rU   r   r   r   r  ®  s   €zNativeCoroutineHandler.getN)r“   r”   r•   r  r   r   r   r   r  ­  s    r  c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )Ú
GenWebTestc                 C   s&   t dtfdtfdtfdtfdtfgƒS )Nú/coroutine_sequenceú/coroutine_unfinished_sequenceú/undecorated_coroutineú/async_prepare_errorú/native_coroutine)r
   r  r  r  r  r  rU   r   r   r   Úget_app´  s   þøÿzGenWebTest.get_appc                 C   ó   |   d¡}|  |jd¡ d S )Nr!  ó   123©ÚfetchrR   Úbody©r   Úresponser   r   r   Útest_coroutine_sequence_handlerÂ  ó   
z*GenWebTest.test_coroutine_sequence_handlerc                 C   r'  )Nr"  r(  r)  r,  r   r   r   Ú*test_coroutine_unfinished_sequence_handlerÆ  r/  z5GenWebTest.test_coroutine_unfinished_sequence_handlerc                 C   r'  )Nr#  r(  r)  r,  r   r   r   Útest_undecorated_coroutinesÊ  r/  z&GenWebTest.test_undecorated_coroutinesc                 C   r'  )Nr$  r  )r*  rR   Úcoder,  r   r   r   Ú test_async_prepare_error_handlerÎ  r/  z+GenWebTest.test_async_prepare_error_handlerc                 C   s*   |   d¡}|  |jd¡ |  |jd¡ d S )Nr%  éÈ   s   ok)r*  rR   r2  r+  r,  r   r   r   Útest_native_coroutine_handlerÒ  s   
z(GenWebTest.test_native_coroutine_handlerN)	r“   r”   r•   r&  r.  r0  r1  r3  r5  r   r   r   r   r   ³  s    r   c                   @   s`   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
dS )ÚWithTimeoutTestc                 c   sL   � |   tj¡� t tjdd�tƒ ¡V  W d   ƒ d S 1 sw   Y  d S )Nçš™™™™™¹?©Úseconds)r9   r   ÚTimeoutErrorrÀ   rÁ   rÂ   r   rU   r   r   r   Útest_timeoutÙ  s   €"ÿzWithTimeoutTest.test_timeoutc                 #   sL   � t ƒ ‰ | j tjdd�‡ fdd„¡ t tjdd�ˆ ¡V }|  |d¡ d S )Nr7  r8  c                      s
   ˆ   d¡S )NÚasdf)rß   r   ©rÌ   r   r   Ú<lambda>â  ó   
 z?WithTimeoutTest.test_completes_before_timeout.<locals>.<lambda>é  r<  )r   r/   Úadd_timeoutrÁ   rÂ   r   rÀ   rR   r   r   r=  r   Útest_completes_before_timeoutÞ  s   €ÿz-WithTimeoutTest.test_completes_before_timeoutc                 #   sl   � t ƒ ‰ | j tjdd�‡ fdd„¡ |  t¡� t tjdd�ˆ ¡V  W d   ƒ d S 1 s/w   Y  d S )Nr7  r8  c                      s   ˆ   tƒ ¡S r   )Úset_exceptionr:   r   r=  r   r   r>  ì  s    z;WithTimeoutTest.test_fails_before_timeout.<locals>.<lambda>r@  )	r   r/   rA  rÁ   rÂ   r9   r:   r   rÀ   rU   r   r=  r   Útest_fails_before_timeoutç  s   €

þ"ÿz)WithTimeoutTest.test_fails_before_timeoutc                 c   s8   � t ƒ }| d¡ t tjdd�|¡V }|  |d¡ d S )Nr<  r@  r8  )r   rß   r   rÀ   rÁ   rÂ   rR   )r   rÌ   r   r   r   r   Útest_already_resolvedñ  s
   €
z%WithTimeoutTest.test_already_resolvedc              	   c   sŒ   � t  d¡�6}|  tj¡� t | j ¡ | tj	d¡¡V  W d   ƒ n1 s'w   Y  W d   ƒ d S W d   ƒ d S 1 s?w   Y  d S )Nr$   r7  )
r   ÚThreadPoolExecutorr9   r   r:  rÀ   r/   ri   Úsubmitrº   ©r   Úexecutorr   r   r   Útest_timeout_concurrent_futureø  s   €ÿÿÿ"ÿz.WithTimeoutTest.test_timeout_concurrent_futurec                 c   sb   � t  d¡�!}dd„ }| |¡}| ¡  t tjdd�|¡V  W d   ƒ d S 1 s*w   Y  d S )Nr$   c                   S   r*   r   r   r   r   r   r   rò     ró   z?WithTimeoutTest.test_completed_concurrent_future.<locals>.dummyr@  r8  )r   rF  rG  r   r   rÀ   rÁ   rÂ   )r   rI  rò   r+   r   r   r   Ú test_completed_concurrent_future  s   €
"ùz0WithTimeoutTest.test_completed_concurrent_futurec                 c   sR   � t  d¡�}t tjdd�| dd„ ¡¡V  W d   ƒ d S 1 s"w   Y  d S )Nr$   r@  r8  c                   S   s
   t  d¡S )Nrã   )ri   rº   r   r   r   r   r>    r?  z?WithTimeoutTest.test_normal_concurrent_future.<locals>.<lambda>)r   rF  r   rÀ   rÁ   rÂ   rG  rH  r   r   r   Útest_normal_concurrent_future  s   €
þ"ÿz-WithTimeoutTest.test_normal_concurrent_futureN)r“   r”   r•   r   r;  rB  rD  rE  rJ  rK  rL  r   r   r   r   r6  Ø  s    


	


r6  c                   @   sP   e Zd Zedd„ ƒZedd„ ƒZdd„ Zedd„ ƒZed	d
„ ƒZedd„ ƒZ	dS )ÚWaitIteratorTestc                 C   st   t  ¡ }|  | ¡ d¡ |  t¡� t jtƒ tƒ d�}W d   ƒ n1 s%w   Y  |  |jd¡ |  |j	d¡ d S )Nzempty generator iterated)r[   úbad nil current indexúbad nil current future)
r   ÚWaitIteratorrn   Údoner9   r÷   r   rÆ   Úcurrent_indexÚcurrent_future)r   Úgr   r   r   Útest_empty_iterator  s   ÿz$WaitIteratorTest.test_empty_iteratorc           	      c   sÄ  � t ƒ }t ƒ }t ƒ }| d¡ | d¡ | d¡ t |||¡}d}| ¡ s}| ¡ V }|dkrD|  |jd¡ |  |j	|¡ |  |d¡ n1|dkr]|  |jd¡ |  |j	|¡ |  |d¡ n|dkru|  |jd¡ |  |j	|¡ |  |d¡ |d7 }| ¡ r&|  
|jd¡ |  
|j	d¡ tj||d	�}| ¡ sÒ| ¡ V }|jd
kr®|  |j	|koª|dkd¡ n|jdkrÁ|  |j	|ko½|dkd¡ n	|  d|j› �¡ |d7 }| ¡ r–|  
|jd¡ |  
|j	d¡ d S )Né   rB   éT   r   r$   rJ   rN  rO  )r²   rµ   r²   z"WaitIterator dict status incorrectrµ   zgot bad WaitIterator index )r   rß   r   rP  rQ  ÚnextrR   rR  rž   rS  rÆ   rn   Úfail)	r   r²   rµ   r½   rT  r   ÚrÚdgÚdrr   r   r   Útest_already_done$  sZ   €



ð

þ
þñz"WaitIteratorTest.test_already_donec                 C   s|   |dkr|d   d¡ n|dkr|d  tƒ ¡ n|dkr+|d   d¡ |d   d	¡ |dk r<| j | j|d |¡ d S d S )
NrQ   rJ   rV  rÓ   r   é   r$   rB   rW  )rß   rC  r:   r/   r°   Úfinish_coroutines)r   ré   r   r   r   r   r_  Y  s   ÿz"WaitIteratorTest.finish_coroutinesc                 c   sü   � t ƒ t ƒ t ƒ t ƒ g}|  d|¡ tj|Ž }d}| ¡ s|z| ¡ V }W n ty6   |  |j|d d¡ Y n<w |dkrK|  	|dd¡ |  	|j
dd¡ n'|dkr_|  	|dd¡ |  	|j
dd¡ n|d	krr|  	|d
d¡ |  	|j
d	d¡ |d7 }| ¡ rd S d S )Nr   zexception future invalidrV  úiterator value incorrectrJ   úwrong indexrB   r$   rQ   rW  )r   r_  r   rP  rQ  rX  r:   rž   rS  rR   rR  )r   r   rT  r   rZ  r   r   r   Útest_iteratore  s,   €
ÿñzWaitIteratorTest.test_iteratorc                 #   sN   � t ƒ t ƒ t ƒ t ƒ g‰ ˆ dˆ ¡ dˆ_‡ ‡fdd„}|ƒ V  ˆ ˆj¡ d S )Nr   Fc                  “   sþ   �d} t jˆ Ž }z(|2 z"3 d H W }| dkr%ˆ |dd¡ ˆ |jdd¡ ntdƒ‚| d7 } q6 W n ty=   | d7 } Y nw |2 z83 d H W }| dkrZˆ |dd¡ ˆ |jdd¡ n| d	krnˆ |d
d¡ ˆ |jd	d¡ ntd|  ƒ‚| d7 } q@6 dˆ_d S )Nr   rV  r`  rJ   ra  z!expected exception on iteration 1r$   rB   rQ   rW  zdidn't expect iteration %dT)r   rP  rR   rR  rî   r:   r—   )r   rT  rZ  ©r   r   r   r   r+   ˆ  s2   €

úÿ
÷

z5WaitIteratorTest.test_iterator_async_await.<locals>.f)r   r_  r—   rn   r1   r   rc  r   Útest_iterator_async_await  s   €z*WaitIteratorTest.test_iterator_async_awaitc                 c   s,   � t  tjdd�t  t  d¡¡ ¡ ¡V  d S )Nr7  r8  r   )r   rÀ   rÁ   rÂ   rP  rº   rX  rU   r   r   r   Útest_no_ref¤  s   €
ÿzWaitIteratorTest.test_no_refN)
r“   r”   r•   r   rU  r]  r_  rb  rd  re  r   r   r   r   rM    s    


4

$rM  c                   @   s8   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	d
„ ZdS )ÚRunnerGCTestc                 C   s   t  ¡ dko
tjdkS )NÚPyPy)rQ   )ÚplatformÚpython_implementationÚsysÚversion_inforU   r   r   r   Úis_pypy3°  s   zRunnerGCTest.is_pypy3c                 #   sF   � d g‰‡fdd„‰ t j‡ ‡‡fdd„ƒ}t  tjdd�|ƒ ¡V  d S )Nc                      s   t  d¡ ˆ d ƒ  d¡ d S )NrJ   r   é{   )ÚgcÚcollectrß   r   )Úweakref_scoper   r   Úcallback¹  s   
z&RunnerGCTest.test_gc.<locals>.callbackc                  3   s,   � t ƒ } t | ¡ˆd< ˆj ˆ ¡ | V  d S )Nr   )r   rô   rõ   r/   r°   ©Úfut©rq  r   rp  r   r   Útester½  s
   €
z$RunnerGCTest.test_gc.<locals>.testerçš™™™™™É?r8  )r   r.   rÀ   rÁ   rÂ   )r   ru  r   rt  r   Útest_gc³  s   €zRunnerGCTest.test_gcc                    sŽ   |   ¡ }g ‰g ‰tj‡fdd„ƒ‰ tj‡ ‡fdd„ƒ}| |¡ | ¡  t ¡  |  ˆd ƒ ¡ |  t	ˆƒd¡ |  
¡ sE|  ˆd ¡ d S d S )Nc                	   3   s*   � z	 t  d¡V  ˆ  d¡ qˆ  d ¡ w ©NTgü©ñÒMbP?©r   rº   rÔ   r   r³   r   r   Úinfinite_coroÎ  s   €
þz9RunnerGCTest.test_gc_infinite_coro.<locals>.infinite_coroc                  3   s.   � ˆ ƒ } | | _ ˆ t | ¡¡ t d¡V  d S ©Nrv  )Ú	_refcyclerÔ   rô   rõ   r   rº   rr  )rz  Úwfutr   r   Údo_somethingØ  s
   €z8RunnerGCTest.test_gc_infinite_coro.<locals>.do_somethingr   rJ   éÿÿÿÿ)Úget_new_ioloopr   r.   r0   Úclosern  ro  rÆ   ÚassertGreaterEqualÚlenrl  ©r   Úloopr~  r   )rz  r   r}  r   Útest_gc_infinite_coroÆ  s   	
þz"RunnerGCTest.test_gc_infinite_coroc                    sº   dd l ‰ dd„ ‰|  ¡ }g ‰g ‰tj‡ ‡‡‡fdd„ƒ}| |¡ tddƒ� | ¡  t ¡  W d   ƒ n1 s9w   Y  |  	ˆd ƒ ¡ |  
tˆƒd¡ |  ¡ s[|  	ˆd	 ¡ d S d S )
Nr   c              	   Ó   s.   �z	 t  d¡I d H  |  d¡ q|  d ¡ w rx  ry  r³   r   r   r   rz  î  s   €
þz@RunnerGCTest.test_gc_infinite_async_await.<locals>.infinite_coroc                  3   s:   � ˆ   ¡  ˆˆƒ¡} | | _ˆ t | ¡¡ t d¡V  d S r{  )rü   Úcreate_taskr|  rÔ   rô   rõ   r   rº   rr  ©r¹   rz  r   r}  r   r   r~  û  s
   €z?RunnerGCTest.test_gc_infinite_async_await.<locals>.do_somethingr¹   z$Task was destroyed but it is pendingrJ   r  )r¹   r€  r   r.   r0   r   r�  rn  ro  rÆ   r‚  rƒ  rl  r„  r   rˆ  r   Útest_gc_infinite_async_awaitê  s"   	

þþz)RunnerGCTest.test_gc_infinite_async_awaitc                 C   s4   t jdd„ ƒ}|  ¡ }| |¡}|  |d d g¡ d S )Nc                  s   s    � t  t jt jg¡V } t  | ¡‚r   )r   Úmultir   r   r³   r   r   r   Úwait_a_moment  s   €
z5RunnerGCTest.test_multi_moment.<locals>.wait_a_moment)r   r.   r€  r0   rR   )r   r‹  r…  r   r   r   r   Útest_multi_moment  s
   

zRunnerGCTest.test_multi_momentN)	r“   r”   r•   rl  r   rw  r†  r‰  rŒ  r   r   r   r   rf  ¯  s    
$$rf  Úctx_varzcontextvars module not presentc                   @   sd   e Zd Zdd„ Zejdd„ ƒZdd„ Zejdd„ ƒZd	d
„ Z	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdS )ÚContextVarsTestc                 Ã   s    �t  |¡ |  |¡I d H  d S r   ©r�  Úsetrë   r&   r   r   r   Únative_root!  s   €
zContextVarsTest.native_rootc                 c   s"   � t  |¡ d V  |  |¡V  d S r   r�  r&   r   r   r   Úgen_root%  s   €
zContextVarsTest.gen_rootc                 ƒ   s    �ˆ  t ¡ ˆ¡ ˆ ˆ¡I d H  ˆ  t ¡ ˆ¡ t ¡ ‰ ˆj d ‡ ‡‡fdd„¡I d H  ˆ  t ¡ ˆ¡ t 	¡  d ‡ ‡‡fdd„¡I d H  ˆ  t ¡ ˆ¡ d S )Nc                      ó   ˆ   ˆjˆ¡S r   ©ÚrunÚthread_innerr   ©Úctxr   r'   r   r   r>  2  ó    z'ContextVarsTest.inner.<locals>.<lambda>c                      r“  r   r”  r   r—  r   r   r>  7  r™  )
rR   r�  r  Ú	gen_innerÚcontextvarsÚcopy_contextr/   Úrun_in_executorr¹   rü   r&   r   r—  r   rë   +  s   € 
ÿzContextVarsTest.innerc                 c   s,   � |   t ¡ |¡ d V  |   t ¡ |¡ d S r   ©rR   r�  r  r&   r   r   r   rš  ;  s   €zContextVarsTest.gen_innerc                 C   s   |   t ¡ |¡ d S r   rž  r&   r   r   r   r–  A  s   zContextVarsTest.thread_innerc                 c   s,   � |   d¡|   d¡|  d¡|  d¡gV  d S )Nr$   rJ   rQ   é   )r‘  r’  rU   r   r   r   Útest_propagateD  s   €
üzContextVarsTest.test_propagatec                 c   s    � t  d¡}d V  t  |¡ d S r#   )r�  r�  Úreset)r   Útokenr   r   r   Ú
test_resetO  s   €
zContextVarsTest.test_resetc                 #   s*   � d‰‡ ‡fdd„}t  ˆ¡ |ƒ V  d S )Né
   c                   “   s   �ˆ   t ¡ ˆ¡ d S r   rž  r   r&   r   r   Únative_async_function[  s   €zgContextVarsTest.test_propagate_to_first_yield_with_native_async_function.<locals>.native_async_function)r�  r�  )r   r¥  r   r&   r   Ú8test_propagate_to_first_yield_with_native_async_functionW  s
   €
zHContextVarsTest.test_propagate_to_first_yield_with_native_async_functionN)r“   r”   r•   r‘  r   r.   r’  rë   rš  r–  r   r   r£  r¦  r   r   r   r   rŽ    s    




rŽ  Ú__main__)2r¹   Ú
concurrentr   rn  rÁ   rh  rj  ri   rô   ÚunittestÚtornado.concurrentr   Útornado.logr   Útornado.testingr   r   r   r   Útornado.test.utilr	   Útornado.webr
   r   r   Útornador   r›  ÚImportErrorÚtypingÚTYPE_CHECKINGr   r   r   r–   r  r  r  r  r  r   r6  rM  rf  Ú
ContextVarr�  ÚskipIfrŽ  r“   Úmainr   r   r   r   Ú<module>   sZ    ÿ |  d
%@ l
Bÿ