
    g)                        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j8                        Z G d dej8                        Z G d dej8                        Z G d de	      Z e!dk(  r ejD                          yy)    )genioloop)
HTTPServer)Event)AsyncHTTPTestCaseAsyncTestCasebind_unused_portgen_testApplicationNc              #      K   t         j                  j                  |       }|t         j                  | <   	 d  |t         j                  | = y |t         j                  | <   y # |t         j                  | = w |t         j                  | <   w xY wwN)osenvironget)namevalue	old_values      N/var/www/openai/venv/lib/python3.12/site-packages/tornado/test/testing_test.pyset_environr      sq     

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

4 (BJJt 

4 (BJJts   3BA" (B")BBc                       e Zd Zd Zd Zy)AsyncTestCaseTestc                    | j                   j                  }| j                   j                   |       dz   | j                         | j	                          | j                   j                   |       dz   | j                         | j                  | j                        5  | j	                  d       d d d        | j                   j                   |       dz   | j                         t        dd      5  | j                  | j                        5  | j	                          d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)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    ||   	  $		:		 	  !TYY7t445IIdI# 6 	  !TYY7-v6""4#8#89		 : 76 65 :9 76s0   D13E	D= E	1D:=E	E		Ec                 P   | j                   j                  | j                   j                         dz   | j                         | j	                  d       | j                   j                  | j                   j                         dz   | j                         | j	                  d       y)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   sv     	  !2!2!4t!;TYYG		#	 	  !2!2!4s!:DIIF		#	    N)__name__
__module____qualname__r'   r+    r,   r   r   r      s    $r,   r   c                   $     e Zd Z fdZd Z xZS )LeakTestc                 J    t         |           t        j                          y r   )supertearDowngccollectr&   	__class__s    r   r5   zLeakTest.tearDownA   s    


r,   c                     t               fd}| j                  j                  |       | j                  j                  | j                         | j	                          y )Nc                  v   K   	  j                          d {    y 7 # t        j                  $ r Y y w xY wwr   )r#   asyncioCancelledError)events   r   callbackz0LeakTest.test_leaked_coroutine.<locals>.callbackM   s2     jjl"")) s(   9    9  6969)r   r   add_callbackr"   r#   )r&   r?   r>   s     @r   test_leaked_coroutinezLeakTest.test_leaked_coroutineF   sD    
 	 	!!(+!!$)),		r,   )r-   r.   r/   r5   rA   __classcell__r9   s   @r   r2   r2   @   s    
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 | j                         }|j                  |       || _        || _        y 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   sU    %'
dmCA4#>#>#@A$#r,   c                     t               S r   r   r*   s    r   get_appzAsyncHTTPTestCaseTest.get_appc   s
    }r,   c                     d}| j                  |      }| j                  |j                  j                  | j	                  |             y )Nz/path)fetchassertEqualrequesturlget_urlr&   pathresponses      r   test_fetch_segmentz(AsyncHTTPTestCaseTest.test_fetch_segmentf   s:    ::d#))--t||D/ABr,   c                     d| j                   z  }| j                  |      }| j                  |j                  j                  |       y )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   s>     *D,<,<<::d#))--t4r,   c                 V    | j                   j                          t        |           y r   )rK   r"   r4   r5   r8   s    r   r5   zAsyncHTTPTestCaseTest.tearDowns   s     !r,   )	r-   r.   r/   rG   rQ   r[   r]   r5   rB   rC   s   @r   rE   rE   X   s"    $C
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y	)
!AsyncTestCaseReturnAssertionsTestc                 
    G d dt               } |d      }t        j                         }|j                  |       | j	                  t        |j                        d       | j                  d|j                  d   d          y )Nc                       e Zd Zd Zy)JAsyncTestCaseReturnAssertionsTest.test_undecorated_generator.<locals>.Testc              3      K   d  y wr   r0   r*   s    r   test_genzSAsyncTestCaseReturnAssertionsTest.test_undecorated_generator.<locals>.Test.test_gen   s	        N)r-   r.   r/   re   r0   r,   r   Testrc   ~   s    r,   rg   re   r   should be decoratedr   r   unittest
