
    ^hs.                     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Jr  S SKr	S SK	J
r
  S SKJr  S SKJrJrJr  S SKJrJrJrJr  S SKJr  S SKJrJr   " S	 S
\5      r " S S\R6                  5      r " S S\R6                  5      r " S S\R6                  5      r " S S\5      rg)    N)ThreadPoolExecutor)gen)IOLoop)AsyncIOLoopto_asyncio_futureAddThreadSelectorEventLoop)AsyncTestCasegen_testsetup_with_context_managerAsyncHTTPTestCase)ignore_deprecation)ApplicationRequestHandlerc                   V    \ rS rSr\S 5       rS r\S 5       r\S 5       r	S r
S rSrg	)
AsyncIOLoopTest'   c                 .    U R                   R                  $ N)io_loopasyncio_loopselfs    S/home/james-whalen/.local/lib/python3.13/site-packages/tornado/test/asyncio_test.pyr   AsyncIOLoopTest.asyncio_loop(   s    ||(((    c                 r   ^  U 4S jnT R                   R                  U" 5       5        T R                  5         g )Nc                  j   >#    [         R                  " 5       R                  T R                  5        g 7fr   )asyncioget_event_loop	call_soonstopr   s   r   add_callback;AsyncIOLoopTest.test_asyncio_callback.<locals>.add_callback.   s!     ""$..tyy9s   03)r   run_until_completewait)r   r"   s   ` r   test_asyncio_callback%AsyncIOLoopTest.test_asyncio_callback,   s)    	: 	,,\^<		r   c              #      #    [         R                  " [         R                  " 5       R                  S S 5      5      v nU R	                  US5        g 7f)Nc                      gN*    r,   r   r   <lambda>5AsyncIOLoopTest.test_asyncio_future.<locals>.<lambda>9   s    2r   r+   )r   ensure_futurer   run_in_executorassertEqual)r   xs     r   test_asyncio_future#AsyncIOLoopTest.test_asyncio_future4   sG      ''""$44T:F
 
 	Bs   AAc              #   n   #    [         R                  S 5       nU" 5       v nU R                  US5        g 7f)Nc               3   r   #    [         R                  " 5       n U R                  S S 5       S h  vN nU$  N7f)Nc                      gr*   r,   r,   r   r   r-   DAsyncIOLoopTest.test_asyncio_yield_from.<locals>.f.<locals>.<lambda>B   s    Br   )r   r   r0   )
event_loopr2   s     r   f2AsyncIOLoopTest.test_asyncio_yield_from.<locals>.f?   s3      //1J%55dJGGAH Hs   ,757r+   )r   	coroutiner1   )r   r:   results      r   test_asyncio_yield_from'AsyncIOLoopTest.test_asyncio_yield_from=   s6     		 
	
 s$s   35c                 z  ^^ [         R                  S 5       mU4S jmU4S jnU4S jnU R                  U R                  R	                  T5      S5        U R                  U R                  R	                  U5      S5        U R                  U R                  R	                  U5      S5        U R                  U R
                  R                  T" 5       5      S5        U R                  U R
                  R                  U" 5       5      S5        U R                  U R
                  R                  U" 5       5      S5        g )Nc               3   Z   #    [         R                  v   [         R                  " S5      e7fr*   )r   momentReturnr,   r   r   tornado_coroutine?AsyncIOLoopTest.test_asyncio_adapter.<locals>.tornado_coroutineM   s     ****R. s   )+c                  .   >#    T " 5       I S h  vN $  N7fr   r,   rD   s   r    native_coroutine_without_adapterNAsyncIOLoopTest.test_asyncio_adapter.<locals>.native_coroutine_without_adapterR   s     *,,,,s   c                  @   >#    [        T " 5       5      I S h  vN $  N7fr   r   rG   s   r   native_coroutine_with_adapterKAsyncIOLoopTest.test_asyncio_adapter.<locals>.native_coroutine_with_adapterU   s     *+<+>????   c                  @   >#    [        T " 5       5      I S h  vN $  N7fr   rK   )rH   s   r   native_coroutine_with_adapter2LAsyncIOLoopTest.test_asyncio_adapter.<locals>.native_coroutine_with_adapter2Y   s     *+K+MNNNNrN   r+   )r   r<   r1   r   run_syncr   r$   )r   rL   rP   rH   rD   s      @@r   test_asyncio_adapter$AsyncIOLoopTest.test_asyncio_adapterH   s   
 
	! 
	!	-	@	O 	../OPRTU../LMrR../MNPRS 	001Q1ST	
 	001N1PQ	
 	001O1QR	
