
    R?g)                        S SK JrJr  S SKJr  S SKJr  S SKJrJ	r	J
r
Jr  S SKJr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKr\R.                  S 5       r " S S	\	5      r " S
 S\	5      r " S S\5      r " S S\R8                  5      r " S S\R8                  5      r " S S\R8                  5      r " S S\	5      r \!S:X  a  \RD                  " 5         gg)    )genioloop)
HTTPServer)Event)AsyncHTTPTestCaseAsyncTestCasebind_unused_portgen_testApplicationNc              #   $  #    [         R                  R                  U 5      nU[         R                  U '    S v   Uc  [         R                  U 	 g U[         R                  U '   g ! Uc  [         R                  U 	 f U[         R                  U '   f = f7fN)osenvironget)namevalue	old_values      ;/usr/lib/python3/dist-packages/tornado/test/testing_test.pyset_environr      sp     

t$IBJJt)

4 (BJJt 

4 (BJJts   3BA# )B#*BBc                        \ rS rSrS rS rSrg)AsyncTestCaseTest   c                    U R                   R                  nU R                   R                  U" 5       S-   U R                  5        U R	                  5         U R                   R                  U" 5       S-   U R                  5        U R                  U R                  5         U R	                  SS9  S S S 5        U R                   R                  U" 5       S-   U R                  5        [        SS5         U R                  U R                  5         U R	                  5         S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N(= f! , (       d  f       g = f)N{Gz?   timeoutASYNC_TEST_TIMEOUTz0.01)io_looptimeadd_timeoutstopwaitassertRaisesfailureExceptionr   )selfr!   s     r   test_wait_timeout#AsyncTestCaseTest.test_wait_timeout    s    ||   	  $		:		 	  !TYY7t445IIdI# 6 	  !TYY7-v6""4#8#89		 : 76 65 :9 76s0   D.0ED?E.
D<?
E		E
Ec                 D   U R                   R                  U R                   R                  5       S-   U R                  5        U R	                  SS9  U R                   R                  U R                   R                  5       S-   U R                  5        U R	                  SS9  g)zM
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_calls,AsyncTestCaseTest.test_subsequent_wait_calls2   sv     	  !2!2!4t!;TYYG		#	 	  !2!2!4s!:DIIF		#	     N)__name__
__module____qualname____firstlineno__r(   r-   __static_attributes__r0   r/   r   r   r      s    $r/   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )LeakTest@   c                 L   > [         TU ]  5         [        R                  " 5         g r   )supertearDowngccollectr'   	__class__s    r   r;   LeakTest.tearDownA   s    


r/   c                    ^ [        5       mU4S jnU R                  R                  U5        U R                  R                  U R                  5        U R	                  5         g )Nc                  x   >#     T R                  5       I S h  vN   g  N! [        R                   a     g f = f7fr   )r$   asyncioCancelledError)events   r   callback0LeakTest.test_leaked_coroutine.<locals>.callbackM   s1     jjl"")) s(   :    :  7:7:)r   r    add_callbackr#   r$   )r'   rF   rE   s     @r   test_leaked_coroutineLeakTest.test_leaked_coroutineF   sD    
 	 	!!(+!!$)),		r/   r0   )r1   r2   r3   r4   r;   rI   r5   __classcell__r?   s   @r   r7   r7   @   s    
 r/   r7   c                   F   ^  \ rS rSrU 4S jrS rS rS rU 4S jrSr	U =r
$ )AsyncHTTPTestCaseTestX   c                    > [         TU ]  5         [        5       u  p[        5       n[	        U40 U R                  5       D6nUR                  U5        X l        X@l        g r   )	r:   setUpr	   r   r   get_httpserver_options
add_socketsecond_portsecond_server)r'   sockportappserverr?   s        r   rQ   AsyncHTTPTestCaseTest.setUpY   sO    %'
mCA4#>#>#@A$#r/   c                     [        5       $ r   r   r,   s    r   get_appAsyncHTTPTestCaseTest.get_appc   s
    }r/   c                     SnU R                  U5      nU R                  UR                  R                  U R	                  U5      5        g )Nz/path)fetchassertEqualrequesturlget_urlr'   pathresponses      r   test_fetch_segment(AsyncHTTPTestCaseTest.test_fetch_segmentf   s:    ::d#))--t||D/ABr/   c                     SU R                   -  nU R                  U5      nU R                  UR                  R                  U5        g )Nzhttp://127.0.0.1:%d/path)rT   r_   r`   ra   rb   rd   s      r   test_fetch_full_http_url.AsyncHTTPTestCaseTest.test_fetch_full_http_urlk   s>     *D,<,<<::d#))--t4r/   c                 V   > U R                   R                  5         [        TU ]  5         g r   )rU   r#   r:   r;   r>   s    r   r;   AsyncHTTPTestCaseTest.tearDowns   s     !r/   )rT   rU   )r1   r2   r3   r4   rQ   r\   rg   rj   r;   r5   rK   rL   s   @r   rN   rN   X   s"    $C
