L i{^ddlZddlZddlZddlZddlZddlmZddlmZddlZddlmZ ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd lmZGd d eZdZdZGdde ZGdde ZGdde ZGdde ZGdde Zedk(rej8yy)N)ABCMeta)abstractmethod)greenlet)TestCase)RUNNING_ON_MANYLINUX)PY313)PY314)RUNNING_ON_FREETHREAD_BUILD)fails_leakcheckc eZdZy) SomeErrorN__name__ __module__ __qualname__b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/greenlet/tests/test_greenlet.pyrrsrrc tjjjt#|j t j dxYwNr)r getcurrentparentswitchappendsysexc_inforseens rfmainr "sJ$$++- O CLLN1%& s ,4)AcFd}t||}|j|y)Nc|Nr)excs rcrasherzsend_exception..crasher.s rr RawGreenletr)gr$r%g1s rsend_exceptionr++s WQ 'BIIcNrceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zej"exreddZdZdZdZdZdZdZdZdZdZdZdZdZ e!d0dZ"e!dZ#dZ$e!dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+ej"exred&d'Z,d(Z-d)Z.d*Z/d+Z0d,Z1d-Z2d.Z3y/)1 TestGreenletcgfd}t|}jd|jjd|jjd|jt t dy)Ncjdtjjj jdy)Nrrrrrrlstsrfz'TestGreenlet._do_simple_test..f9s4 JJqM    ! ( ( / / 1 JJqMrr)r(rr assertEquallistrange)selfr4r)r3s @r_do_simple_testzTestGreenlet._do_simple_test6sc  N 1    1    1  d58n-rc$|jyr#)r<r;s r test_simplezTestGreenlet.test_simpleEs rct}|jt5}|jddd|j dt j y#1swY/xYwNrun)r( assertRaisesAttributeErrorrassertInstr exceptionr;r)r$s r(test_switch_no_run_raises_AttributeErrorz5TestGreenlet.test_switch_no_run_raises_AttributeErrorHsP M   ~ . # HHJ  eS/0  s AA(ct}|jt5}|jtddd|j dt jy#1swY/xYwrA)r(rCrDthrowrrErFrGrHs r'test_throw_no_run_raises_AttributeErrorz4TestGreenlet.test_throw_no_run_raises_AttributeErrorOsS M   ~ . # GGI   eS/0  s A$$A-ctd}|j||j|jt j y)Nr&)r(assertIsNotNoneassertIsrrrr;r)s rtest_parent_equals_Nonez$TestGreenlet.test_parent_equals_NoneVs5 t $ Q ahh 3 3 56rcttd}|j||j|jy)N)rB)r(rN assertIsNonerBrPs rtest_run_equals_Nonez!TestGreenlet.test_run_equals_None[s, D ! Q !%% rcgfd}t|}t|}|j|jtd|j|jtd|j|jtd|j|jd|j|jtd|j|jdy)Ncjdtjjj j ddgy)Nr)rrrrrextendr2srr4z)TestGreenlet.test_two_children..fcs9 JJqM    ! ( ( / / 1 JJ1v rrr5r6T)r(rr8lendead)r;r4r)hr3s @rtest_two_childrenzTestGreenlet.test_two_children`s  N N   S1%   S1%   S1% &   S1% &rcgfdfd}|jtj|tsdndt |}|jtj|tsdnd|j |jgd|jtj|tsdydy)Ncjdtjjj y)Nbr1r2srr4z3TestGreenlet.test_two_recursive_children..fws) JJsO    ! ( ( / / 1rcjdt}|jjdy)Nac)rr(r)r)r4r3s rr)z3TestGreenlet.test_two_recursive_children..g{s+ JJsOAA HHJ JJsOrr5r)rar_rb)r8r getrefcountr r(r)r;r)r4r3s @@rtest_two_recursive_childrenz(TestGreenlet.test_two_recursive_childrents 2  +eQC N +eQC   o. +eQCCrc gfd}tdDcgc]}tj|}}|D]}|j|D]}|j dj t t |ycc}w)NcHjjdyNT)r<r)r;successsrr4z$TestGreenlet.test_threads..fs  " NN4 r target)r: threadingThreadstartjoinr8rY)r;r4ithsthrhs` @r test_threadszTestGreenlet.test_threadss !499=ayq)== B HHJ  B GGBK  Ws3x0 >sB cg}tt}tt}|j||j|||_|j |g|j t |j|j |t g|j}|j |d|j |t g|jd}|j |d|j |t gy)Nr)r(r rrr8rCr)r;rr*g2values rtest_exceptionzTestGreenlet.test_exceptions     $ $  r" )RYY/  {+  #  {+ "  #  {+rcg}tt}|j||jtt |t|j |tgyr#)r(r rrCKeyErrorr+r8)r;rr*s rtest_send_exceptionz TestGreenlet.test_send_exceptionsB   $ (NBA z*rcg}tt}tt}|j||j||j|g~t j |j|t jg~t j |j|t jt jgyr#)r(r rr8gccollectr GreenletExit)r;rr*rvs r test_dealloczTestGreenlet.test_deallocs     $ $ r"    5 567    5 5x7L7LMNrcVd}t|}|jtj}ddlm}|x}t_ ~|t_|j }|jd||jd||jd|y#|t_wxYw)Nc tjjjy#tj$rt dwxYwr#)rrrrrrrrrrBzHTestGreenlet.test_dealloc_catches_GreenletExit_throws_other..runs? *##%,,335(( *T) *s ,/A r)StringIO Exceptionignoredr)r(rrstderriorgetvaluerE)r;rBr) oldstderrrrvs r.test_dealloc_catches_GreenletExit_throws_otherz;TestGreenlet.test_dealloc_catches_GreenletExit_throws_others *    JJ &j( #"CJ OO  k1% i# k1% #CJs B B(z=Sometimes flaky (getting one GreenletExit in the second list)c2ggtjtjtjtjfd}tj|}|jj d|j g|j t ddd=tstj|j gjj d |j tjgj|jddd=dd=y#j|jddd=dd=wxYw)Nc>tt}|jj|~t j j jdtj jdty)Nr0)r(r rrr}r~setwait)r*/bg_glet_created_running_and_no_longer_ref_in_bgbg_should_be_clearfg_ref_releasedok_to_exit_bg_threadrsomerefs rr4z1TestGreenlet.test_dealloc_other_thread..fsnU#B IIdO NN2  JJL ; ? ? A   # M  " " $ % %a ( Mrrjrirr0)rlEventrmrnrr8rYr r}r~rrrro) r;r4trrrrrrs @@@@@@rtest_dealloc_other_threadz&TestGreenlet.test_dealloc_other_threadsF:C//:K7#//+&__.(0     A &  7<.f1"sE a A   QXXt ,    ! ( ( / / 2$rr)r(r assertTruegr_frame assertFalser8)r;rr)framefrom_gs` r test_framezTestGreenlet.test_frame!s} % O  +,   !23 T*rcd}tj|d}tj|d}|j|j|jd|jdy)NcBtfd}|jy)Nc.tjSr#)timesleepxsrz>TestGreenlet.test_thread_bug..runner..3sDJJqMrr')rr)s` rrunnerz,TestGreenlet.test_thread_bug..runner2s12A HHJr)g?rkargs)g333333?ri)rlrmrnro)r;rt1t2s rtest_thread_bugzTestGreenlet.test_thread_bug1sU   V& 9   V& 9        rclfd}t|jdd}j|dy)NcNj|dj|dy)Nr6r5*)r8)rar_r;s rrBz,TestGreenlet.test_switch_kwargs..run=s&   Q "   Q "rr6r5)rar_rr(rr8)r;rBrs` rtest_switch_kwargszTestGreenlet.test_switch_kwargs<s4    # #a1 # - Brcd}t|}|jddi|jd|jdddif|j|jd|jy)Nctjjj|tjjjdd||dzfS)Nrr5r0rrrrrs rrBz6TestGreenlet.test_switch_kwargs_to_parent..runEsR    ! ( ( / /! / 4    ! ( ( / /Q / 7a1f9 rrr0)r5)r0 )r(r8r)r;rBr)s rtest_switch_kwargs_to_parentz)TestGreenlet.test_switch_kwargs_to_parentDsd    #q188A;/ $a)188:6 ,rcitjtjfd}tj|}|jj d|j t j5djdddj|jdjy#1swY;xYw)Ncftdd<jjdy)Ncyr#rrrrrzITestGreenlet.test_switch_to_another_thread..run..Trr)rir(rr created_eventdata done_eventsrrBz7TestGreenlet.test_switch_to_another_thread..runS)#L1DI     OOB rrjrir)) rlrrmrnrrCrerrorrrroclear)r;rBthreadrrrs @@@rtest_switch_to_another_threadz*TestGreenlet.test_switch_to_another_threadNs!) __&  !!- 2   x~~ .  I     B   s CC"cPfd}fdt|jy)Nc td#tj}tj j |tjYyxYw)Nfun) ValueErrorrrr(rr8)rr[r;s rr4z&TestGreenlet.test_exc_state..fbsK ; '' ;<<>A%%'  3<<>:s AA#cNjtjdy)N)NNN)r8rrr>srr[z&TestGreenlet.test_exc_state..hjs   S\\^-? @rr')r;r4r[s` @rtest_exc_statezTestGreenlet.test_exc_stateas  ; A Arcd}d}d}t|}|j|ji|j|j|jd|j|jddi|j|_|j|jddi|j t |||j t ||dy)Nc6dtj_yNr)rrtestrrrr4z*TestGreenlet.test_instance_dict..fps)+H   ! &rc|`yr#__dict__)r)s rdeldictz0TestGreenlet.test_instance_dict..deldictrs rc||_yr#r)r)rws rsetdictz0TestGreenlet.test_instance_dict..setdictts AJrrr)r(r8rrrrC TypeError)r;r4rrr)s rtest_instance_dictzTestGreenlet.test_instance_dictos ,   N R(   $ fb\2ZZ  fb\2 )Wa0 )Wa4rcpgfd}t|}|j|jdgy)Nc`jttjdyrA)rhasattrrr)has_runsrfuncz;TestGreenlet.test_running_greenlet_has_no_run..funcs" NN++-u5 rFr)r;rr)rs @r test_running_greenlet_has_no_runz-TestGreenlet.test_running_greenlet_has_no_runs4      5'*rcddl}|jt|jt|jt|jtyr)copyrCrr(deepcopy)r;rs r test_deepcopyzTestGreenlet.test_deepcopys5 )TYY > )T]]KMBrc4tdtjgfd}t|}|j~|j |j d|j dj dd=ddy)Ncyr#rrrrrz;TestGreenlet.test_parent_restored_on_kill..rrc jy#tj$rcjtjj jtjjYywxYwr#)rrrrrr)hubmainresultsrworkerz9TestGreenlet.test_parent_restored_on_kill..workers_  ((  h113::; h1134  sA3B  B r&rr)r(rrrrrOr)r;rr)rrrs @@@rtest_parent_restored_on_killz)TestGreenlet.test_parent_restored_on_kills,'""$  s +    fQi& fQi&&, 1Irct}td|}|jt5|jdddy#1swYyxYw)Ncyr#rrrrrz9TestGreenlet.test_parent_return_failure..rrr&)r(rCrDr)r;r*rvs rtest_parent_return_failurez'TestGreenlet.test_parent_return_failuresA ] b 1   ~ .  IIK   s AAcGddt}|d}|jt|jty)NceZdZdZy)>TestGreenlet.test_throw_exception_not_lost..mygreenletcJ t#YnxYwtj||Sr#)rr(__getattribute__r;names rrzOTestGreenlet.test_throw_exception_not_lost..mygreenlet.__getattribute__s)#O"33D$??s Nrrrrrrr mygreenletrs @rrcyr#rrrrrz.rr)r(rCrrK)r;rr)s rtest_throw_exception_not_lostz*TestGreenlet.test_throw_exception_not_losts4 @ @ | $ )QWWik:rcgdfd}tj|}|j|jd~r|j |j t j5}djtddds0tj}|j|dk(xsd|vn%|jtjdtdjdr;|j t 5djj#dddsKtdjj$drFdjj$j#n|j'dj~ddd=d |_y#1swY0xYw#1swYxYw) Nc\tjjjyr#rrrrrzGTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash..worker    ! ( ( / / 1rct}|jj|r%|jtjyyr#)r(rrrr)r)rwait_for_cleanuprs rcreatorzHTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash..creators?F#A HHJ MM!  ##% rrjrirBcannot switch to a different thread (which happens to have exited)z Cannot switchrT)rlrmrnrowait_for_pending_cleanupsrCrrrKrrFrGrr8rr RuntimeErrorrf_localsrSexpect_greenlet_leak)r;rrrr$srrs ` @@r*_do_test_throw_to_dead_thread_doesnt_crashz7TestGreenlet._do_test_throw_to_dead_thread_doesnt_crashs 2 &   G ,   r    * * ,   x~~ . '# 1IOOI & ' CMM"A OOYY("a'    CMM"T  6!9%%w /""<0 +q ""((* + vay))22G<q ""++113   fQi00 1  1I%)!C ' '" + +s9GG G  Gc$|jyr#rr>s r&test_throw_to_dead_thread_doesnt_crashz3TestGreenlet.test_throw_to_dead_thread_doesnt_crashs 779rc&|jdyrgr r>s r+test_throw_to_dead_thread_doesnt_crash_waitz8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_waits 77=rcGddt}|}|j|jddd|_y)NceZdZdZdZdZy)7TestGreenlet.test_recursive_startup..convolutedc<tj|d|_yr)r(__init__countr>s rrz@TestGreenlet.test_recursive_startup..convoluted.__init__s$$T* rc|dk(r'|jdk(rd|_|jdtj||S)NrBrr+)rrr(rrs rrzHTestGreenlet.test_recursive_startup..convoluted.__getattribute__s85=TZZ1_!"DJKKO"33D$??rc< |jj|r#rr)r;rws rrBz;TestGreenlet.test_recursive_startup..convoluted.run sKK&&u-rN)rrrrrrBrrr convolutedrs  @  .rrrrT)r(r8rr)r;rr)s rtest_recursive_startupz#TestGreenlet.test_recursive_startups9 . . L "r* %)!rcLtjjtjjGfddt}d}fd}t j }t |g|d_djtj|}|jjj|jt j ||jdy)NceZdZfdZy);TestGreenlet.test_threaded_updatecurrent..finalizedcFjjyr#releaseacquire)r;lock1lock2s r__del__zCTestGreenlet.test_threaded_updatecurrent..finalized.__del__s  rNrrrr#r!r"sr finalizedrs rr&c\tjjjyr#rrrr deallocatorz=TestGreenlet.test_threaded_updatecurrent..deallocator%rrcjtjd=jjtjjyrr rrr)r)r!r"srfthreadz9TestGreenlet.test_threaded_updatecurrent..fthread'sF MMO    !! MMO MMO    ! MMOrrrjri)rlLockr objectrrr(bombrrmrnrr8ro) r;r&r(r+rrr)r!r"s @@@rtest_threaded_updatecurrentz(TestGreenlet.test_threaded_updatecurrents       2 ""$  % &K!  !   G ,     ,,.5 r rcgfddtgdjtdj}|j|j|dy)Nctjjj}d=tjj_ tjjj|j tjy#j tjwxYwr)rrrrr)rw initiatorrrs rrz>TestGreenlet.test_dealloc_switch_args_not_lost..workerGs'')00779Eq '224;;I  3##%,,33E: H//12 H//12s -B&&%C cyrrrrrr2zATestGreenlet.test_dealloc_switch_args_not_lost..initiatorTrrr)r(rrr8)r;rwr2rrs @@@r!test_dealloc_switch_args_not_lostz.TestGreenlet.test_dealloc_switch_args_not_lostEsk 3 f%&q  6!95   "  #rcdGddt}|tdfd}t|}|j|j y)Nc||i|yr#r)rraks r_applyz0TestGreenlet.test_tuple_subclass.._applyms !MqMrceZdZdZy)1TestGreenlet.test_tuple_subclass..mytuplecptjjtj |Sr#)rrrtuple__len__r>s rr>z9TestGreenlet.test_tuple_subclass..mytuple.__len__qs&##%,,.}}T**rN)rrrr>rrrmytupler;ps +rr?r)racftjjjyr#r)r9rkwargssr switchapplyz5TestGreenlet.test_tuple_subclass..switchapplyvs$ 8&&(//66f Er)r=dictr(r8r)r;r?rBr)r9rrAs @@@rtest_tuple_subclassz TestGreenlet.test_tuple_subclass_sL  +e +y F  $ V,rctdtfdtdi}Gdd|}Gdd|}||jt|y)NAbstractSubclassrBcyr#rr>s rrz7TestGreenlet.test_abstract_subclasses..rrc eZdZy):TestGreenlet.test_abstract_subclasses..BadSubclassNrrrr BadSubclassrI rrJceZdZdZy);TestGreenlet.test_abstract_subclasses..GoodSubclasscyr#rr>s rrBz?TestGreenlet.test_abstract_subclasses..GoodSubclass.runsrN)rrrrBrrr GoodSubclassrMs rrO)rr(rrCr)r;rFrJrOs rtest_abstract_subclassesz%TestGreenlet.test_abstract_subclasses{sT"  N N#45 68  *  +   )[1rctjsytjddkryfd}tdD] }|s yy)Nr2c tj jtj jdg fd}tj|}|j G fddt  G fddt }g}t dz}tj}|}|D]>}d} d r|jd yt} d rn>|j|@tj d r|jd yj|j||D]}j|j| y ) NFcnjtjjyr#r*r%sranother_threadzWTestGreenlet.test_implicit_parent_with_threads..attempt..another_threads! ##% rrjceZdZfdZy)TTestGreenlet.test_implicit_parent_with_threads..attempt..gc_callbackcPjjdd<y)NTrr)r;r!r"recycleds rr#z\TestGreenlet.test_implicit_parent_with_threads..attempt..gc_callback.__del__sMMOMMO"&HQKrNr$)r!r"rYsr gc_callbackrWs'rrZceZdZfdZy)PTestGreenlet.test_implicit_parent_with_threads..attempt..garbagec,||_|_yr#)cyclecallback)r;rZs rrzYTestGreenlet.test_implicit_parent_with_threads..attempt..garbage.__init__s!%DJ$/MDMrN)rrrr)rZsrgarbager\s2rr`r5rriT)rlr,r rmrnr-r:rrror(rr}r~r8r)rUrr`lrcurrentr)_lastrZr!r"rYNr;s @@@@rattemptz?TestGreenlet.test_implicit_parent_with_threads..attempts9NN$E MMONN$E MMOwH   7A GGI ' 'f '  2& 2Aac A))+G A A;FF2J "}A;  A;FF2J   T[[' 2 4  73 4rr7)r} isenabled get_thresholdr:)r;rfrcres` @r!test_implicit_parent_with_threadsz.TestGreenlet.test_implicit_parent_with_threadssO||~     q ! r6 , Zq Ay rcxddlmddlmGddt}t j |}g_fd}tdD]}||j`tr&jt j ||yjt j ||y)Nrr)rc eZdZy)TTestGreenlet.test_issue_245_reference_counting_subclass_no_threads..GreenletNrrrrGreenletrmrKrrnc jjy#$r#jjYywxYwr#)rrgletsr)rrr;sr greenlet_mainzYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads..greenlet_mains? 0 ##**, 0 !!*,/ 0s#%A  A ri) rrrr(rrcrpr:rr assertGreaterEqualr8)r;rn initial_refsrqrcrrs` @@r5test_issue_245_reference_counting_subclass_no_threadszBTestGreenlet.test_issue_245_reference_counting_subclass_no_threadss () { x0   0r -A ] # * * , - J &  # #COOH$=| L   S__X6 Erz;The manylinux images appear to hang on this test on 3.13rc2c ddlm}ddlm}ddlm Gddt  g | fd fd}t j }g}|d z}trd }t|D]5}|}|||f } |j|| j7|D]} | jd  dd=j|j|jt j |y) Nr)rm)rrkc eZdZy)STestGreenlet.test_issue_245_reference_counting_subclass_threads..MyGreenletNrrrr MyGreenletrwrKrrxcDjjyr#rrksrrqzVTestGreenlet.test_issue_245_reference_counting_subclass_threads..greenlet_mains L   & & (rc}j||j~|jjdy)Nri)rrrr)greenlet_running_eventminerxrrprq ref_cleareds r thread_mainzTTestGreenlet.test_issue_245_reference_counting_subclass_threads..thread_mainsHm,D LL  KKM " & & (   R  Lr-rRrri)rlrmrrrr(rrcr r:rrnrrrr8)r;rmrr~rsthread_ready_events thread_countrceventrrrxrrprqr}s @@@@@r2test_issue_245_reference_counting_subclass_threadsz?TestGreenlet.test_issue_245_reference_counting_subclass_threadss %#'  g  )  8z2  #b( &L|$ AGE;eX>F  & &u - LLN  . J OOB   !H &&( 4lCrcd}t|}d}t||}|jt5|jdddy#1swYyxYw)Ncy)N rrrrno_argsz\TestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error..no_args:r4rcyrrrrrleafzYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error..leaf?r4r)r(rCrr)r;rparent_never_startedrchilds r>test_falling_off_end_switches_to_unstarted_parent_raises_errorzKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error9sV  +73 D"67  y )  LLN   s A  Acd}t|}d}t||}|j}|j|dy)Nc |dfSNrrs rone_argzUTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works..one_argIs r7NrcyrrrrrrzRTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works..leafNr4r)rrr)r;rrrrrs r7test_falling_off_end_switches_to_unstarted_parent_workszDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_worksHsC  +73 D"67 *rcGddt}|}gtfd|}|jt5|jddd|j dg|jt5|jddd|j dgy#1swY^xYw#1swY)xYw)NceZdZdZy)XTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..Parentc|dk(rtyrA)rrs rrziTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..Parent.__getattribute__Xs5=#O!rNrrrrParentrWs $rrc&jdSrrrsrrzZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.._DKKOrr)r(rCrrr8)r;rrrrs @r;test_switch_to_dead_greenlet_with_unstarted_perverse_parentzHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parentVs $[ $ &x35IJ  y )  LLN  t$   y )  LLN  t$     sB,?B8,B58Ccgtfd}tfd}|j|jdg||_|j}|j ||jddgy)Nc&jdSrrrsrrzDTestGreenlet.test_switch_to_dead_greenlet_reparent..ms4;;r?rc&jdSrrrsrrzDTestGreenlet.test_switch_to_dead_greenlet_reparent..nrrrr)r(rr8rrS)r;rrrrs @r%test_switch_to_dead_greenlet_reparentz2TestGreenlet.test_switch_to_dead_greenlet_reparentksn*+BC34  t$+  &! Bx(rcdtjfd}fdt|}|jtd}|j|j |j |j |j jjd|j |j j|j |j jjjd|j|j jjy)Ncyr#rinnersrouterzHTestGreenlet.test_can_access_f_back_of_suspended_greenlet..outers GrcNjtjdyr)rrrrsrrzHTestGreenlet.test_can_access_f_back_of_suspended_greenlet..inners KK a( )rcyr#rrrrrzKTestGreenlet.test_can_access_f_back_of_suspended_greenlet..rrrr) rrr(rrNrr8f_codeco_namerrS)r;rr unrelatedrrs @@r,test_can_access_f_back_of_suspended_greenletz9TestGreenlet.test_can_access_f_back_of_suspended_greenletys""$  *%   -  S\\* ,,44g> S\\001 ,,33;;WE #,,--445rcddlmddlmfdt }|j d|j }tdD]-}|j|jd||j}/|j|jdd|j|j|j|j dd y) Nr)partialr)_test_extension_cppc|dkDr|j|dz zStjjj S)Nrr) test_callrrrr)rrrrecurses rrz@TestGreenlet.test_get_stack_with_nested_c_calls..recursesJ1u.88!a%9PQQQ&&(//668 8rr7rrii) functoolsrrr(rrr:r8rrrS)r;grrrprrrs @@@r"test_get_stack_with_nested_c_callsz/TestGreenlet.test_get_stack_with_nested_c_callss%) 9  ! !  q !A   U^^C0! 4LLE ! ,a0 %,,' 2-rc4tjfd}fdt|}|j}td}|j|j |j j d|j|jy)Nc<tjdyr)rrrsrrz6TestGreenlet.test_frames_always_exposed..outers #--" #rc(j|yr#)r)rrs rrz6TestGreenlet.test_frames_always_exposed..inners KK rcyr#rrrrrz9TestGreenlet.test_frames_always_exposed..rrr) rrr(rr8rrrSr)r;rrrrrrs @@rtest_frames_always_exposedz'TestGreenlet.test_frames_always_exposedsx""$ $    -  --w7 %,,'rN)F)4rrrr<r?rIrLrQrTr\rdrsrxr{rrunittestskipIfr rrrrrrrrrrrrrrr rr r rr/r5rDrPrirtrrrrrrrrrrrr-r-4se .117 ! '(D, 1,8+ O&6X__ &&G55n+  -&  5" +C 6 ;7)7)r::>))*-^$4-82 5n(FTX__ &&EDDDDL  +%* )6:.&(rr-cHeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) TestGreenletSetParentErrorsc itjtjfd}d}tj|}|jj dt |}|j |jt5}d|_ dddj|jd|jtjdy#1swYPxYw)Ncftdd<jjdy)Ncyr#rrrrrzQTestGreenletSetParentErrors.test_threaded_reparent..run..rrr)rirrsrrBz?TestGreenletSetParentErrors.test_threaded_reparent..runrrc\tjjjyr#rrrrblankzATestGreenletSetParentErrors.test_threaded_reparent..blankrrrjrir)z&parent cannot be on a different thread)rlrrmrnrr(rrCrrrror8rFrG) r;rBrrr)r$rrrs @@@rtest_threaded_reparentz2TestGreenletSetParentErrors.test_threaded_reparents!) __&   2!!- 2      z * !cCyAH ! B S]]+-UV  ! !s  C99Dcgfd}tj|}|j|jd|j |j dzGfddt }|d}|jtj5}|jddd|jtjd dd=y#1swY4xYw) Nc`td}j||jy)Ncyr#rrrrrzYTestGreenletSetParentErrors.test_unexpected_reparenting..worker..rr)r(rr)r)anothers rrzGTestGreenletSetParentErrors.test_unexpected_reparenting..workers"L)A NN1  HHJrrjrir)initial_main_greenletsceZdZfdZy)KTestGreenletSetParentErrors.test_unexpected_reparenting..convolutedcN|dk(r d|_tj||SNrBrrr(rr;rrs rrz\TestGreenletSetParentErrors.test_unexpected_reparenting..convoluted.__getattribute__(5=")!*DK"33D$??rNrrsrrr  @rrcyr#rrrrrzITestGreenletSetParentErrors.test_unexpected_reparenting..rrr)rlrmrnrormain_greenlets_before_testr(rCrrrr8rFrG)r;rrrr)r$rs @rtest_unexpected_reparentingz7TestGreenletSetParentErrors.test_unexpected_reparentings    F +   r & &&d>]>]`a>a&b @ @ | $   x~~ . # HHJ  S]]+] _ AJ   s CC%cgtjtjfd}Gfddt}tj|}|j j d |d}|j tj5}|jddd|jdtj|jdt|j|jd t|jj|jddd=y#1swYxYw#j|jddd=wxYw) Nctd}j||jjj dy)Ncyr#rrrrrzhTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..worker.. rrri)r(rrrr)r)rkeep_main_aliveswitched_to_greenlets rrzVTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..worker s<L)A NN1  HHJ $ $ &   $rceZdZfdZy)ZTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..convolutedcN|dk(r d|_tj||Srrrs rrzkTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..convoluted.__getattribute__rrNrrsrrrrrrrjricyr#rrrrrzXTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..rrz#Cannot switch to a different threadExpectedCurrent)rlrr(rmrnrrCrrrrErFrGrro) r;rrrr)r$rrrs @@@r*test_unexpected_reparenting_thread_runningzFTestGreenletSetParentErrors.test_unexpected_reparenting_thread_runnings%(0#//+ %  @ @   F +  !!"% <(A""8>>2 c   MM?S]]AS T MM*c#--&8 9 MM)S%7 8    ! FF2J       ! FF2J s%>(E!&E7A7E!EE!!(F ctd}|j|jtj|j t 5}|`ddd|jtjdy#1swY/xYw)Ncyr#rrrrrzGTestGreenletSetParentErrors.test_cannot_delete_parent..*rrcan't delete attribute) r(rOrrrrCrDr8rFrG)r;rr$s rtest_cannot_delete_parentz5TestGreenletSetParentErrors.test_cannot_delete_parent)sk\* fmmX%8%8%:;   ~ . #   S]]+-EF  s BB c|jt5}tj`ddd|j t jdy#1swY/xYw)NrrCrDrrrr8rFrGr;r$s r!test_cannot_delete_parent_of_mainz=TestGreenletSetParentErrors.test_cannot_delete_parent_of_main1sP   ~ . -###%, - S]]+-EF - -s AA"c^|jtjjyr#)rSrrrr>s r!test_main_greenlet_parent_is_nonez=TestGreenletSetParentErrors.test_main_greenlet_parent_is_none7s (--/667rcd}fd}t|}j||||jj||||jy)Nc\tjjjyr#rrrrbgzCTestGreenletSetParentErrors.test_set_parent_wrong_types..bg<s    ! ( ( / / 1rcdddfD]b}jt5}||_dddjt j dt |jzdy#1swYGxYw)Nr42z4GreenletChecker: Expected any type of greenlet, not )rCrrr8rFrGtyper)gletpr$r;s rcheckzFTestGreenletSetParentErrors.test_set_parent_wrong_types..check@sy1dD( _&&y1$S"#DK$   &JTRSWM]M]]_  _$$s A..A7 )r(rrr)r;rrr)s` rtest_set_parent_wrong_typesz7TestGreenletSetParentErrors.test_set_parent_wrong_types;sW 2 _ O  a    a  rctd}|jt5}||_ddd|j t j dy#1swY/xYw)Ncyr#rrrrrz@TestGreenletSetParentErrors.test_trivial_cycle..Xrrcyclic parent chain)r(rCrrr8rFrG)r;rr$s rtest_trivial_cyclez.TestGreenletSetParentErrors.test_trivial_cycleWsR<(   z * cDK  S]]+-BC  s AA!c|jt5}tjtj_ddd|j t jdy#1swY/xYw)Nz(cannot set the parent of a main greenletrrs rtest_trivial_cycle_mainz3TestGreenletSetParentErrors.test_trivial_cycle_main]s_   ~ . A#+3+>+>+@H   ! ( A S]]+-WX A As ,A00A9ctd}td}td}||_||_|jt5}||_ddd|j t j dy#1swY/xYw)Ncyr#rrrrrz?TestGreenletSetParentErrors.test_deeper_cycle..drrcyr#rrrrrz?TestGreenletSetParentErrors.test_deeper_cycle..errcyr#rrrrrz?TestGreenletSetParentErrors.test_deeper_cycle..frrr)r(rrCrr8rFrG)r;r*rvg3r$s rtest_deeper_cyclez-TestGreenletSetParentErrors.test_deeper_cyclecst  &  &  &    z * cBI  S]]+-BC  s A>>BN) rrrrrrrrrrrrrrrrrrs<W2'R"HGG 88D Y Drrc6eZdZdZdZdZdZdZdZdZ y) TestReprcJ|j|j|||fyr#)rendswith)r;gotsuffixs rassertEndsWithzTestRepr.assertEndsWithqs  V,sFm)reprrrr r;rs rtest_main_while_runningz TestRepr.test_main_while_runningts& $$& ' A>?rctjfd}t|}|j}|j |dy)NctSr#)r rsrrBz-TestRepr.test_main_in_background..runzs : r suspended active started main>)rrr(rr )r;rBr)rrs @rtest_main_in_backgroundz TestRepr.test_main_in_backgroundxs>""$    HHJ A@ArcNtt}|j|dy)Nz pending>)r r(r r s r test_initialzTestRepr.test_initials   A{+rc&tjGfddtj}|}|j |j d|j |jd|j |jdtdD]}tjdtdD]N}|j|jjt|j}|j |dPy) Nc$eZdZdxZZdZfdZy)/TestRepr.test_main_from_other_thread..TNct|_tj|_t|j|_yr#)r  original_mainrr main_gletr~)r;rs rrBz3TestRepr.test_main_from_other_thread..T.runs0%)$Z"!)!4!4!6#'#7 r)rrrrr~rrBrsrTrs*. .MKI 8rrrirr r0gMbP?z (thread exited) dead>)rrrlrmrnror rr~r:rrrrrZr )r;rrrcrrs @rtest_main_from_other_threadz$TestRepr.test_main_from_other_threads""$ 8    8 C   r  AOO-NO AMM+JK q A JJu  q =A OOAKK,, -Q[[!A   #; < =rctd}|j|jt|d|j dt||j dt||j dt|y)Ncyr#rrrrrz$TestRepr.test_dead..rrz dead> suspendedstartedactive)r(rr r  assertNotInrPs r test_deadzTestRepr.test_deadse  %   DGX. d1g. DG, 47+rctd}td}tj}|||fD]0}|j|t|j|t2y)Ncyr#rrrrrz>TestRepr.test_formatting_produces_native_str..rrcyr#rrrrrz>TestRepr.test_formatting_produces_native_str..rr)r(rrassertIsInstancerF)r;g_dead g_not_startedg_curr)s r#test_formatting_produces_native_strz,TestRepr.test_formatting_produces_native_strsf\*#L1 ##%- A  ! !   ! !  rN) rrrr rrrrr$r,rrrrros(=@B,!=F,rrceZdZdZdZdZy)TestMainGreenletcdttjvsJttj}dt|vsJ|S)Nr)r rrr)r;rs r_check_current_is_mainz'TestMainGreenlet._check_current_is_mainsHh1134444 $$& 'T!W$$$rcb|j}td|fi}|j|y)Nsubclass)r0rrN)r; main_typer2s r)test_main_greenlet_type_can_be_subclassedz:TestMainGreenlet.test_main_greenlet_type_can_be_subclasseds.//1  YL"5 X&rct|j|jtjtyr#)r0r(rrr(r>s rtest_main_greenlet_is_greenletz/TestMainGreenlet.test_main_greenlet_is_greenlets' ##% h113[ArN)rrrr0r4r6rrrr.r.s' Brr.c<eZdZdZdZdZdZdZdZdZ dZ y ) TestBrokenGreenletscd}tjj|}d|_|j t d5|j dddy#1swYyxYw)Nctd)NzNever get here)AssertionErrorrrrrz.funcs !12 2rTz;Failed to switch stacks into a greenlet for the first time.)r _greenletUnswitchableGreenletforce_switch_errorassertRaisesRegex SystemErrorr)r;rr)s rtest_failed_to_initialstubz.TestBrokenGreenlets.test_failed_to_initialstubsY 3    3 3D 9#  # #K$ac  HHJ   s AA#cgfd}tjj|}|j|j dg|j|j ddgd|_|j td5|jdddd|_|j|j gdy#1swY5xYw)Ncjdtjjj jdtjjj jdy)Nrr5r0r1)runssrrzDTestBrokenGreenlets.test_failed_to_switch_into_running..funcsZ KKN    ! ( ( / / 1 KKN    ! ( ( / / 1 KKNrrr5Tz0Failed to switch stacks into a running greenlet.F)rr5r0)rr<r=rr8r>r?r@)r;rr)rDs @r"test_failed_to_switch_into_runningz6TestBrokenGreenlets.test_failed_to_switch_into_runnings     3 3D 9   s#   1v&#  # #K$VX  HHJ  %   y)  s CCc|jd}|jd|j|j|j|j y)Nzfail_slp_switch.pyzfail_slp_switch is running)assertScriptRaisesrEoutput returncode,get_expected_returncodes_for_aborted_processr;exs r&test_failed_to_slp_switch_into_runningz:TestBrokenGreenlets.test_failed_to_slp_switch_into_runningsA  $ $%9 : 2BII> bmmT%V%V%XYrc|jd}|jd||jd||jd||jd||jd||jd|y)Nzfail_switch_two_greenlets.pyz In g1_runTRACEz LEAVE TRACEzFalling off end of mainzFalling off end of g1_runzFalling off end of g2 run_scriptrEr;rHs r#test_reentrant_switch_two_greenletsz7TestBrokenGreenlets.test_reentrant_switch_two_greenlets sh!?@ k6* gv& mV, /8 16: -v6rc|jdd}|jd|j|jd|jy)Nzfail_switch_three_greenlets.py)r) exitcodesrzpositional arguments)rGrErHrKs r%test_reentrant_switch_three_greenletsz9TestBrokenGreenlets.test_reentrant_switch_three_greenletss@ $ $%EQU $ V k299- ,bii8rcJ|jd}|jd|y)Nzfail_switch_three_greenlets2.pyaRESULTS: [('trace', 'switch'), ('trace', 'switch'), ('g2 arg', 'g2 from tracefunc'), ('trace', 'switch'), ('main g1', 'from g2_run'), ('trace', 'switch'), ('g1 arg', 'g1 from main'), ('trace', 'switch'), ('main g2', 'from g1_run'), ('trace', 'switch'), ('g1 from parent', 'g1 from main 2'), ('trace', 'switch'), ('main g1.2', 'g1 done'), ('trace', 'switch'), ('g2 from parent', ()), ('trace', 'switch'), ('main g2.2', 'g2 done')]rPrRs r&test_reentrant_switch_three_greenlets2z:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2 s) !BC  =  rcJ|jd}|jd|y)Nz#fail_initialstub_already_started.pya!RESULTS: ['Begin C', 'Switch to b from B.__getattribute__ in C', ('Begin B', ()), '_B_run switching to main', ('main from c', 'From B'), 'B.__getattribute__ back from main in C', ('Begin A', (None,)), ('A dead?', True, 'B dead?', True, 'C dead?', False), 'C done', ('main from c.2', None)]rPrRs r4test_reentrant_switch_GreenletAlreadyStartedInPythonzHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPython2s'!FG  1   rcJ|jd}|jd|y)Nzfail_clearing_run_switches.pyzRESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]rPrRs r*test_reentrant_switch_run_callable_has_delz>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_del>s'!@A    rN) rrrrArErMrSrVrXrZr\rrrr8r8s+ *8Z 79 $   rr8__main__)r}rrrlrabcrrrr(rrrr r r leakcheckr rrr r+r-rrr.r8rrrrrr`s ,")&  K(8K(\jD(jDZRxRjBxB.k (k Z zHMMOr