K ifBddlZddlmZddlZddlZddlmZmZddlm Z ddl m Z m Z Gdde Z Gdd e ZGd d e ZGd d e ZGdde ZGdde Zedk(rej(yy)N) timedelta)genlocks) TimeoutError)gen_test AsyncTestCaseceZdZfdZdZdZdZedZdZ dZ dZ ed Z ed Z ed Zed Zed ZedZxZS) ConditionTestc0t|g|_yN)supersetUphistory)self __class__s ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/tornado/test/locks_test.pyrzConditionTest.setUps   c:fd}j|y)z=Record the resolution of a Future returned by Condition.wait.cjsjjdyjjy)Ntimeout)resultrappend)_futurekeyrs rcallbackz+ConditionTest.record_done..callbacks0==? ##I. ##C(rN)add_done_callback)rrrrs``` r record_donezConditionTest.record_dones )   *rcn|jj|j|jy)zRun all queued callbacks on the IOLoop. In these tests, this method is used after calling notify() to preserve the pre-5.0 behavior in which callbacks ran synchronously. N)io_loop add_callbackstopwaitrs r loop_brieflyzConditionTest.loop_briefly(s# !!$)), rctj}|jdt||j dt||j |jdt|y)N Conditionwaiters)rr'assertInrepr assertNotInr#rcs r test_reprzConditionTest.test_repr2sO OO  k47+ DG,  ia)rc#Ktj}|jjd|j|j yw)N{Gz?)rr'r call_laternotifyr#r,s r test_notifyzConditionTest.test_notify9s5 OO  ahh/ffhsAActj}|j|jd|j|jd|j d|j |j jd|j d|j |j jd|jgd|j y)Nwait1wait2notify1notify2)r5r8r6r9) rr'rr#r2r%rr assertEqualr,s r test_notify_1zConditionTest.test_notify_1?s OO  7+ 7+    I&    I& A4<<Prcftj}tdD]"}|j|j |$|j d|j |jttd|j|j d|j |jttd|j|j d|j |jttd|jy)Nr7) rr'rangerr#r2r%r:listrrr-is r test_notify_nzConditionTest.test_notify_nKs OO q *A   QVVXq ) *    eAh6    eAh6    eAh6rcftj}tdD]"}|j|j |$|j |j |jjd|jttddgz|jy)Nr? notify_all) rr'rArr#rGr%rrr:rBrCs rtest_notify_allzConditionTest.test_notify_all\s OO q *A   QVVXq ) *   L) eAh<.8$,,Grc# Ktj}|jtd}|jj d|j tjd|j|yw)Nr0seconds{Gz?Q?) rr'r#rr r1r2rsleep assertFalserr-r#s rtest_wait_timeoutzConditionTest.test_wait_timeouths[ OO vvi-. ahh/iio *&sBBc#Ktj}|jjd|j|j t d}tjd|yw)Nr0rLrJrM) rr'r r1r2r#rrrNrPs rtest_wait_timeout_preemptedz)ConditionTest.test_wait_timeout_preemptedpsR OO  ahh/vvi-.iio sA2A4c#Ktj}|j|jd|j|jt dd|j|jd|j|jdt j d|jdg|j|jdt j d|jgd |j|jgd |j|jd|jgd |jyw) Nrr0rJr7r@r>rLrrrr@)rrr@r>) rr'rr#rrrNr:rr2r,s rtest_notify_n_with_timeoutz(ConditionTest.test_notify_n_with_timeoutzs OO  1%  $ 78!< 1% 1%iio )dll3  iio *DLL9 *DLL9    -t||r7c$jSr )r2)rr-s rz2ConditionTest.test_nested_notify..s qxxzrr@c3<K|]}|jywr done).0fs r z3ConditionTest.test_nested_notify..s6AFFH6) rr'rAasyncio ensure_futurer#rr2 assertTrueall)rrfuturesr-s @rtest_nested_notifyz ConditionTest.test_nested_notifys OO =B!HEq7((2EE  $$%9:    6g667Fs"B$*BAB$c#.Ktj}tdD]}|jt dt j |j}|jdt|jtjd|jdt|j|j|j|j|j|jyw)Ner0rJfrLr7)rr'rAr#rrcrdr:len_waitersrrNrOr^r2re)rr-rrs rtest_garbage_collectionz%ConditionTest.test_garbage_collections OO s ,A FF9T* + ,&&qvvx0 c!**o.iio C O, '    &sDD)__name__ __module__ __qualname__rrr%r.rr3r;rErHrQrSrVrXrhrn __classcell__)rs@rr r s +* Q7" H''==. : : 8 8''rr c4eZdZdZdZedZdZdZy) EventTestc,tj}|jdt|v|j dt|v|j |j dt|v|jdt|vy)Nclearset)rEventrestrrOrw)revents rr.zEventTest.test_reprsn  3u:-. #e*,-  CJ./ U+,rctj}tj|j }|j tj|j }|j tj|j }|j|j|j|j|j|jyr ) rrxrcrdr#rwrvrer^rO)refuture_0future_1future_2s r test_eventzEventTest.test_events KKM((2 ((2  ((2  (  ( )rc#\Ktj}|jt5|j t dddd|j jt d|j|j t dy#1swYWxYww)Nr0rJr7) rrx assertRaisesrr#rr add_timeoutrwrr|s rtest_event_timeoutzEventTest.test_event_timeoutsz KKM   | , 2&&401 1 2   4!8!%%@ffYq)**  2 2s*B,B  AB, B)%B,ctj}|j|j|j|j yr )rrxrwreis_setrs rtest_event_set_multiplez!EventTest.test_event_set_multiples1 KKM    #rcttj}tj|j }|j tj|j }|j |j|j|j|jyr ) rrxrcrdr#rvrwrer^)rr|f0f1s rtest_event_wait_clearzEventTest.test_event_wait_clearso KKM  " "1668 ,   " "1668 ,   "  "rN) rorprqr.rrrrrrrrtrts*- *++$ #rrtcTeZdZdZdZdZedZedZdZ edZ y) SemaphoreTestcP|jttjdy)Nvalue)r ValueErrorr Semaphorer$s rtest_negative_valuez!SemaphoreTest.test_negative_values *eooR@rcztj}|jdt||jdt||j |jdt||j dt||j |jdt|y)Nrzunlocked,value:1lockedr()rrr)r*acquirer+rsems rr.zSemaphoreTest.test_reprs}oo k49- ($s)4  hS * DI.  ic+rc^tj}tj|j }|j |j tj|j }|j|j tj|j }|j|j |j |j|j |j|j |j |j|j tj|j j |jdt|jy)Nr) rrrcrdrrer^rOreleaser:rlrm)rrrrf2s r test_acquirezSemaphoreTest.test_acquires oo  " "3;;= 1  " " "3;;= 1 #  " "3;;= 1   " #   "  --ckkm<AACD C -.rc#Ktjd}|j|j|jtd}|jj d|j tjd|jtj5|ddd|jtj|j}|j|j|j |j|jy#1swYxYww)Nr@r0rJrLg333333?)rrrrr r1rrrNrrrcrdrOr^re)rrrr`s rtest_acquire_timeoutz"SemaphoreTest.test_acquire_timeoutsooa kkmkkm++i56 ckk2iin   s// 0 M   ! !#++- 0 "  !  sB1E3E8B EE Ec#Ktjd}|j|jj d|j |jt d}tjd|yw)Nr7r0rLrJrM) rrrr r1rrrrN)rrrs rtest_acquire_timeout_preemptedz,SemaphoreTest.test_acquire_timeout_preempted's`ooa kkm ckk2++i56iio sBBcltj}|j|j|jt j |j j|jt j |j j|jt j |j j|jt j |j jyr ) rrrrercrdrr^rOrs rtest_release_unacquiredz%SemaphoreTest.test_release_unacquired2soo   --ckkm<AACD --ckkm<AACD --ckkm<AACD ..s{{}=BBDErc #Ktjd}tdDcgc]0}tj|j t d2}}tj|j }|jdt|jtjd|jdt|j|j|j|j|j|j|D]"}|j!t"|j$$ycc}ww) Nrrrjr0rJrkrLr7)rrrArcrdrrr:rlrmrrNrOr^rrerrr)rrrrgrs rrnz%SemaphoreTest.test_garbage_collection>sooA&3Z   ! !#++i.E"F G  &&s{{}5 c#,,/0iio C -. '   & ;F   lFMM : ;% s$E5EDEN) rorprqrr.rrrrrrnrrrrrsTA,/(""  F;;rrceZdZedZedZedZedZedZedZ edZ dZ y ) SemaphoreContextManagerTestc#$Ktj}|j5}|j|ddd|j t j |jjy#1swYJxYwwr )rrr assertIsNonerercrdr^)rryieldeds rtest_context_managerz0SemaphoreContextManagerTest.test_context_managerYsjooKKM! 'g   g & ' --ckkm<AACD  ' 's'BBA BB  Bc#Ktjfd}|jtjj j yw)NcK4d{}j|dddd{y7&7#1d{7swYyxYwwr )r)rrrs rr`zGSemaphoreContextManagerTest.test_context_manager_async_await..fgsI + +g!!'* + + + + + + +9A 1A 5 A 3A A A> AA )rrrercrdrr^)rr`rs` @r test_context_manager_async_awaitzSemaphoreContextManagerTest.test_context_manager_timeout_errorsooA&   s// 0  Id$;<<    ..s{{}=BBDE     s56CB5B)B5 A C)B2 .B55B>:Cc#4Ktjgtjfd}t dDcgc] }|| c}g}t dD]}|j d|zd|zg|j |ycc}ww)Nc3Kj5jd|ztjdjd|zdddy#1swYyxYww)N acquired %dr0 release %d)rrrrN)indexrrs rr`zESemaphoreContextManagerTest.test_context_manager_contended..fsW % 5}u45iio%|e34 5 5 5sA+AA A+A($A+r@rr)rrr coroutinerAextendr:)rr`rDexpected_historyrrs @@rtest_context_manager_contendedz:SemaphoreContextManagerTest.test_context_manager_contendedsoo  5  5 #1X&qt&&q KA  # #]Q%6 q8H$I J K )73 's=BBABc#K|jtj5tj5 ddddddy#1swYxYw#1swYyxYwwr )rr BadYieldErrorrrr$s rtest_yield_semz*SemaphoreContextManagerTest.test_yield_semsZ  s00 1 ))        2 A$AA A A$ A AA!A$c|jt5tj5 ddddddy#1swYxYw#1swYyxYwr )r RuntimeErrorrrr$s rtest_context_manager_misusez7SemaphoreContextManagerTest.test_context_manager_misusesN  | , "        A >A A A  AN) rorprqrrrrrrrrrrrrrrXs EE E EEEEEFF44&rrceZdZdZy)BoundedSemaphoreTestctj}|jt|j|j t j|j }|j|j|j |j|j|j |jt|jyr ) rBoundedSemaphorerrrrrcrdrOr^re)rrrs rrz,BoundedSemaphoreTest.test_release_unacquireds$$& *ckk2 &&s{{}5 '   &  *ckk2rN)rorprqrrrrrrs 3rrcdeZdZdZdZedZedZedZdZ edZ dZ y ) LockTestscxtj}t||jt|yr )rLockr*rrlocks rr.zLockTests.test_reprs$zz| T   T rctj}|jtj|j j tj|j }|j|j |j|j|j yr ) rrrercrdrr^rOr)rrrs rtest_acquire_releasezLockTests.test_acquire_releasesxzz| --dlln=BBDE&&t||~6 '   &rc#Ktj|jtjj j d}gtjfd}t|Dcgc] }|| }}|jtd|Dj||jtt|ycc}ww)Nc3~Kj5j|dddy#1swYyxYwwr )rridxrrs rr`z&LockTests.test_acquire_fifo..fs3 & $s# $ $ $s=1 =:=c3<K|]}|jywr r])r_rs rraz.LockTests.test_acquire_fifo..sAvV[[]Arb)rrrercrdrr^rrrArOanyrr:rBrNr`rDrgrrs @@rtest_acquire_fifozLockTests.test_acquire_fifoszz| --dlln=BBDE   $  $"'q*A1Q4** AAAB   eAh1 +sA?C3C.A!C3c#Ktj|jtjj j d}gfd}t|Dcgc] }|| }}j||jtt|ycc}ww)NrcK4d{j|dddd{y7&7#1d{7swYyxYwwr )rrs rr`z1LockTests.test_acquire_fifo_async_with..fsE $ $s# $ $ $ $ $ $ $r) rrrercrdrr^rArr:rBrs @@rtest_acquire_fifo_async_withz&LockTests.test_acquire_fifo_async_withszz| --dlln=BBDE  $"'q*A1Q4**   eAh1+sA,B?0B:?AB?c#xKtj}|j|jtj 5|jt dddd|jtj|jjy#1swYJxYww)Nr0rJ)r) rrrrrrrrOrcrdr^rs rrzLockTests.test_acquire_timeoutszz|    s// 0 @,,y'>,? ? @ ..t||~>CCEF  @ @sAB:B.%A B:.B73B:ctj}|jt|j|j |j |jt|jyr )rrrrrrrs rtest_multi_releasezLockTests.test_multi_releasesGzz| , 5   , 5rc#K|jtj5tj5 ddddddy#1swYxYw#1swYyxYwwr )rrrrrr$s rtest_yield_lockzLockTests.test_yield_locksY  s00 1  $        rc|jt5tj5 ddddddy#1swYxYw#1swYyxYwr )rrrrr$s rrz%LockTests.test_context_manager_misusesM  | ,         rN) rorprqr.rrrrrrrrrrrrrsh'22"22"GG6rr__main__)rcdatetimertypingunittesttornadorr tornado.genrtornado.testingrrr rtrrrrromainrrrrs $3k'Mk'\,# ,#^a;Ma;HV-Vr 3= 3 R Rj zHMMOr