r   c                     [        [        R                  " 5       5      nUR                  5         UR                  5         g r   )r   r   r   closer   loops     r    test_add_thread_close_idempotent0AsyncIOLoopTest.test_add_thread_close_idempotentp   s'    )'*@*@*BC



r   r,   N)__name__
__module____qualname____firstlineno__propertyr   r&   r
   r3   r>   rS   rY   __static_attributes__r,   r   r   r   r   '   sL    ) )     % %&
Pr   r   c                   ,    \ rS rSrS rS rS rS rSrg)LeakTestv   c                 2    [        SS9R                  5         g )NFmake_current)r   rV   r   s    r   setUpLeakTest.setUpw   s    '--/r   c                      [         R                  " 5       R                  5       nUR                  5         g ! [         a     g f = fr   )r   get_event_loop_policyr   rV   	ExceptionrW   s     r   tearDownLeakTest.tearDown{   s=    	002AACD
 JJL	  		s   #6 
AAc                    [        [        R                  5      n[        S5       HV  n[        R
                  " 5          [        R                  " S[        5        [        5       nUR                  5         S S S 5        MX     [        [        R                  5      U-
  nU R                  US5        g ! , (       d  f       M  = f)N
   ignorer   )lenr   _ioloop_for_asynciorangewarningscatch_warningssimplefilterDeprecationWarningr   rV   r1   r   
orig_countirX   	new_counts        r   test_ioloop_close_leakLeakTest.test_ioloop_close_leak   s    334
rA((*%%h0BC"}

 +*  223j@	A& +*s   6B..
B=	c                    [        [        R                  5      n[        S5       Hr  n[        R
                  " 5       nUR                  [        R                  5        UR                  UR                  5        UR                  5         UR                  5         Mt     [        [        R                  5      U-
  nU R                  US5        g )Nro      )rq   r   rr   rs   r   new_event_loopr    currentr!   run_foreverrV   r1   rx   s        r   test_asyncio_close_leak LeakTest.test_asyncio_close_leak   s    334
rA))+DNN6>>*NN499%JJL  223j@	 	A&r   r,   N)	r[   r\   r]   r^   rg   rl   r|   r   r`   r,   r   r   rb   rb   v   s    0	''r   rb   c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
SelectorThreadLeakTest   c                     [         R                  " U R                  5       5        [        R                  " 5       U l        g r   )r   rundummy_tornado_coroutine	threadingactive_countorig_thread_countr   s    r   rg   SelectorThreadLeakTest.setUp   s*     	D0023!*!7!7!9r   c                    [         R                   " 5       S-   n[         R                   " 5       U:  ai  [        [        R                  " 5       5      n[	        U5      U R
                  ::  a  O1[         R                  " S5        [         R                   " 5       U:  a  Mi  U R                  [	        W5      U R
                  U5        g )Nr   g?)timelistr   	enumeraterq   r   sleepassertLessEqual)r   deadlinethreadss      r   assert_no_thread_leak,SelectorThreadLeakTest.assert_no_thread_leak   s     99;?iikH$9..01G7|t555JJsO	 iikH$
 	S\4+A+A7Kr   c                 6   #    [         R                  " 5         g 7fr   )r   r   r   s    r   r   .SelectorThreadLeakTest.dummy_tornado_coroutine   s     s   c                     [        S5       H'  n[        R                  " U R                  5       5        M)     U R	                  5         g Nro   )rs   r   r   r   r   )r   rz   s     r   test_asyncio_run'SelectorThreadLeakTest.test_asyncio_run   s3    rAKK4467  	""$r   c                    [        S5       Hf  n[        R                  " 5       nUR                  U R	                  5       5        UR                  UR                  5       5        UR                  5         Mh     U R                  5         g r   )rs   r   r   r$   r   shutdown_asyncgensrV   r   r   rz   rX   s      r   test_asyncio_manual*SelectorThreadLeakTest.test_asyncio_manual   sc    rA))+D##D$@$@$BC##D$;$;$=>JJL  	""$r   c                     [        S5       H7  n[        SS9nUR                  U R                  5        UR	                  5         M9     U R                  5         g )Nro   Fre   )rs   r   rR   r   rV   r   r   s      r   test_tornado#SelectorThreadLeakTest.test_tornado   sE    rA u-DMM$667JJL  	""$r   )r   N)r[   r\   r]   r^   rg   r   r   r   r   r   r`   r,   r   r   r   r      s!    :L%%%r   r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	AnyThreadEventLoopPolicyTest   c                     [        U [        5       5        [        R                  R                  R
                  U l        [        R                  " 5       U l        [        S5      U l	        g )Nr   )
r   r   tornadoplatformr   AnyThreadEventLoopPolicyrj   orig_policyr   executorr   s    r   rg   "AnyThreadEventLoopPolicyTest.setUp   sN    "4);)=> $$== 	% #88:*1-r   c                 x    [         R                  " U R                  5        U R                  R	                  5         g r   )r   set_event_loop_policyr   r   shutdownr   s    r   rl   %AnyThreadEventLoopPolicyTest.tearDown   s&    %%d&6&67 r   c                 ^    S nU R                   R                  U5      nUR                  5       $ )Nc                  P    [         R                  " 5       n U R                  5         U $ )zGet the event loop. Close it if one is returned.

Returns the (closed) event loop. This is a silly thing
to do and leaves the thread in a broken state, but it's
enough for this test. Closing the loop avoids resource
leak warnings.
r   r   rV   )rX   s    r   get_and_close_event_loopWAnyThreadEventLoopPolicyTest.get_event_loop_on_thread.<locals>.get_and_close_event_loop   s      ))+DJJLKr   )r   submitr=   )r   r   futures      r   get_event_loop_on_thread5AnyThreadEventLoopPolicyTest.get_event_loop_on_thread   s*    
	 %%&>?}}r   c                 l   [         R                  " 5          [         R                  " S[        5        U R	                  [
        U R                  R                  [        R                  5      R                  5        [        R                  " U R                  5       5        U R                  U R                  R                  [        R                  5      R                  5       [        R                  5        U R                  R                  S 5      R                  5         S S S 5        g ! , (       d  f       g = f)Nrp   c                  H    [         R                  " 5       R                  5       $ r   r   r,   r   r   r-   DAnyThreadEventLoopPolicyTest.test_asyncio_accessor.<locals>.<lambda>       )?)?)A)G)G)Ir   )rt   ru   rv   rw   assertRaisesRuntimeErrorr   r   r   r   r=   r   r   assertIsInstanceAbstractEventLoopr   s    r   test_asyncio_accessor2AnyThreadEventLoopPolicyTest.test_asyncio_accessor   s    $$&!!(,>? dmm2273I3IJQQ ))$*G*G*IJ!!$$W%;%;<CCE)) MM  !IJQQS '&&s   DD%%