5 r/   rN   c                       \ rS rSrS r\R                  " \R                  " 5       S:H  S5      \R                  " \	R                  S:  S5      S 5       5       rS rS	 rS
rg)!AsyncTestCaseReturnAssertionsTestx   c                     " S S[         5      nU" S5      n[        R                  " 5       nUR                  U5        U R	                  [        UR                  5      S5        U R                  SUR                  S   S   5        g )Nc                       \ rS rSrS rSrg)JAsyncTestCaseReturnAssertionsTest.test_undecorated_generator.<locals>.Test~   c              3      #    S v   g 7fr   r0   r,   s    r   test_genSAsyncTestCaseReturnAssertionsTest.test_undecorated_generator.<locals>.Test.test_gen   s        r0   N)r1   r2   r3   r4   rv   r5   r0   r/   r   Testrs   ~   s    r/   ry   rv   r   should be decoratedr   r   unittest
TestResultrunr`   lenerrorsassertInr'   ry   testresults       r   test_undecorated_generator<AsyncTestCaseReturnAssertionsTest.test_undecorated_generator}   sj    	= 	 J$$&V]]+Q/+V]]1-=a-@Ar/   PyPyz+pypy destructor warnings cannot be silenced)      z-py312 has its own check for test case returnsc                     " S S[         5      nU" S5      n[        R                  " 5       n[        R                  " 5          [        R
                  " S5        UR                  U5        S S S 5        U R                  [        UR                  5      S5        U R                  SUR                  S   S   5        g ! , (       d  f       NV= f)Nc                       \ rS rSrS rSrg)JAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine.<locals>.Test   c                    #    g 7fr   r0   r,   s    r   	test_coroTAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine.<locals>.Test.test_coro   s     s   r0   N)r1   r2   r3   r4   r   r5   r0   r/   r   ry   r      s    r/   ry   r   ignorer   rz   r   )r   r|   r}   warningscatch_warningssimplefilterr~   r`   r   r   r   r   s       r   test_undecorated_coroutine<AsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine   s    	= 	 K $$& $$&!!(+HHV ' 	V]]+Q/+V]]1-=a-@A '&s   (B::
Cc                     " S S[         5      nU" S5      n[        R                  " 5       nUR                  U5        U R	                  [        UR                  5      S5        U R	                  [        UR                  5      S5        g )Nc                   D    \ rS rSr\R
                  " S5      S 5       rSrg)TAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip.<locals>.Test   zdon't run thisc              3      #    S v   g 7fr   r0   r,   s    r   rv   ]AsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip.<locals>.Test.test_gen   s     rx   r0   N)r1   r2   r3   r4   r|   skiprv   r5   r0   r/   r   ry   r      s    ]]+, -r/   ry   rv   r   r   )r   r|   r}   r~   r`   r   r   skippedr   s       r   $test_undecorated_generator_with_skipFAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip   sf    	= 	
 J$$&V]]+Q/V^^,a0r/   c                     " S S[         5      nU" S5      n[        R                  " 5       nUR                  U5        U R	                  [        UR                  5      S5        U R                  SUR                  S   S   5        g )Nc                       \ rS rSrS rSrg)AAsyncTestCaseReturnAssertionsTest.test_other_return.<locals>.Test   c                     g)N*   r0   r,   s    r   test_other_returnSAsyncTestCaseReturnAssertionsTest.test_other_return.<locals>.Test.test_other_return   s    r/   r0   N)r1   r2   r3   r4   r   r5   r0   r/   r   ry   r      s    r/   ry   r   r   z%Return value from test method ignoredr   r{   r   s       r   r   3AsyncTestCaseReturnAssertionsTest.test_other_return   sl    	= 	 '($$&V]]+Q/=v}}Q?OPQ?RSr/   r0   N)r1   r2   r3   r4   r   r|   skipIfplatformpython_implementationsysversion_infor   r   r   r5   r0   r/   r   ro   ro   x   sl    
	B __&&(F25 __ 	G#7	B	B 
1	Tr/   ro   c                       \ rS rSrS rSrg)SetUpTearDownTest   c                    ^ / m[         R                  " 5       n " U4S jS[         R                  5      n " U4S jS[        U5      nU" S5      R	                  U5        / SQnU R                  UT5        g)z
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                   .   > \ rS rSrU 4S jrU 4S jrSrg)>SetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDown   c                 (   > TR                  S5        g )NrQ   appendr'   eventss    r   rQ   DSetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDown.setUp   s    g&r/   c                 (   > TR                  S5        g )Nr;   r   r   s    r   r;   GSetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDown.tearDown   s    j)r/   r0   N)r1   r2   r3   r4   rQ   r;   r5   r   s   r   SetUpTearDownr      s    '* *r/   r   c                   "   > \ rS rSrU 4S jrSrg)<SetUpTearDownTest.test_set_up_tear_down.<locals>.InheritBoth   c                 (   > TR                  S5        g Nr   r   r   s    r   r   ASetUpTearDownTest.test_set_up_tear_down.<locals>.InheritBoth.test   s    f%r/   r0   N)r1   r2   r3   r4   r   r5   r   s   r   InheritBothr      s    & &r/   r   r   )rQ   r   r;   N)r|   r}   TestCaser   r~   r`   )r'   r   r   r   expectedr   s        @r   test_set_up_tear_down'SetUpTearDownTest.test_set_up_tear_down   sb     $$&	*H-- 	*	&- 	& 	F'06*r/   r0   N)r1   r2   r3   r4   r   r5   r0   r/   r   r   r      s    +r/   r   c                       \ rS rSrS rSrg)"AsyncHTTPTestCaseSetUpTearDownTest   c                     [         R                  " 5       n " S S[        5      nU" S5      nUR                  U5        U R	                  [        US5      5        U R	                  [        US5      5        g )Nc                        \ rS rSrS rS rSrg)eAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDown   c                     [        5       $ r   r   r,   s    r   r\   mAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDown.get_app   s
    "}$r/   c                 p    U R                  [        U S5      5        U R                  [        U S5      5        g )N_apphttp_server)
assertTruehasattrr,   s    r   r   jAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDown.test   s(    f 56m <=r/   r0   N)r1   r2   r3   r4   r\   r   r5   r0   r/   r   r   r      s    %>r/   r   r   r   r   )r|   r}   r   r~   assertFalser   )r'   r   r   r   s       r   +test_tear_down_releases_app_and_http_serverNAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server   s_    $$&	>- 	> V$v./}56r/   r0   N)r1   r2   r3   r4   r   r5   r0   r/   r   r   r      s    7r/   r   c                      ^  \ rS rSrU 4S jrU 4S jr\S 5       r\S 5       rS r	S r
S rS	 rS
 rS rS rS rSrU =r$ )GenTest   c                 0   > [         TU ]  5         SU l        g )NF)r:   rQ   finishedr>   s    r   rQ   GenTest.setUp   s    r/   c                 X   > U R                  U R                  5        [        TU ]  5         g r   )r   r   r:   r;   r>   s    r   r;   GenTest.tearDown   s    &r/   c                     SU l         g NTr   r,   s    r   	test_syncGenTest.test_sync   s	    r/   c              #   >   #    [         R                  v   SU l        g 7fr   )r   momentr   r,   s    r   
