K i )ddlmZmZddlmZddlmZddlmZm Z m Z m Z ddl m Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZej.dZGdd e ZGd d e ZGd d eZGddej8ZGddej8ZGddej8ZGdde Z e!dk(rejDyy))genioloop) HTTPServer)Event)AsyncHTTPTestCase AsyncTestCasebind_unused_portgen_test ApplicationNc# Ktjj|}|tj|< d|tj|=y|tj|<y#|tj|=w|tj|<wxYwwN)osenvironget)namevalue old_values _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/tornado/test/testing_test.py set_environrsq t$IBJJt)   4 (BJJt    4 (BJJt s3BA"(B")B  BceZdZdZdZy)AsyncTestCaseTestc|jj}|jj|dz|j|j |jj|dz|j|j |j 5|j dddd|jj|dz|jtdd5|j |j 5|j ddddddy#1swYxYw#1swYxYw#1swYyxYw)N{Gz?timeoutASYNC_TEST_TIMEOUTz0.01)io_looptime add_timeoutstopwait assertRaisesfailureExceptionr)selfr s rtest_wait_timeoutz#AsyncTestCaseTest.test_wait_timeout s||     $ :    !TYY7   t44 5 $ IIdI # $   !TYY7 -v 6 ""4#8#89       $ $     s0D13E D= E 1D:=E E  EcP|jj|jjdz|j|j d|jj|jjdz|j|j dy)ze This test makes sure that a second call to wait() clears the first timeout. g皙?rg?g?N)rr!r r"r#r&s rtest_subsequent_wait_callsz,AsyncTestCaseTest.test_subsequent_wait_calls2sv   !2!2!4t!;TYYG #    !2!2!4s!:DIIF # N)__name__ __module__ __qualname__r'r+r,rrrs $ r,rc$eZdZfdZdZxZS)LeakTestcJt|tjyr)supertearDowngccollectr& __class__s rr5zLeakTest.tearDownAs  r,ctfd}|jj||jj|j|j y)NcvK jd{y7#tj$rYywxYwwr)r#asyncioCancelledError)eventsrcallbackz0LeakTest.test_leaked_coroutine..callbackMs2 jjl""))  s(9  9 6969)rr add_callbackr"r#)r&r?r>s @rtest_leaked_coroutinezLeakTest.test_leaked_coroutineFsD   !!(+ !!$)), r,)r-r.r/r5rA __classcell__r9s@rr2r2@s  r,r2c:eZdZfdZdZdZdZfdZxZS)AsyncHTTPTestCaseTestct|t\}}t}t |fi|j }|j |||_||_yr) r4setUpr r rget_httpserver_options add_socket second_port second_server)r&sockportappserverr9s rrGzAsyncHTTPTestCaseTest.setUpYsU  %' dmCA4#>#>#@A$#r,ctSrr r*s rget_appzAsyncHTTPTestCaseTest.get_appcs }r,cd}|j|}|j|jj|j |y)Nz/path)fetch assertEqualrequesturlget_urlr&pathresponses rtest_fetch_segmentz(AsyncHTTPTestCaseTest.test_fetch_segmentfs:::d# ))--t||D/ABr,cd|jz}|j|}|j|jj|y)Nzhttp://127.0.0.1:%d/path)rJrSrTrUrVrXs rtest_fetch_full_http_urlz.AsyncHTTPTestCaseTest.test_fetch_full_http_urlks>*D,<,<<::d# ))--t4r,cV|jjt| yr)rKr"r4r5r8s rr5zAsyncHTTPTestCaseTest.tearDownss  ! r,) r-r.r/rGrQr[r]r5rBrCs@rrErEXs"$C 5r,rEceZdZdZej ejdk(dej ejdk\ddZ dZ dZ y ) !AsyncTestCaseReturnAssertionsTestc Gddt}|d}tj}|j||j t |j d|jd|j ddy)NceZdZdZy)JAsyncTestCaseReturnAssertionsTest.test_undecorated_generator..Testc3Kdywrr0r*s rtest_genzSAsyncTestCaseReturnAssertionsTest.test_undecorated_generator..Test.test_gens N)r-r.r/rer0r,rTestrc~s r,rgrershould be decoratedrrunittest TestResultrunrTlenerrorsassertInr&rgtestresults rtest_undecorated_generatorz.Testc Kywrr0r*s r test_corozTAsyncTestCaseReturnAssertionsTest.test_undecorated_coroutine..Test.test_coros sN)r-r.r/r{r0r,rrgrys r,rgr{ignorerrhr) rrjrkwarningscatch_warnings simplefilterrlrTrmrnrorps rtest_undecorated_coroutinez.Testzdon't run thisc3Kdywrr0r*s rrez]AsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skip..Test.test_gens rfN)r-r.r/rjskiprer0r,rrgrs X]]+ , - r,rgrerr)rrjrkrlrTrmrnskippedrps r$test_undecorated_generator_with_skipzFAsyncTestCaseReturnAssertionsTest.test_undecorated_generator_with_skipsf =  J$$&  V]]+Q/ V^^,a0r,c Gddt}|d}tj}|j||j t |j d|jd|j ddy)NceZdZdZy)AAsyncTestCaseReturnAssertionsTest.test_other_return..Testcy)N*r0r*s rtest_other_returnzSAsyncTestCaseReturnAssertionsTest.test_other_return..Test.test_other_returnsr,N)r-r.r/rr0r,rrgrs r,rgrrz%Return value from test method ignoredrrirps rrz3AsyncTestCaseReturnAssertionsTest.test_other_returnsl = '($$&  V]]+Q/ =v}}Q?OPQ?RSr,N) r-r.r/rsrjskipIfplatformpython_implementationsys version_inforrrr0r,rr`r`xsr BX__&&&(F25X__ G#7  B  B 1 Tr,r`ceZdZdZy)SetUpTearDownTestcgtj}Gfddtj}Gfddt|}|dj |gd}|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"eZdZfdZfdZy)>SetUpTearDownTest.test_set_up_tear_down..SetUpTearDownc(jdy)NrGappendr&eventss rrGzDSetUpTearDownTest.test_set_up_tear_down..SetUpTearDown.setUps g&r,c(jdy)Nr5rrs rr5zGSetUpTearDownTest.test_set_up_tear_down..SetUpTearDown.tearDowns j)r,N)r-r.r/rGr5rsr SetUpTearDownrs  ' *r,rceZdZfdZy).InheritBothc(jdyNrqrrs rrqzASetUpTearDownTest.test_set_up_tear_down..InheritBoth.tests f%r,N)r-r.r/rqrsr InheritBothrs &r,rrq)rGrqr5N)rjrkTestCaserrlrT)r&rrrrexpectedrs @rtest_set_up_tear_downz'SetUpTearDownTest.test_set_up_tear_downsb$$& *H-- * &- & F'0 6*r,N)r-r.r/rr0r,rrrs+r,rceZdZdZy)"AsyncHTTPTestCaseSetUpTearDownTestctj}Gddt}|d}|j||j t |d|j t |dy)NceZdZdZdZy)eAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server..SetUpTearDownctSrr r*s rrQzmAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server..SetUpTearDown.get_apps "}$r,cp|jt|d|jt|dy)N_app http_server) assertTruehasattrr*s rrqzjAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_server..SetUpTearDown.tests(f 56m <=r,N)r-r.r/rQrqr0r,rrrs  % >r,rrqrr)rjrkrrl assertFalser)r&rrrrqs r+test_tear_down_releases_app_and_http_serverzNAsyncHTTPTestCaseSetUpTearDownTest.test_tear_down_releases_app_and_http_servers_$$& >- >V$  v./ }56r,N)r-r.r/rr0r,rrrs7r,rcxeZdZfdZfdZedZedZdZdZ dZ dZ d Z d Z d Zd ZxZS) GenTestc0t|d|_y)NF)r4rGfinishedr8s rrGz GenTest.setUps   r,cX|j|jt| yr)rrr4r5r8s rr5zGenTest.tearDowns  & r,cd|_yNTrr*s r test_synczGenTest.test_syncs  r,c#>Ktjd|_ywr)rmomentrr*s r test_asynczGenTest.test_asyncsjj sctdd} |||jdd|_y#tj$r.|j dt j Yd|_ywxYw)Nr)rc3:KtjdywNrrsleepr*s rrqz"GenTest.test_timeout..test))A, did not get expected exceptionz gen.sleep(1)T)r failr TimeoutErrorro traceback format_excrr&rqs r test_timeoutzGenTest.test_timeoutsu #      B J II6 7  "" B MM.)*>*>*@ A  Bs57A65A6cFtdd}||d|_y)Nrrc3:Ktjdyw)Nr)rr*s rrqz%GenTest.test_no_timeout..tests))C. rTr rrs rtest_no_timeoutzGenTest.test_no_timeout s) !  !  ! T  r,ctdd}tdd5||dddd|_y#1swYd|_yxYw)Ng?rc3:Ktjdyw)Ng?rr*s rtest_long_timeoutzDGenTest.test_timeout_environment_variable..test_long_timeouts))D/ !rr0.1T)r rr)r&rs r!test_timeout_environment_variablez)GenTest.test_timeout_environment_variablesP #  "  "-u 5 $ d # $  $ s 8Actdd}tdd5|jtj5||ddddddd|_y#1swYxYw#1swYd|_yxYw)Nrrc3:Ktjdywrrr*s rtest_short_timeoutzHGenTest.test_no_timeout_environment_variable..test_short_timeout"rrrrT)r rr$rrr)r&rs r$test_no_timeout_environment_variablez,GenTest.test_no_timeout_environment_variable!sy $    -u 5 )""6#6#67 )"4( ) )  ) ) ) s" A, A A, A) %A,,A<c<td}||dd|_y)Nc7TK|j|dtjyw)Nrq)rTrr)r&argss rtest_with_argsz5GenTest.test_with_method_args..test_with_args.s   T9 -** s&(rqTr)r&rs rtest_with_method_argszGenTest.test_with_method_args-s'     tV$ r,c>td}||dd|_y)Nc;XK|j|dditjywr)assertDictEqualrr)r&kwargss rtest_with_kwargsz9GenTest.test_with_method_kwargs..test_with_kwargs7s%  &&)9 :** s(*rqrTr)r&rs rtest_with_method_kwargszGenTest.test_with_method_kwargs6s'     F+ r,c,td}||y)NcKd|_ywrrr*s rrqz+GenTest.test_native_coroutine..test@s  DMs )r rs rtest_native_coroutinezGenTest.test_native_coroutine?s  !  ! T r,ctdd} |||jdy#tj$r d|_YywxYw)Nr)rcJKtjdd{y7wrrr*s rrqz3GenTest.test_native_coroutine_timeout..testHs))A,  s #!#rT)r rrrrrs rtest_native_coroutine_timeoutz%GenTest.test_native_coroutine_timeoutFsN #     ! J II6 7"" ! DM !s.A  A )r-r.r/rGr5r rrrrrrrrrrrBrCs@rrrs]$   !r,r__main__)#tornadorrtornado.httpserverr tornado.locksrtornado.testingrrr r tornado.webr r< contextlibr6rrrrrjr}contextmanagerrrr2rErr`rrrr-mainr0r,rrs)XX#    ) ) B}0-@?T(9(9?TD+))+:7):):7$g!mg!T zHMMOr,