TestResultrunrT   lenerrorsassertInr&   rg   testresults       r   test_undecorated_generatorz<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                     G d dt               } |d      }t        j                         }t        j                         5  t        j
                  d       |j                  |       d d d        | j                  t        |j                        d       | j                  d|j                  d   d          y # 1 sw Y   QxY w)Nc                       e Zd Zd Zy)JAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine.<locals>.Testc                    K   y wr   r0   r*   s    r   	test_corozTAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine.<locals>.Test.test_coro   s	     s   N)r-   r.   r/   r{   r0   r,   r   rg   ry      s    r,   rg   r{   ignorer   rh   r   )r   rj   rk   warningscatch_warningssimplefilterrl   rT   rm   rn   ro   rp   s       r   test_undecorated_coroutinez<AsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine   s    	= 	 K $$& $$&!!(+HHV ' 	V]]+Q/+V]]1-=a-@A '&s    'B77C c                     G d dt               } |d      }t        j                         }|j                  |       | j	                  t        |j                        d       | j	                  t        |j                        d       y )Nc                   <    e Zd Z ej                  d      d        Zy)TAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip.<locals>.Testzdon't run thisc              3      K   d  y wr   r0   r*   s    r   re   z]AsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip.<locals>.Test.test_gen   s	     rf   N)r-   r.   r/   rj   skipre   r0   r,   r   rg   r      s     X]]+, -r,   rg   re   r   r   )r   rj   rk   rl   rT   rm   rn   skippedrp   s       r   $test_undecorated_generator_with_skipzFAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip   sf    	= 	
 J$$&V]]+Q/V^^,a0r,   c                 
    G d dt               } |d      }t        j                         }|j                  |       | j	                  t        |j                        d       | j                  d|j                  d   d          y )Nc                       e Zd Zd Zy)AAsyncTestCaseReturnAssertionsTest.test_other_return.<locals>.Testc                      y)N*   r0   r*   s    r   test_other_returnzSAsyncTestCaseReturnAssertionsTest.test_other_return.<locals>.Test.test_other_return   s    r,   N)r-   r.   r/   r   r0   r,   r   rg   r      s    r,   rg   r   r   z%Return value from test method ignoredr   ri   rp   s       r   r   z3AsyncTestCaseReturnAssertionsTest.test_other_return   sl    	= 	 '($$&V]]+Q/=v}}Q?OPQ?RSr,   N)r-   r.   r/   rs   rj   skipIfplatformpython_implementationsysversion_infor   r   r   r0   r,   r   r`   r`   x   sr    
	B X__&&&(F25 X__ 	G#7	B	B 
1	Tr,   r`   c                       e Zd Zd Zy)SetUpTearDownTestc                     g t        j                         } G fddt         j                        } G fddt        |      } |d      j	                  |       g d}| j                  |       y)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y)>SetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDownc                 (    j                  d       y )NrG   appendr&   eventss    r   rG   zDSetUpTearDownTest.test_set_up_tear_down.<locals>.SetUpTearDown.setUp   s    g&r,   c                 (    j                  d       y )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      s    '*r,   r   c                       e Zd Z fdZy)<SetUpTearDownTest.test_set_up_tear_down.<locals>.InheritBothc                 (    j                  d       y Nrq   r   r   s    r   rq   zASetUpTearDownTest.test_set_up_tear_down.<locals>.InheritBoth.test   s    f%r,   N)r-   r.   r/   rq   r   s   r   InheritBothr      s    &r,   r   rq   )rG   rq   r5   N)rj   rk   TestCaser   rl   rT   )r&   rr   r   r   expectedr   s        @r   test_set_up_tear_downz'SetUpTearDownTest.test_set_up_tear_down   sb     $$&	*H-- 	*	&- 	& 	F'06*r,   N)r-   r.   r/   r   r0   r,   r   r   r      s    +r,   r   c                       e Zd Zd Zy)"AsyncHTTPTestCaseSetUpTearDownTestc                     t        j                         } G d dt              } |d      }|j                  |       | j	                  t        |d             | j	                  t        |d             y )Nc                       e Zd Zd Zd Zy)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                 p    | j                  t        | d             | j                  t        | d             y )N_apphttp_server)
assertTruehasattrr*   s    r   rq   zjAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server.<locals>.SetUpTearDown.test   s(    f 56m <=r,   N)r-   r.   r/   rQ   rq   r0   r,   r   r   r      s    %>r,   r   rq   r   r   )rj   rk   r   rl   assertFalser   )r&   rr   r   rq   s       r   +test_tear_down_releases_app_and_http_serverzNAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server   s_    $$&	>- 	> V$v./}56r,   N)r-   r.   r/   r   r0   r,   r   r   r      s    7r,   r   c                   x     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                 0    t         |           d| _        y )NF)r4   rG   finishedr8   s    r   rG   zGenTest.setUp   s    r,   c                 X    | j                  | j                         t        |           y r   )r   r   r4   r5   r8   s    r   r5   zGenTest.tearDown   s    &r,   c                     d| _         y NTr   r*   s    r   	test_synczGenTest.test_sync   s	    r,   c              #   >   K   t         j                   d| _        y wr   )r   momentr   r*   s    r   
test_asynczGenTest.test_async   s     jjs   c                     t        d      d        }	  ||        | j                  d       d| _        y # t        j                  $ r. | j	                  dt        j                                Y d| _        y w xY w)Nr)   r   c              3   :   K   t        j                  d       y wNr   r   sleepr*   s    r   rq   z"GenTest.test_timeout.<locals>.test        ))A,   did not get expected exceptionzgen.sleep(1)T)r
   failr   TimeoutErrorro   	traceback
format_excr   r&   rq   s     r   test_timeoutzGenTest.test_timeout   su    	#		 
	
	BJII67  "" 	B MM.)*>*>*@A	Bs   5 7A65A6c                 F    t        d      d        } ||        d| _        y )Nr   r   c              3   :   K   t        j                  d       y w)Nr)   r   r*   s    r   rq   z%GenTest.test_no_timeout.<locals>.test  s     ))C. r   Tr
   r   r   s     r   test_no_timeoutzGenTest.test_no_timeout  s)    	!		! 
	! 	T
r,   c                     t        d      d        }t        dd      5   ||        d d d        d| _        y # 1 sw Y   d| _        y xY w)Ng      ?r   c              3   :   K   t        j                  d       y w)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  sK    	#		" 
	" -u5d# 6  6 s	   	8Ac                     t        d      d        }t        dd      5  | j                  t        j                        5   ||        d d d        d d d        d| _        y # 1 sw Y   xY w# 1 sw Y   d| _        y xY w)Nr   r   c              3   :   K   t        j                  d       y w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!  sm    	$		 
 	 -u5""6#6#67"4( 8 6  87 6 s"    A,	A A, A)	%A,,A<c                 <    t         d        } || d       d| _        y )Nc              7   T   K   | j                  |d       t        j                   y w)Nrq   )rT   r   r   )r&   argss     r   test_with_argsz5GenTest.test_with_method_args.<locals>.test_with_args.  s      T9-**s   &(rq   Tr   )r&   r   s     r   test_with_method_argszGenTest.test_with_method_args-  s'    		 
	 	tV$r,   c                 >    t         d        } || d       d| _        y )Nc              ;   X   K   | j                  |ddi       t        j                   y wr   )assertDictEqualr   r   )r&   kwargss     r   test_with_kwargsz9GenTest.test_with_method_kwargs.<locals>.test_with_kwargs7  s%       &&)9:**s   (*rq   r   Tr   )r&   r   s     r   test_with_method_kwargszGenTest.test_with_method_kwargs6  s'    		 
	 	F+r,   c                 ,    t         d        } ||        y )Nc                    K   d| _         y wr   r   r*   s    r   rq   z+GenTest.test_native_coroutine.<locals>.test@  s      DMs   	)r
   r   s     r   test_native_coroutinezGenTest.test_native_coroutine?  s    		! 
	! 	T
r,   c                     t        d      d        }	  ||        | j                  d       y # t        j                  $ r
 d| _        Y y w xY w)Nr)   r   c                 J   K   t        j                  d       d {    y 7 wr   r   r*   s    r   rq   z3GenTest.test_native_coroutine_timeout.<locals>.testH  s     ))A,s   #!#r   T)r
   r   r   r   r   r   s     r   test_native_coroutine_timeoutz%GenTest.test_native_coroutine_timeoutF  sN    	#		 
		!JII67"" 	! DM	!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]        $	

!r,   r   __main__)#tornador   r   tornado.httpserverr   tornado.locksr   tornado.testingr   r   r	   r
   tornado.webr   r<   
contextlibr6   r   r   r   r   rj   r}   contextmanagerr   r   r2   rE   r   r`   r   r   r   r-   mainr0   r,   r   <module>r      s     )  X X #   	 	  
    
) 
) B} 0- @?T(9(9 ?TD+)) +:7):): 7$g!m g!T zHMMO r,   