test_asyncGenTest.test_async   s     jjs   c                     [        SS9S 5       n U" U 5        U R                  S5        SU l        g ! [        R                   a(    U R	                  S[
        R                  " 5       5         NCf = f)Nr+   r   c              3   <   #    [         R                  " S5      v   g 7fNr   r   sleepr,   s    r   r   "GenTest.test_timeout.<locals>.test        ))A,   did not get expected exceptionzgen.sleep(1)T)r
   failr   TimeoutErrorr   	traceback
format_excr   r'   r   s     r   test_timeoutGenTest.test_timeout   sn    	#		 
	
	BJII67  "" 	B MM.)*>*>*@A	Bs   2 9A.-A.c                 @    [        SS9S 5       nU" U 5        SU l        g )Nr   r   c              3   <   #    [         R                  " S5      v   g 7f)Nr+   r   r,   s    r   r   %GenTest.test_no_timeout.<locals>.test  s     ))C. r   Tr
   r   r   s     r   test_no_timeoutGenTest.test_no_timeout  s)    	!		! 
	! 	T
r/   c                     [        SS9S 5       n[        SS5         U" U 5        S S S 5        SU l        g ! , (       d  f       N= f)Ng      ?r   c              3   <   #    [         R                  " S5      v   g 7f)Ng      ?r   r,   s    r   test_long_timeoutDGenTest.test_timeout_environment_variable.<locals>.test_long_timeout  s     ))D/!r   r   0.1T)r
   r   r   )r'   r  s     r   !test_timeout_environment_variable)GenTest.test_timeout_environment_variable  sE    	#		" 
	" -u5d# 6  65s	   	5
