XjddlZddlZddlZddlZddlZddlmZddlmZddlZddlmZ ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd lmZdd lmZddlmZddlmZGddeZdZdZGdde ZGdde ZGdde ZGdde ZGdde ZGdde Ze d k(rejByy)!N)ABCMeta)abstractmethod)greenlet)TestCase)RUNNING_ON_MANYLINUX)PY313)PY314)WIN)RUNNING_ON_FREETHREAD_BUILD)fails_leakcheck) fails_leakcheck_on_py314_or_less)ignores_leakcheck)ignores_leakcheck_ifc eZdZy) SomeErrorN__name__ __module__ __qualname__p/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/greenlet/tests/test_greenlet.pyrr"srrc tjjjt#|j t j dxYwNr)r getcurrentparentswitchappendsysexc_inforseens rfmainr$&sJ$$++- O CLLN1%& s ,4)AcFd}t||}|j|y)Nc|Nr)excs rcrasherzsend_exception..crasher2s rr RawGreenletr)gr(r)g1s rsend_exceptionr//s WQ 'BIIcNrceZdZdZdZdZdZdZdZdZ dZ d Z e d Z d Zd Zd ZdZej&exreddZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"e#d5dZ$e#e%e&xre'jPddd k(d!d"Z)d#Z*e+d$Z,d%Z-d&Z.d'Z/d(Z0d)Z1d*Z2ej&exred+d,Z3d-Z4d.Z5d/Z6d0Z7d1Z8d2Z9d3Z:d4Z;y)6 TestGreenletcgfd}t|}jd|jjd|jjd|jt t dy)Ncjdtjjj jdy)Nrrrrrrlstsrfz'TestGreenlet._do_simple_test..f=s4 JJqM    ! ( ( / / 1 JJqMrr)r,rr assertEquallistrange)selfr8r-r7s @r_do_simple_testzTestGreenlet._do_simple_test:sc  N 1    1    1  d58n-rc$|jyr')r@r?s r test_simplezTestGreenlet.test_simpleIs 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_AttributeErrorLsP M   ~ . # HHJ  eS/0  s AA(ct}|jt5}|jtddd|j dt jy#1swY/xYwrE)r,rGrHthrowrrIrJrKrLs r'test_throw_no_run_raises_AttributeErrorz4TestGreenlet.test_throw_no_run_raises_AttributeErrorSsS 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_NoneZs5 t $ Q ahh 3 3 56rcttd}|j||j|jy)N)rF)r,rR assertIsNonerFrTs 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)rrrrrextendr6srr8z)TestGreenlet.test_two_children..fgs9 JJqM    ! ( ( / / 1 JJ1v rrr9r:T)r,rr<lendead)r?r8r-hr7s @rtest_two_childrenzTestGreenlet.test_two_childrends  N N   S1%   S1%   S1% &   S1% &rcgfdfd}|jtj|tsdndt |}|jtj|tsdnd|j |jgd|jtj|tsdydy)Ncjdtjjj y)Nbr5r6srr8z3TestGreenlet.test_two_recursive_children..f{s) JJsO    ! ( ( / / 1rcjdt}|jjdy)Nac)rr,r)r-r8r7s rr-z3TestGreenlet.test_two_recursive_children..gs+ JJsOAA HHJ JJsOrr9r)rercrf)r<r getrefcountr r,r)r?r-r8r7s @@rtest_two_recursive_childrenz(TestGreenlet.test_two_recursive_childrenxs 2  +eQC N +eQC   o. +eQCCrc gfd}tdDcgc]}tj|}}|D]}|j|D]}|j dj t t |ycc}w)NcHjjdyNT)r@r)r?successsrr8z$TestGreenlet.test_threads..fs  " NN4 r target)r> threadingThreadstartjoinr<r])r?r8ithsthrls` @r test_threadszTestGreenlet.test_threadss !499=ayq)== B HHJ  B GGBK  Ws3x0 >sB cxdddfd }tdD]}|tjy)Ncd}tj|}|j|j||jy)Nc^ tjjj-r'rrrrrrrbodyzPTestGreenlet.test_switching_many_threads..creates_greenlet..bodys%'')00779r)rrrwait) greenletswait_to_die_untilr|r-s rcreates_greenletzBTestGreenlet.test_switching_many_threads..creates_greenlets< :!!$'A HHJ   Q   " " $rc|j|js?t|D]} |js|j !|js>yy#t j $rYJwxYwr')r}is_setr=r^rrerror)r~wait_to_check_until quit_afterr-s rswitches_from_other_threadzLTestGreenlet.test_switching_many_threads..switches_from_other_threadsk  $ $ & '')iA vvHHJ!'') $>>sA!!A76A7c dg}tj}tj}t|Dcgc]}tj||f}}t|Dcgc]}tj |||f}}||zD]}|j t ||kr$t jdt ||kr$|j|D]}|jd|j|D]}|jdycc}wcc}w)Nroargsg-C6?g?) rpEventr>rqrrr]timesleepsetrs) thread_countr~greenlets_all_createdall_threads_dead_creators switcherstrrs rrun_itz8TestGreenlet.test_switching_many_threads..run_itsBI$-OO$5 !(0  &   (8 @U@WXH&   (B'02G'7'9:I*   i.</ 6"i.</ ! % % ' s    " s  5s D((!D-))r>gccollect)r?rrrrs @@rtest_switching_many_threadsz(TestGreenlet.test_switching_many_threadss6 %  Hr A H JJL rcg}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$rrr<rGr)r?r#r.g2values rtest_exceptionzTestGreenlet.test_exceptions     $ $  r" )RYY/  {+  #  {+ "  #  {+rcg}tt}|j||jtt |t|j |tgyr')r,r$rrGKeyErrorr/r<)r?r#r.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$rr<rrr GreenletExit)r?r#r.rs r test_dealloczTestGreenlet.test_deallocs     $ $ r"    5 567    5 5x7L7LMNrc<d}t|}|jgtj}fd}|t_ ~|t_|j t d|j djty#|t_wxYw)Nc tjjjy#tj$rt dwxYwr')rrrrrrrrrrFzHTestGreenlet.test_dealloc_catches_GreenletExit_throws_other..run s? *##%,,335(( *T) *s ,/A c(j|yr'r) unraisableunraisable_eventss r_capturezMTestGreenlet.test_dealloc_catches_GreenletExit_throws_other.._captures  $ $Z 0rrr) r,rr unraisablehookr<r]assertIsInstance exc_valuer)r?rFr-old_hookrrs @r.test_dealloc_catches_GreenletExit_throws_otherz;TestGreenlet.test_dealloc_catches_GreenletExit_throws_other s *    %% 1% *!)C  ./3 /2<tt}|jj|~t j j jdtj jdty)Nr4)r,r$rrrrrr})r./bg_glet_created_running_and_no_longer_ref_in_bgbg_should_be_clearfg_ref_releasedok_to_exit_bg_threadr#somerefs rr8z1TestGreenlet.test_dealloc_other_thread..f4snU#B IIdO NN2  JJL ; ? ? A   # M  " " $ % %a ( Mrrnrmrr4)rprrqrrr}r<r]r rrrrrrs) r?r8rrrrrr#rs @@@@@@rtest_dealloc_other_threadz&TestGreenlet.test_dealloc_other_thread$sF:C//:K7#//+&__.(0     A &  7<.f1csE a A   QXXt ,    ! ( ( / / 2$rr)r,r assertTruegr_frame assertFalser<)r?rr-framefrom_gs` r test_framezTestGreenlet.test_framebs} % O  +,   !23 T*rcd}tj|d}tj|d}|j|j|jd|jdy)NcBtfd}|jy)Nc.tjSr')rrxsrz>TestGreenlet.test_thread_bug..runner..tsDJJqMrr+)rr-s` rrunnerz,TestGreenlet.test_thread_bug..runnerss12A HHJr)g?r)g333333?rm)rprqrrrs)r?rt1t2s rtest_thread_bugzTestGreenlet.test_thread_bugrsU   V& 9   V& 9        rclfd}t|jdd}j|dy)NcNj|dj|dy)Nr:r9*)r<)rercr?s rrFz,TestGreenlet.test_switch_kwargs..run~s&   Q "   Q "rr:r9)rercrr,rr<)r?rFrs` rtest_switch_kwargszTestGreenlet.test_switch_kwargs}s4    # #a1 # - Brcd}t|}|jddi|jd|jdddif|j|jd|jy)Nctjjj|tjjjdd||dzfS)Nrr9r4r{rs rrFz6TestGreenlet.test_switch_kwargs_to_parent..runsR    ! ( ( / /! / 4    ! ( ( / /Q / 7a1f9 rrr4)r9)r4 )r,r<r)r?rFr-s rtest_switch_kwargs_to_parentz)TestGreenlet.test_switch_kwargs_to_parentsd    #q188A;/ $a)188:6 ,rcitjtjfd}tj|}|jj d|j t j5djdddj|jdjy#1swY;xYw)Ncftdd<jjdy)Ncyr'rrrrrzITestGreenlet.test_switch_to_another_thread..run..rr-rmr,rr} created_eventdata done_eventsrrFz7TestGreenlet.test_switch_to_another_thread..run)#L1DI     OOB rrnrmr-) rprrqrrr}rGrrrrrsclear)r?rFthreadrrrs @@@rtest_switch_to_another_threadz*TestGreenlet.test_switch_to_another_threads!) __&  !!- 2   x~~ .  I     B   s CC"cPfd}fdt|jy)Nc td#tj}tj j |tjYyxYw)Nfun) ValueErrorr r!r,rr<)r!r_r?s rr8z&TestGreenlet.test_exc_state..fsK ; '' ;<<>A%%'  3<<>:s AA#cNjtjdy)N)NNN)r<r r!rBsrr_z&TestGreenlet.test_exc_state..hs   S\\^-? @rr+)r?r8r_s` @rtest_exc_statezTestGreenlet.test_exc_states  ; A Arcd}d}d}t|}|j|ji|j|j|jd|j|jddi|j|_|j|jddi|j t |||j t ||dy)Nc6dtj_yNr)rrtestrrrr8z*TestGreenlet.test_instance_dict..fs)+H   ! &rc|`yr'__dict__)r-s rdeldictz0TestGreenlet.test_instance_dict..deldicts rc||_yr'r)r-rs rsetdictz0TestGreenlet.test_instance_dict..setdicts AJrrr)r,r<rrrrG TypeError)r?r8rrr-s rtest_instance_dictzTestGreenlet.test_instance_dicts ,   N R(   $ fb\2ZZ  fb\2 )Wa0 )Wa4rcpgfd}t|}|j|jdgy)Nc`jttjdyrE)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)copyrGrr,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,rrrrrSr)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,rGrHr)r?r.rs 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') Exceptionr,__getattribute__r?names rrzOTestGreenlet.test_throw_exception_not_lost..mygreenlet.__getattribute__s)#O"33D$??s Nrrrrrrr mygreenletrs @rrcyr'rrrrrz.rr)r,rGrrO)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'r{rrrrzGTestGreenlet._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!  ##% rrnrmrBcannot switch to a different thread (which happens to have exited)z Cannot switchrT)rprqrrrswait_for_pending_cleanupsrGrrrOrrJrKrr<rr RuntimeErrorrf_localsrWexpect_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  GNr9)r4rmz;does not leaks on Windows 3.10, but does on other platformsc$|jyr'r%rBs r&test_throw_to_dead_thread_doesnt_crashz3TestGreenlet.test_throw_to_dead_thread_doesnt_crash:s 779rc&|jdyrkr'rBs r+test_throw_to_dead_thread_doesnt_crash_waitz8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_waitBs 77=rcGddt}|}|j|jddd|_y)NceZdZdZdZdZy)7TestGreenlet.test_recursive_startup..convolutedc<tj|d|_yr)r,__init__countrBs rr/z@TestGreenlet.test_recursive_startup..convoluted.__init__Hs$$T* rc|dk(r'|jdk(rd|_|jdtj||S)NrFrr+)r0rr,rrs rrzHTestGreenlet.test_recursive_startup..convoluted.__getattribute__Ks85=TZZ1_!"DJKKO"33D$??rc< |jj|r'rr)r?rs rrFz;TestGreenlet.test_recursive_startup..convoluted.runPsKK&&u-rN)rrrr/rrFrrr convolutedr-Gs  @  .rr5rr2T)r,r<rr#)r?r5r-s rtest_recursive_startupz#TestGreenlet.test_recursive_startupEs9 . . 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__cs  rNrrrr@r>r?sr finalizedr9bs rrCc\tjjjyr'r{rrr deallocatorz=TestGreenlet.test_threaded_updatecurrent..deallocatorjrrcjtjd=jjtjjyrr=rrr<)r-r>r?srfthreadz9TestGreenlet.test_threaded_updatecurrent..fthreadlsF MMO    !! MMO MMO    ! MMOrrrnrm)rpLockr=objectrrr,bombrrqrrr<r<rs) r?rCrErHrrr-r>r?s @@@rtest_threaded_updatecurrentz(TestGreenlet.test_threaded_updatecurrent[s       2 ""$  % &K!  !   G ,     ,,.5 r rcgfddtgdjtdj}|j|j|dy)Nctjjj}d=tjj_ tjjj|j tjy#j tjwxYwr)rrrrr)r initiatorr#rs rrz>TestGreenlet.test_dealloc_switch_args_not_lost..workers'')00779Eq '224;;I  3##%,,33E: H//12 H//12s -B&&%C cyrrrrrrOzATestGreenlet.test_dealloc_switch_args_not_lost..initiatorrrr)r,rrr<)r?rrOr#rs @@@r!test_dealloc_switch_args_not_lostz.TestGreenlet.test_dealloc_switch_args_not_lostsk 3 f%&q  6!95   "  #rcdGddt}|tdfd}t|}|j|j y)Nc||i|yr'r)rreks r_applyz0TestGreenlet.test_tuple_subclass.._applys !MqMrceZdZdZy)1TestGreenlet.test_tuple_subclass..mytuplecptjjtj |Sr')rrrtuple__len__rBs rr[z9TestGreenlet.test_tuple_subclass..mytuple.__len__s&##%,,.}}T**rN)rrrr[rrrmytuplerXs +rr\r)recftjjjyr'r{)rVrkwargssr switchapplyz5TestGreenlet.test_tuple_subclass..switchapplys$ 8&&(//66f Er)rZdictr,r<r)r?r\r_r-rVrr^s @@@rtest_tuple_subclassz TestGreenlet.test_tuple_subclasssL  +e +y F  $ V,rctdtfdtdi}Gdd|}Gdd|}||jt|y)NAbstractSubclassrFcyr'rrBs rrz7TestGreenlet.test_abstract_subclasses..rrc eZdZy):TestGreenlet.test_abstract_subclasses..BadSubclassNrrrr BadSubclassrf rrgceZdZdZy);TestGreenlet.test_abstract_subclasses..GoodSubclasscyr'rrBs rrFz?TestGreenlet.test_abstract_subclasses..GoodSubclass.runsrN)rrrrFrrr GoodSubclassrjs rrl)rr,rrGr)r?rcrgrls rtest_abstract_subclassesz%TestGreenlet.test_abstract_subclassessT"  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'rGrBsranother_threadzWTestGreenlet.test_implicit_parent_with_threads..attempt..another_threads! ##% rrnceZdZfdZy)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"&HQKrNrA)r>r?rvsr gc_callbackrts'rrwceZdZfdZy)PTestGreenlet.test_implicit_parent_with_threads..attempt..garbagec,||_|_yr')cyclecallback)r?rws rr/zYTestGreenlet.test_implicit_parent_with_threads..attempt..garbage.__init__s!%DJ$/MDMrN)rrrr/)rwsrgarbagerys2rr}r9rrmT)rprIr=rqrrrJr>rrrsr,rrrr<r)rrrr}lrcurrentr-rlastrwr>r?rvNr?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 4rr;)r isenabled get_thresholdr>)r?rrrs` @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..GreenletNrrrrGreenletrrhrrc jjy#$r#jjYywxYwr')rrgletsr)rrr?sr greenlet_mainzYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads..greenlet_mains? 0 ##**, 0 !!*,/ 0s#%A  A rm) rrrr,r rgrr>rr assertGreaterEqualr<)r?r initial_refsrrrrs` @@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)rq)rrc eZdZy)STestGreenlet.test_issue_245_reference_counting_subclass_threads..MyGreenletNrrrr MyGreenletr?rhrrcDjjyr'r4rsrrzVTestGreenlet.test_issue_245_reference_counting_subclass_threads..greenlet_mainEs L   & & (rc}j||j~|jjdy)Nrm)rrrr})greenlet_running_eventminerrrr ref_cleareds r thread_mainzTTestGreenlet.test_issue_245_reference_counting_subclass_threads..thread_mainHsHm,D LL  KKM " & & (   R  Lr-rorrm)rprqrrrr,r rgr r>rrrr}rr r<)r?rqrrrthread_ready_eventsrreventrrrrrrrs @@@@@r2test_issue_245_reference_counting_subclass_threadsz?TestGreenlet.test_issue_245_reference_counting_subclass_threads1s %#'  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_argsrQrcyrrrrrleafzYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error..leafrQr)r,rGrr)r?rparent_never_startedrchilds r>test_falling_off_end_switches_to_unstarted_parent_raises_errorzKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error~sV  +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_args r7NrcyrrrrrrzRTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works..leafrQr)rrr)r?rrrrrs r7test_falling_off_end_switches_to_unstarted_parent_workszDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_workssC  +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(rtyrE)rrs rrziTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..Parent.__getattribute__s5=#O!rNrrrrParentrs $rrc&jdSrrr"srrzZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..DKKOrr)r,rGrrr<)r?rrrr#s @r;test_switch_to_dead_greenlet_with_unstarted_perverse_parentzHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parents $[ $ &x35IJ  y )  LLN  t$   y )  LLN  t$     sB,?B8,B58Ccgtfd}tfd}|j|jdg||_|j}|j ||jddgy)Nc&jdSrrr"srrzDTestGreenlet.test_switch_to_dead_greenlet_reparent..s4;;r?rc&jdSrrr"srrzDTestGreenlet.test_switch_to_dead_greenlet_reparent..rrrr)r,rr<rrW)r?rrrr#s @r%test_switch_to_dead_greenlet_reparentz2TestGreenlet.test_switch_to_dead_greenlet_reparentsn*+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)rr rrsrrzHTestGreenlet.test_can_access_f_back_of_suspended_greenlet..inners KK a( )rcyr'rrrrrzKTestGreenlet.test_can_access_f_back_of_suspended_greenlet..rrrr) rrr,rrRrr<f_codeco_namerrW)r?rr unrelatedrrs @@r,test_can_access_f_back_of_suspended_greenletz9TestGreenlet.test_can_access_f_back_of_suspended_greenlets""$  *%   -  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)vrrrecurses rrz@TestGreenlet.test_get_stack_with_nested_c_calls..recursesJ1u.88!a%9PQQQ&&(//668 8rr;rrmi) functoolsrrr,rrr>r<r"rrW)r?grrrtrrrs @@@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)r rrsrrz6TestGreenlet.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,rr<rrrWr)r?rrrrrrs @@rtest_frames_always_exposedz'TestGreenlet.test_frames_always_exposedsx""$ $    -  --w7 %,,'rcfdfdfd}fd}tj|tj|jy)Nc(j|Sr'r)rrs rk1zITestGreenlet.test_switching_holding_critical_section_no_crash..k1 IIKHrc(j|Sr'r)rr.s rk2zITestGreenlet.test_switching_holding_critical_section_no_crash..k2rrcBtdgjy)Nrkey)sortedr)rrsrg1_bodyzNTestGreenlet.test_switching_holding_critical_section_no_crash..g1_bodys A3B  IIKrctdgttdd5}|jdddy#1swYyxYw)Nrrrtzutf-8)encoding)ropen__file__read)r8rs rg2_bodyzNTestGreenlet.test_switching_holding_critical_section_no_crash..g2_body"s= A3B hw7 1   s <A)rr)r?rrr.rrrs @@@@r0test_switching_holding_critical_section_no_crashz=TestGreenlet.test_switching_holding_critical_section_no_crashsB         w '   w ' r)F)))*-^$4-82 5n(FTX__ &&EDDDDL  +%* )6:.&(0&rr1cHeZdZdZdZdZdZdZdZdZ 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..6rrr-rmrrsrrFz?TestGreenletSetParentErrors.test_threaded_reparent..run5rrc\tjjjyr'r{rrrblankzATestGreenletSetParentErrors.test_threaded_reparent..blank:rrrnrmr-z&parent cannot be on a different thread)rprrqrrr}r,rrGrrrrsr<rJrK) r?rFrrr-r(rrrs @@@rtest_threaded_reparentz2TestGreenletSetParentErrors.test_threaded_reparent0s!) __&   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..Lrr)r,rr)r-anothers rrzGTestGreenletSetParentErrors.test_unexpected_reparenting..workerKs"L)A NN1  HHJrrnrmr)initial_main_greenletsceZdZfdZy)KTestGreenletSetParentErrors.test_unexpected_reparenting..convolutedcN|dk(r d|_tj||SNrFrrr,rr?rrs rrz\TestGreenletSetParentErrors.test_unexpected_reparenting..convoluted.__getattribute__g(5=")!*DK"33D$??rNrrsrr5rf  @rr5cyr'rrrrrzITestGreenletSetParentErrors.test_unexpected_reparenting..krrr)rprqrrrsr main_greenlets_before_testr,rGrrrr<rJrK)r?rrr5r-r(rs @rtest_unexpected_reparentingz7TestGreenletSetParentErrors.test_unexpected_reparentingIs    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..yrrrm)r,rrrr})r-rkeep_main_aliveswitched_to_greenlets rrzVTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..workerxs<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__rrNrrsrr5r ~rrr5rnrmcyr'rrrrrzXTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..rrz#Cannot switch to a different threadExpectedCurrent)rprr,rqrrr}rGrrrrIrJrKrrs) r?rr5rr-r(rr r s @@@r*test_unexpected_reparenting_thread_runningzFTestGreenletSetParentErrors.test_unexpected_reparenting_thread_runningrs%(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,rSrrrrGrHr<rJrK)r?rr(s rtest_cannot_delete_parentz5TestGreenletSetParentErrors.test_cannot_delete_parentsk\* fmmX%8%8%:;   ~ . #   S]]+-EF  s BB c|jt5}tj`ddd|j t jdy#1swY/xYw)NrrGrHrrrr<rJrKr?r(s r!test_cannot_delete_parent_of_mainz=TestGreenletSetParentErrors.test_cannot_delete_parent_of_mainsP   ~ . -###%, - S]]+-EF - -s AA"c^|jtjjyr')rWrrrrBs r!test_main_greenlet_parent_is_nonez=TestGreenletSetParentErrors.test_main_greenlet_parent_is_nones (--/667rcd}fd}t|}j||||jj||||jy)Nc\tjjjyr'r{rrrbgzCTestGreenletSetParentErrors.test_set_parent_wrong_types..bgs    ! ( ( / / 1rcdddfD]b}jt5}||_dddjt j dt |jzdy#1swYGxYw)Nr42z4GreenletChecker: Expected any type of greenlet, not )rGrrr<rJrKtyper)gletpr(r?s rcheckzFTestGreenletSetParentErrors.test_set_parent_wrong_types..checksy1dD( _&&y1$S"#DK$   &JTRSWM]M]]_  _$$s A..A7 )r,rrr)r?rr%r-s` rtest_set_parent_wrong_typesz7TestGreenletSetParentErrors.test_set_parent_wrong_typessW 2 _ O  a    a  rctd}|jt5}||_ddd|j t j dy#1swY/xYw)Ncyr'rrrrrz@TestGreenletSetParentErrors.test_trivial_cycle..rrcyclic parent chain)r,rGrrr<rJrK)r?r#r(s rtest_trivial_cyclez.TestGreenletSetParentErrors.test_trivial_cyclesR<(   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_mains_   ~ . 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..rrcyr'rrrrrz?TestGreenletSetParentErrors.test_deeper_cycle..rrcyr'rrrrrz?TestGreenletSetParentErrors.test_deeper_cycle..rrr))r,rrGrr<rJrK)r?r.rg3r(s rtest_deeper_cyclez-TestGreenletSetParentErrors.test_deeper_cyclest  &  &  &    z * cBI  S]]+-BC  s A>>BN) rrrrrrrrrr&r*r,r2rrrrr/s<W2'R"HGG 88D Y DrrcJeZdZeedsd dZdZdZdZdZ dZ d Z y) TestReprassertEndsWithNcL|j|j||||fyr')rendswith)r?r$suffixmsgs rr5zTestRepr.assertEndsWiths OOAJJv.FC0@ Arcbttj}|j|dy)N current active started main>)reprrrr5r?rs rtest_main_while_runningz TestRepr.test_main_while_runnings& $$& ' A>?rctjfd}t|}|j}|j |dy)NctSr')r<rsrrFz-TestRepr.test_main_in_background..runs : r suspended active started main>)rrr,rr5)r?rFr-r>rs @rtest_main_in_backgroundz TestRepr.test_main_in_backgrounds>""$    HHJ A@ArcNtt}|j|dy)Nz pending>)r<r,r5r=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 rrFz3TestRepr.test_main_from_other_thread..T.runs0%)$Z"!)!4!4!6#'#7 r)rrrrJrrKrFrsrTrHs*. .MKI 8rrLrmrBr;r4gMbP?z (thread exited) dead>)rrrprqrrrsr5rJrr>rrrrKr^r<)r?rLrrr>rs @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,rr5r< assertNotInrTs 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,rrrrJ)r?g_dead g_not_startedg_curr-s r#test_formatting_produces_native_strz,TestRepr.test_formatting_produces_native_strsf\*#L1 ##%- A  ! !   ! !  rr') rrrrrr5r?rCrErMrTr[rrrr4r4s4 8- . B@B,!=F,rr4c$eZdZdZdZdZdZy)TestMainGreenletcdttjvsJttj}dt|vsJ|S)Nr)r<rrr")r?rs r_check_current_is_mainz'TestMainGreenlet._check_current_is_main6sHh1134444 $$& 'T!W$$$rcb|j}td|fi}|j|y)Nsubclass)r_r"rR)r? main_typeras r)test_main_greenlet_type_can_be_subclassedz:TestMainGreenlet.test_main_greenlet_type_can_be_subclassed>s.//1  YL"5 X&rct|j|jtjtyr')r_rrrr,rBs rtest_main_greenlet_is_greenletz/TestMainGreenlet.test_main_greenlet_is_greenletCs' ##% h113[Arcfd}tj|jjt5t ddddy#1swYyxYw)Ncrjt5tddddy#1swYyxYwrE)rGrHgetattr)r-r?srdo_itz1TestMainGreenlet.test_greenlet_run..do_itHs0"">2 "5! " " "s -6rF)rrrGrHrh)r?rir-s` @rtest_greenlet_runz"TestMainGreenlet.test_greenlet_runGsP "   e $    ~ .  Au    s  AA"N)rrrr_rcrerjrrrr]r]2s' Brr]c<eZdZdZdZdZdZdZdZdZ dZ y ) TestBrokenGreenletscd}tjj|}d|_|j t d5|j dddy#1swYyxYw)Nctd)NzNever get here)AssertionErrorrrrrz.funcWs !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_initialstubVsY 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)Nrr9r4r5)runssrrzDTestBrokenGreenlets.test_failed_to_switch_into_running..funcdsZ KKN    ! ( ( / / 1 KKN    ! ( ( / / 1 KKNrrr9Tz0Failed to switch stacks into a running greenlet.F)rr9r4)rrprqrr<rrrsrt)r?rr-rxs @r"test_failed_to_switch_into_runningz6TestBrokenGreenlets.test_failed_to_switch_into_runningbs     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)assertScriptRaisesrIoutput returncode,get_expected_returncodes_for_aborted_processr?exs r&test_failed_to_slp_switch_into_runningz:TestBrokenGreenlets.test_failed_to_slp_switch_into_running~sA  $ $%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_scriptrIr?r|s r#test_reentrant_switch_two_greenletsz7TestBrokenGreenlets.test_reentrant_switch_two_greenletssh!?@ k6* gv& mV, /8 16: -v6rc|jdd}|jd|j|jd|jy)Nzfail_switch_three_greenlets.py)r) exitcodesrzpositional arguments)r{rIr|rs 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')]rrs r&test_reentrant_switch_three_greenlets2z:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2s) !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)]rrs r4test_reentrant_switch_GreenletAlreadyStartedInPythonzHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPythons'!FG  1   rcJ|jd}|jd|y)Nzfail_clearing_run_switches.pyzRESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]rrs r*test_reentrant_switch_run_callable_has_delz>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_dels'!@A    rN) rrrruryrrrrrrrrrrlrlRs+ *8Z 79 $   rrlcLeZdZejeedddZy) TestModule_is_gil_enabledz,Needs 3.13 and above for sys._is_gil_enabledctr$|jtjy|j tjyr')r rr rrrBs rtest_no_gil_on_free_threadedz'TestModule.test_no_gil_on_free_threadeds3 '   S002 3 OOC//1 2rN)rrrr skipUnlessrr rrrrrrs0X&78GI3I3rr__main__)"rr rrprabcrrrr,rrrr r r r leakcheckr rrrrrr$r/r1rr4r]rlrrrrrrrs ,")&7(+  t8tnjD(jDZSxSlx@k (k Z33 zHMMOr