
    Mh)                        d dl mZm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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Zej        d             Z G d d	e	          Z G d
 de	          Z G d de          Z G d dej                  Z G d dej                  Z G d dej                  Z G d de	          Z e!dk    r ej"                     dS dS )    )genioloop)
HTTPServer)Event)AsyncHTTPTestCaseAsyncTestCasebind_unused_portgen_testApplicationNc              #      K   t           j                            |           }|t           j        | <   	 d V  |t           j        | = d S |t           j        | <   d S # |t           j        | = n|t           j        | <   w xY wN)osenvironget)namevalue	old_values      Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/test/testing_test.pyset_environr      s      
t$$IBJt)
4   (BJt 
4  (BJt((((s   A !A9c                       e Zd Zd Zd ZdS )AsyncTestCaseTestc                    | j         j        }| j                              |            dz   | j                   |                                  | j                              |            dz   | j                   |                     | j                  5  |                     d           d d d            n# 1 swxY w Y   | j                              |            dz   | j                   t          dd          5  |                     | j                  5  |                                  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N{Gz?   timeoutASYNC_TEST_TIMEOUTz0.01)io_looptimeadd_timeoutstopwaitassertRaisesfailureExceptionr   )selfr    s     r   test_wait_timeoutz#AsyncTestCaseTest.test_wait_timeout    s   |  	  $	:::		 	  !TY777t455 	$ 	$IIdI###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	  !TY777-v66 	 	""4#899  		              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sH   B44B8;B8:ED6*E6D:	:E=D:	>EEEc                 F   | j                             | j                                         dz   | j                   |                     d           | j                             | j                                         dz   | j                   |                     d           dS )ze
        This test makes sure that a second call to wait()
        clears the first timeout.
        g        皙?r   g?g?N)r   r!   r    r"   r#   r&   s    r   test_subsequent_wait_callsz,AsyncTestCaseTest.test_subsequent_wait_calls2   s     	  !2!2!4!4t!;TYGGG		#	 	  !2!2!4!4s!:DIFFF		#	    N)__name__
__module____qualname__r'   r+    r,   r   r   r      s2          $    r,   r   c                   $     e Zd Z fdZd Z xZS )LeakTestc                 n    t                                                       t          j                     d S r   )supertearDowngccollectr&   	__class__s    r   r5   zLeakTest.tearDownA   s(    

r,   c                     t                      fd}| j                            |           | j                            | j                   |                                  d S )Nc                  n   K   	                                    d {V  d S # t          j        $ r Y d S w xY wr   )r#   asyncioCancelledError)events   r   callbackz0LeakTest.test_leaked_coroutine.<locals>.callbackM   sW      jjll""""""""")   s   ! 44)r   r   add_callbackr"   r#   )r&   r?   r>   s     @r   test_leaked_coroutinezLeakTest.test_leaked_coroutineF   sh    
 	 	 	 	 	 	!!(+++!!$),,,		r,   )r-   r.   r/   r5   rA   __classcell__r9   s   @r   r2   r2   @   sG            
      r,   r2   c                   :     e Zd Z fdZd Zd Zd Z fdZ xZS )AsyncHTTPTestCaseTestc                 
   t                                                       t                      \  }}t                      }t	          |fi |                                 }|                    |           || _        || _        d S r   )	r4   setUpr	   r   r   get_httpserver_options