Ac                     [        SS9S 5       n[        SS5         U R                  [        R                  5         U" U 5        S S S 5        S S S 5        SU l        g ! , (       d  f       N= f! , (       d  f       N'= f)Nr   r   c              3   <   #    [         R                  " S5      v   g 7fr   r   r,   s    r   test_short_timeoutHGenTest.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_variable,GenTest.test_no_timeout_environment_variable!  sg    	$		 
 	 -u5""6#6#67"4( 8 6  87 65s"    A.	AA.
A+	'A..
A<c                 <    [         S 5       nU" U S5        SU l        g )Nc              7   T   #    U R                  US5        [        R                  v   g 7f)Nr   )r`   r   r   )r'   argss     r   test_with_args5GenTest.test_with_method_args.<locals>.test_with_args.  s     T9-**s   &(r   Tr  )r'   r  s     r   test_with_method_argsGenTest.test_with_method_args-  s'    		 
	 	tV$r/   c                 8    [         S 5       nU" U SS9  SU l        g )Nc              ;   X   #    U R                  USS05        [        R                  v   g 7fr   )assertDictEqualr   r   )r'   kwargss     r   test_with_kwargs9GenTest.test_with_method_kwargs.<locals>.test_with_kwargs7  s$       &&)9:**s   (*r   r  Tr  )r'   r  s     r   test_with_method_kwargsGenTest.test_with_method_kwargs6  s'    		 
	 	F+r/   c                 ,    [         S 5       nU" U 5        g )Nc                    #    SU l         g 7fr   r   r,   s    r   r   +GenTest.test_native_coroutine.<locals>.test@  s      DMs   	)r
   r   s     r   test_native_coroutineGenTest.test_native_coroutine?  s    		! 
	! 	T
r/   c                     [        SS9S 5       n U" U 5        U R                  S5        g ! [        R                   a
    SU l         g f = f)Nr+   r   c                 L   #    [         R                  " S5      I S h  vN   g  N7fr   r   r,   s    r   r   3GenTest.test_native_coroutine_timeout.<locals>.testH  s     ))A,s   $"$r   T)r
   r   r   r   r   r   s     r   test_native_coroutine_timeout%GenTest.test_native_coroutine_timeoutF  sN    	#		 
		!JII67"" 	! DM	!s   + A	A	r   )r1   r2   r3   r4   rQ   r;   r
   r   r   r   r  r	  r  r  r  r$  r)  r5   rK   rL   s   @r   r   r      sb        $	

! 
!r/   r   __main__)#tornador   r   tornado.httpserverr   tornado.locksr   tornado.testingr   r   r	   r
   tornado.webr   rC   
contextlibr<   r   r   r   r   r|   r   contextmanagerr   r   r7   rN   r   ro   r   r   r   r1   mainr0   r/   r   <module>r4     s     )  X X #   	 	  
    
) 
) B} 0- @?T(9(9 ?TD+)) +:7):): 7$g!m g!T zMMO r/   