D3c                    [         R                  " 5          [         R                  " S[        5        U R	                  U R
                  R                  [        R                  5      R                  5       [        5        U R
                  R                  S 5      R                  5         [        R                  " U R                  5       5        U R	                  U R
                  R                  [        R                  5      R                  5       [        5        U R
                  R                  S 5      R                  5         S S S 5        g ! , (       d  f       g = f)Nrp   c                  H    [         R                  " 5       R                  5       $ r   r   r,   r   r   r-   DAnyThreadEventLoopPolicyTest.test_tornado_accessor.<locals>.<lambda>
  r   r   c                  H    [         R                  " 5       R                  5       $ r   r   r,   r   r   r-   r     r   r   )rt   ru   rv   rw   r   r   r   r   r   r=   r   r   r   r   s    r   test_tornado_accessor2AnyThreadEventLoopPolicyTest.test_tornado_accessor  s     $$&!!(,>?!!$--"6"6v~~"F"M"M"OQWX MM  !IJQQS))$*G*G*IJ!!$--"6"6v~~"F"M"M"OQWXMM  !IJQQS '&&s   D*E		
E)r   r   r   N)
r[   r\   r]   r^   rg   rl   r   r   r   r`   r,   r   r   r   r      s    .! T$Tr   r   c                   t    \ rS rSrSrSr\R                  " SSS9r\R                  \5        S\
4S jrS	 rS
rg)SelectorThreadContextvarsTesti  foo/tornado_test_ctxdefault)r   returnc                 p   ^ U R                   m " U4S jS[        5      n[        U R                  U4/5      $ )Nc                   "   > \ rS rSrU 4S jrSrg)6SelectorThreadContextvarsTest.get_app.<locals>.Handleri  c                 L   >#    U R                  TR                  5       5        g 7fr   )writeget)r   r   s    r   r   :SelectorThreadContextvarsTest.get_app.<locals>.Handler.get  s      

+//12s   !$r,   N)r[   r\   r]   r^   r   r`   )r   s   r   Handlerr     s    
3 
3r   r   )r   r   r   test_endpoint)r   r   r   s     @r   get_app%SelectorThreadContextvarsTest.get_app  s6    00	3n 	3 T//9:;;r   c                     U R                  U R                  U R                  U R                  5      R                  R                  5       5        g r   )r1   	ctx_valuefetchr   bodydecoder   s    r   test_context_vars/SelectorThreadContextvarsTest.test_context_vars)  s4    D4F4F)G)L)L)S)S)UVr   r,   N)r[   r\   r]   r^   r   r   contextvars
ContextVarr   setr   r   r   r`   r,   r   r   r   r     s@    IM"--.@)T#< <$Wr   r   ) r   r   r   r   unittestrt   concurrent.futuresr   tornado.platform.asyncior   r   tornado.ioloopr   r   r   r   tornado.testingr	   r
   r   r   tornado.test.utilr   tornado.webr   r   r   TestCaserb   r   r   r   r,   r   r   <module>r      s          1   ! 
  1 3Lm L^%'x   %'P0%X.. 0%f=T8#4#4 =T@W$5 Wr   