add_socketsecond_portsecond_server)r&   sockportappserverr9   s        r   rG   zAsyncHTTPTestCaseTest.setUpY   sw    %''
dmmCAA4#>#>#@#@AA$#r,   c                     t                      S r   r   r*   s    r   get_appzAsyncHTTPTestCaseTest.get_appc   s    }}r,   c                     d}|                      |          }|                     |j        j        |                     |                     d S )Nz/path)fetchassertEqualrequesturlget_urlr&   pathresponses      r   test_fetch_segmentz(AsyncHTTPTestCaseTest.test_fetch_segmentf   sF    ::d##)-t||D/A/ABBBBBr,   c                     d| j         z  }|                     |          }|                     |j        j        |           d S )Nzhttp://127.0.0.1:%d/path)rJ   rS   rT   rU   rV   rX   s      r   test_fetch_full_http_urlz.AsyncHTTPTestCaseTest.test_fetch_full_http_urlk   sD     *D,<<::d##)-t44444r,   c                 z    | j                                          t                                                       d S r   )rK   r"   r4   r5   r8   s    r   r5   zAsyncHTTPTestCaseTest.tearDowns   s4    !!!r,   )	r-   r.   r/   rG   rQ   r[   r]   r5   rB   rC   s   @r   rE   rE   X   s        $ $ $ $ $  C C C
5 5 5        r,   rE   c                       e Zd Zd Z ej         ej                    dk    d           ej        ej	        dk    d          d                         Z
d Zd Zd	S )
!AsyncTestCaseReturnAssertionsTestc                 0    G d dt                     } |d          }t          j                    }|                    |           |                     t          |j                  d           |                     d|j        d         d                    d S )Nc                       e Zd Zd ZdS )JAsyncTestCaseReturnAssertionsTest.test_undecorated_generator.<locals>.Testc              3      K   d V  d S r   r0   r*   s    r   test_genzSAsyncTestCaseReturnAssertionsTest.test_undecorated_generator.<locals>.Test.test_gen   s      r,   N)r-   r.   r/   re   r0   r,   r   Testrc   ~   s#            r,   rf   re   r   should be decoratedr   r   unittest
TestResultrunrT   lenerrorsassertInr&   rf   testresults       r   test_undecorated_generatorz<AsyncTestCaseReturnAssertionsTest.test_undecorated_generator}   s    	 	 	 	 	= 	 	 	 tJ$&&V]++Q///+V]1-=a-@AAAAAr,   PyPyz+pypy destructor warnings cannot be silenced)      z-py312 has its own check for test case returnsc                     G d dt                     } |d          }t          j                    }t          j                    5  t          j        d           |                    |           d d d            n# 1 swxY w Y   |                     t          |j	                  d           | 
                    d|j	        d         d                    d S )Nc                       e Zd Zd ZdS )JAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine.<locals>.Testc                 
   K   d S r   r0   r*   s    r   	test_corozTAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine.<locals>.Test.test_coro   s      r,   N)r-   r.   r/   rz   r0   r,   r   rf   rx      s#            r,   rf   rz   ignorer   rg   r   )r   ri   rj   warningscatch_warningssimplefilterrk   rT   rl   rm   rn   ro   s       r   test_undecorated_coroutinez<AsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine   s   	 	 	 	 	= 	 	 	 tK  $&& $&& 	 	!(+++HHV	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	V]++Q///+V]1-=a-@AAAAAs   *A;;A?A?c                 2    G d dt                     } |d          }t          j                    }|                    |           |                     t          |j                  d           |                     t          |j                  d           d S )Nc                   @    e Zd Z ej        d          d             ZdS )TAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip.<locals>.Testzdon't run thisc              3      K   d V  d S r   r0   r*   s    r   re   z]AsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip.<locals>.Test.test_gen   s      r,   N)r-   r.   r/   ri   skipre   r0   r,   r   rf   r      s;        X]+,,  -,  r,   rf   re   r   r   )r   ri   rj   rk   rT   rl   rm   skippedro   s       r   $test_undecorated_generator_with_skipzFAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip   s    	 	 	 	 	= 	 	 	
 tJ$&&V]++Q///V^,,a00000r,   c                 0    G d dt                     } |d          }t          j                    }|                    |           |                     t          |j                  d           |                     d|j        d         d                    d S )Nc                       e Zd Zd ZdS )AAsyncTestCaseReturnAssertionsTest.test_other_return.<locals>.Testc                     dS )N*   r0   r*   s    r   test_other_returnzSAsyncTestCaseReturnAssertionsTest.test_other_return.<locals>.Test.test_other_return   s    rr,   N)r-   r.   r/   r   r0   r,   r   rf   r      s#            r,   rf   r   r   z%Return value from test method ignoredr   rh   ro   s       r   r   z3AsyncTestCaseReturnAssertionsTest.test_other_return   s    	 	 	 	 	= 	 	 	 t'(($&&V]++Q///=v}Q?OPQ?RSSSSSr,   N)r-   r.   r/   rr   ri   skipIfplatformpython_implementationsysversion_infor   r   r   r0   r,   r   r`   r`   x   s        
	B 	B 	B X_&&((F25  X_ 	G#7	 B B 	 B 
1 
1 
1	T 	T 	T 	T 	Tr,   r`   c                       e Zd Zd ZdS )SetUpTearDownTestc                    g t          j                    } G fddt           j                  } G fddt          |          } |d                              |           g d}|                     |           dS )a  
        This test makes sure that AsyncTestCase calls super methods for
        setUp and tearDown.

        InheritBoth is a subclass of both AsyncTestCase and
        SetUpTearDown, with the ordering so that the super of
        AsyncTestCase will be SetUpTearDown.
        c                   $    e Zd Z fdZ fdZdS )>SetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDownc                 2                         d           d S )NrG   appendr&   eventss    r   rG   zDSetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDown.setUp   s    g&&&&&r,   c                 2                         d           d S )Nr5   r   r   s    r   r5   zGSetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDown.tearDown   s    j)))))r,   N)r-   r.   r/   rG   r5   r   s   r   SetUpTearDownr      sG        ' ' ' ' '* * * * * * *r,   r   c                       e Zd Z fdZdS )<SetUpTearDownTest.test_set_up_tear_down.<locals>.InheritBothc                 2                         d           d S Nrp   r   r   s    r   rp   zASetUpTearDownTest.test_set_up_tear_down.<locals>.InheritBoth.test   s    f%%%%%r,   N)r-   r.   r/   rp   r   s   r   InheritBothr      s.        & & & & & & &r,   r   rp   )rG   rp   r5   N)ri   rj   TestCaser   rk   rT   )r&   rq   r   r   expectedr   s        @r   test_set_up_tear_downz'SetUpTearDownTest.test_set_up_tear_down   s     $&&	* 	* 	* 	* 	* 	* 	*H- 	* 	* 	*	& 	& 	& 	& 	& 	& 	&- 	& 	& 	& 	F'''0006*****r,   N)r-   r.   r/   r   r0   r,   r   r   r      s#        + + + + +r,   r   c                       e Zd Zd ZdS )"AsyncHTTPTestCaseSetUpTearDownTestc                    t          j                    } G d dt                    } |d          }|                    |           |                     t          |d                     |                     t          |d                     d S )Nc                       e Zd Zd Zd ZdS )eAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDownc                     t                      S r   r   r*   s    r   rQ   zmAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDown.get_app   s    "}}$r,   c                     |                      t          | d                     |                      t          | d                     d S )N_apphttp_server)
assertTruehasattrr*   s    r   rp   zjAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDown.test   s@    f 5 5666m < <=====r,   N)r-   r.   r/   rQ   rp   r0   r,   r   r   r      s2        % % %> > > > >r,   r   rp   r   r   )ri   rj   r   rk   assertFalser   )r&   rq   r   rp   s       r   +test_tear_down_releases_app_and_http_serverzNAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server   s    $&&	> 	> 	> 	> 	>- 	> 	> 	> }V$$v..///}5566666r,   N)r-   r.   r/   r   r0   r,   r   r   r      s#        7 7 7 7 7r,   r   c                        e Zd Z fdZ fdZed             Zed             Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Z xZS )GenTestc                 V    t                                                       d| _        d S )NF)r4   rG   finishedr8   s    r   rG   zGenTest.setUp   s    r,   c                 |    |                      | j                   t                                                       d S r   )r   r   r4   r5   r8   s    r   r5   zGenTest.tearDown   s3    &&&r,   c                     d| _         d S NTr   r*   s    r   	test_synczGenTest.test_sync   s    r,   c              #   4   K   t           j        V  d| _        d S r   )r   momentr   r*   s    r   
test_asynczGenTest.test_async   s      jr,   c                    t          d          d             }	  ||            |                     d           n<# t          j        $ r* |                     dt          j                               Y nw xY wd| _        d S )Nr)   r   c              3   6   K   t          j        d          V  d S Nr   r   sleepr*   s    r   rp   z"GenTest.test_timeout.<locals>.test          )A,,r,   did not get expected exceptionzgen.sleep(1)T)r
   failr   TimeoutErrorrn   	traceback
format_excr   r&   rp   s     r   test_timeoutzGenTest.test_timeout   s    	#				 	 
		
	BDJJJII67777" 	B 	B 	B MM.)*>*@*@AAAAA	B
 s    < 6A54A5c                 \    t          d          d             } ||            d| _        d S )Nr   r   c              3   6   K   t          j        d          V  d S )Nr)   r   r*   s    r   rp   z%GenTest.test_no_timeout.<locals>.test  s       )C..     r,   Tr
   r   r   s     r   test_no_timeoutzGenTest.test_no_timeout  sA    	!				! 	! 
		! 	T


r,   c                     t          d          d             }t          dd          5   ||            d d d            n# 1 swxY w Y   d| _        d S )Ng      ?r   c              3   6   K   t          j        d          V  d S )Ng      ?r   r*   s    r   test_long_timeoutzDGenTest.test_timeout_environment_variable.<locals>.test_long_timeout  s       )D//!!!!!r,   r   0.1T)r
   r   r   )r&   r   s     r   !test_timeout_environment_variablez)GenTest.test_timeout_environment_variable  s    	#				" 	" 
		" -u55 	$ 	$d###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ s   AA	Ac                    t          d          d             }t          dd          5  |                     t          j                  5   ||            d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d| _        d S )Nr   r   c              3   6   K   t          j        d          V  d S r   r   r*   s    r   test_short_timeoutzHGenTest.test_no_timeout_environment_variable.<locals>.test_short_timeout"  r   r,   r   r   T)r
   r   r$   r   r   r   )r&   r   s     r   $test_no_timeout_environment_variablez,GenTest.test_no_timeout_environment_variable!  s   	$				 	 
 		 -u55 	) 	)""6#677 ) )""4((() ) ) ) ) ) ) ) ) ) ) ) ) ) )	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) s5    A9
A"A9"A&	&A9)A&	*A99A= A=c                 L    t           d             } || d           d| _        d S )Nc              7   R   K   |                      |d           t          j        V  d S )Nrp   )rT   r   r   )r&   argss     r   test_with_argsz5GenTest.test_with_method_args.<locals>.test_with_args.  s0      T9---*r,   rp   Tr   )r&   r   s     r   test_with_method_argszGenTest.test_with_method_args-  s:    		 	 
	 	tV$$$r,   c                 N    t           d             } || d           d| _        d S )Nc              ;   V   K   |                      |ddi           t          j        V  d S r   )assertDictEqualr   r   )r&   kwargss     r   test_with_kwargsz9GenTest.test_with_method_kwargs.<locals>.test_with_kwargs7  s5        &&)9:::*r,   rp   r   Tr   )r&   r   s     r   test_with_method_kwargszGenTest.test_with_method_kwargs6  s>    		 	 
	 	F++++r,   c                 <    t           d             } ||            d S )Nc                    K   d| _         d S r   r   r*   s    r   rp   z+GenTest.test_native_coroutine.<locals>.test@  s       DMMMr,   )r
   r   s     r   test_native_coroutinezGenTest.test_native_coroutine?  s.    		! 	! 
	! 	T




r,   c                     t          d          d             }	  ||            |                     d           d S # t          j        $ r d| _        Y d S w xY w)Nr)   r   c                 >   K   t          j        d           d {V  d S r   r   r*   s    r   rp   z3GenTest.test_native_coroutine_timeout.<locals>.testH  s,      )A,,r,   r   T)r
   r   r   r   r   r   s     r   test_native_coroutine_timeoutz%GenTest.test_native_coroutine_timeoutF  s}    	#				 	 
			!DJJJII677777" 	! 	! 	! DMMMM	!s    = AA)r-   r.   r/   rG   r5   r
   r   r   r   r   r   r   r   r   r   r   rB   rC   s   @r   r   r      s                   X   X  $  	 	 	
 
 
      
! 
! 
! 
! 
! 
! 
!r,   r   __main__)#tornador   r   tornado.httpserverr   tornado.locksr   tornado.testingr   r   r	   r
   tornado.webr   r<   
contextlibr6   r   r   r   r   ri   r|   contextmanagerr   r   r2   rE   r   r`   r   r   r   r-   mainr0   r,   r   <module>r      sW           ) ) ) ) ) )       X X X X X X X X X X X X # # # # # #      				 				  



       
) 
) 
)       B    }   0    -   @?T ?T ?T ?T ?T(9 ?T ?T ?TD+ + + + +) + + +:7 7 7 7 7): 7 7 7$g! g! g! g! g!m g! g! g!T zHMOOOOO r,   