U Wg@s ddlZddlZddlZddlZddlZddlmZddlmZddlZddlmZ ddl m Z ddl m Z ddl m Z dd lmZGd d d eZd d ZddZGddde ZGddde ZGddde ZGddde ZGddde ZedkredS)N)ABCMeta)abstractmethod)greenlet)TestCase)RUNNING_ON_MANYLINUX)PY313)fails_leakcheckc@s eZdZdS) SomeErrorN__name__ __module__ __qualname__rrL/opt/hc_python/lib64/python3.8/site-packages/greenlet/tests/test_greenlet.pyr sr cCs<ztjWn |tdYnXtdSNr)r getcurrentparentswitchappendsysexc_infor seenrrrfmain s rcCs"dd}t||d}||dS)NcSs|dSNr)excrrrcrasher,szsend_exception..crasherr RawGreenletr)grrg1rrrsend_exception)s r#c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZeeozedddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Z e!d]d7d8Z"e!d9d:Z#d;d<Z$e!d=d>Z%d?d@Z&dAdBZ'dCdDZ(dEdFZ)dGdHZ*dIdJZ+eeoRedKdLdMZ,dNdOZ-dPdQZ.dRdSZ/dTdUZ0dVdWZ1dXdYZ2dZd[Z3d\S)^ TestGreenletcs^gfdd}t|}d|d|d|ttddS)Ncs&dtjddS)Nrrrrrrrlstrrf7s z'TestGreenlet._do_simple_test..fr)r rr assertEquallistrange)selfr)r!rr'r_do_simple_test4s    zTestGreenlet._do_simple_testcCs |dSr)r1r0rrr test_simpleCszTestGreenlet.test_simplec Cs:t}|t}|W5QRX|dt|jdSNrun)r assertRaisesAttributeErrorrassertInstr exceptionr0r!rrrr(test_switch_no_run_raises_AttributeErrorFs z5TestGreenlet.test_switch_no_run_raises_AttributeErrorc Cs<t}|t}|tW5QRX|dt|jdSr4)r r6r7throwr r8r9r:r;rrr'test_throw_no_run_raises_AttributeErrorMs z4TestGreenlet.test_throw_no_run_raises_AttributeErrorcCs*tdd}||||jtdS)Nr)r assertIsNotNoneassertIsrrrr0r!rrrtest_parent_equals_NoneTs  z$TestGreenlet.test_parent_equals_NonecCs$tdd}||||jdS)N)r5)r r? assertIsNoner5rArrrtest_run_equals_NoneYs  z!TestGreenlet.test_run_equals_Nonecsgfdd}t|}t|}||td||td||td||jd||td||jddS)Ncs*dtjddgdS)Nr)rrrrrextendrr'rrr)as z)TestGreenlet.test_two_children..frr*r+T)r rr-lendead)r0r)r!hrr'rtest_two_children^s zTestGreenlet.test_two_childrencshgfddfdd}t|}|t|d||dddg|t|ddS) NcsdtjdS)Nbr&rr'rrr)us z3TestGreenlet.test_two_recursive_children..fcs(dt}|ddS)Nac)rr rr!r)r(rrr!ys z3TestGreenlet.test_two_recursive_children..gr*rLrKrM)r r-r getrefcountrrArrOrtest_two_recursive_childrenrs z(TestGreenlet.test_two_recursive_childrencsfgfddfddtdD}|D] }|q,|D]}|dq>tt|dS)NcsddSNT)r1rr)r0successrrr)sz$TestGreenlet.test_threads..fcsg|]}tjdqS)target) threadingThread).0ir)rr sz-TestGreenlet.test_threads.. )r/startjoinr-rG)r0Zthsthr)r)r0rSr test_threadss  zTestGreenlet.test_threadscCsg}tt}tt}||||||_||g|t|j||tg|}||d||tg|d}||d||tgdS)Nr)r rrrr-r6r )r0rr"g2valuerrrtest_exceptions      zTestGreenlet.test_exceptioncCs8g}tt}|||tt|t||tgdSr)r rrr6KeyErrorr#r-)r0rr"rrrtest_send_exceptions  z TestGreenlet.test_send_exceptioncCspg}tt}tt}||||||g~t||tjg~t||tjtjgdSr)r rrr-gccollectr GreenletExit)r0rr"rbrrr test_deallocs   zTestGreenlet.test_dealloccCsvdd}t|}|tj}ddlm}|}t_z~W5|t_X|}|d||d||d|dS)NcSs4ztjWntjk r.tdYnXdSr)rrrrrir rrrrr5szHTestGreenlet.test_dealloc_catches_GreenletExit_throws_other..runr)StringIO ExceptionZignoredr )r rrstderriorkgetvaluer8)r0r5r!Z oldstderrrkrmvrrr.test_dealloc_catches_GreenletExit_throws_others    z;TestGreenlet.test_dealloc_catches_GreenletExit_throws_otherz=Sometimes flaky (getting one GreenletExit in the second list)c sggttttfdd}tj|d}|d|g|tddd=t|g dz|t j gW5 | ddd=dd=XdS)NcsZtt}||~tdtdtdS)Nr%)r rrrrgrhsetwait)r"Z/bg_glet_created_running_and_no_longer_ref_in_bgZbg_should_be_clearZfg_ref_releasedZok_to_exit_bg_threadrZsomerefrrr)s    z1TestGreenlet.test_dealloc_other_thread..frTr\rr%) rVEventrWr]rsr-rGrgrhrrr^rri)r0r)trrtrtest_dealloc_other_threads.        z&TestGreenlet.test_dealloc_other_threadcsffdd}t|}|}||jk||}||d|jddS)Ncs,td}|jdtj|dS)Nrmeaning of life)r _getframer-f_backrrrrrZr2rrf1s z#TestGreenlet.test_frame..f1rx)r r assertTruegr_frame assertFalser-)r0r{r!frameZfrom_grr2r test_frames    zTestGreenlet.test_framecCsLdd}tj|dd}tj|dd}|||d|ddS)Ncstfdd}|dS)Ncs tSr)timesleeprxrr$z>TestGreenlet.test_thread_bug..runner..r)rr!rrrrunner#sz,TestGreenlet.test_thread_bug..runner)g?rUargs)g333333?r\)rVrWr]r^)r0rt1t2rrrtest_thread_bug"s zTestGreenlet.test_thread_bugcs.fdd}t|jddd}|ddS)Ncs|d|ddS)Nr+r**)r-rLrKr2rrr5.s  z,TestGreenlet.test_switch_kwargs..runr+r*rrr rr-)r0r5rrr2rtest_switch_kwargs-s zTestGreenlet.test_switch_kwargscCsRdd}t|}|ddi|d|dddif||d|dS)NcSs2tjj|dtjjddd||dfS)Nrr*r%rrrrrrrrr56sz6TestGreenlet.test_switch_kwargs_to_parent..runrr%)r*)r% )r r-r)r0r5r!rrrtest_switch_kwargs_to_parent5s z)TestGreenlet.test_switch_kwargs_to_parentc sittfdd}tj|d}|d|tjdW5QRX | d dS)Ncs&tddd<ddS)NcSsdSrrrrrrrErzITestGreenlet.test_switch_to_another_thread..run..r!r\r rrrsrZ created_eventdata done_eventrrr5Dsz7TestGreenlet.test_switch_to_another_thread..runrTr\r!) rVrurWr]rsr6rerrorrrrr^clear)r0r5threadrrrtest_switch_to_another_thread?s   z*TestGreenlet.test_switch_to_another_threadcs*fdd}fddt|dS)NcsBz tdWn0t}t|tYnXdS)NZfun) ValueErrorrrr rr-)rrIr0rrr)Ss   z&TestGreenlet.test_exc_state..fcstddS)N)NNN)r-rrrr2rrrI[sz&TestGreenlet.test_exc_state..hr)r0r)rrrtest_exc_stateRs zTestGreenlet.test_exc_statecCsdd}dd}dd}t|}||ji|||jd||jddi|j|_||jddi|t|||t||ddS) NcSsdt_dSNr)rrtestrrrrr)asz*TestGreenlet.test_instance_dict..fcSs|`dSr__dict__rNrrrdeldictcsz0TestGreenlet.test_instance_dict..deldictcSs ||_dSrr)r!rcrrrsetdictesz0TestGreenlet.test_instance_dict..setdictrr)r r-rrrr6 TypeError)r0r)rrr!rrrtest_instance_dict`szTestGreenlet.test_instance_dictcs2gfdd}t|}||dgdS)NcsttddSr4)rhasattrrrrZhas_runrrfuncss z;TestGreenlet.test_running_greenlet_has_no_run..funcFrr0rr!rrr test_running_greenlet_has_no_runqs  z-TestGreenlet.test_running_greenlet_has_no_runcCs0ddl}|t|jt|t|jtdSr)copyr6rr deepcopy)r0rrrr test_deepcopy|szTestGreenlet.test_deepcopycstddtgfdd}t|d}|~||d|djdd=dddS)NcSsdSrrrrrrrrz;TestGreenlet.test_parent_restored_on_kill..csNz Wn<tjk rHtjtYnXdSr)rrrirrrrhubmainresultrrworkers  z9TestGreenlet.test_parent_restored_on_kill..workerrrr)r rrrr|r@r)r0rr!rrrtest_parent_restored_on_kills    z)TestGreenlet.test_parent_restored_on_killc Cs8t}tdd|d}|t|W5QRXdS)NcSsdSrrrrrrrrz9TestGreenlet.test_parent_return_failure..r)r r6r7r)r0r"rbrrrtest_parent_return_failures z'TestGreenlet.test_parent_return_failurecCs2Gdddt}|dd}|t|jtdS)Nc@seZdZddZdS)z>TestGreenlet.test_throw_exception_not_lost..mygreenletcSs"ztWn YnXt||Sr)rlr __getattribute__r0namerrrrs zOTestGreenlet.test_throw_exception_not_lost..mygreenlet.__getattribute__Nr r rrrrrr mygreenletsrcSsdSrrrrrrrrz.)r r6r r=)r0rr!rrrtest_throw_exception_not_losts z*TestGreenlet.test_throw_exception_not_lostFc s0gddfdd}tj|d}||d~rH||tj}dt W5QRXst |j }| |dkpd |kn| t |j dtdjd r|tdjW5QRXstdjjd rdjjn|dj~ddd=d |_dS) NcSstjdSrrrrrrrszGTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash..workercs2t}||r.|tdSr)r rrrrrNrwait_for_cleanuprrrcreators  zHTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash..creatorrTr\rBcannot switch to a different thread (which happens to have exited)z Cannot switchrT)rVrWr]r^wait_for_pending_cleanupsr6rrr=r r9r:r|r-rr} RuntimeErrorrf_localsrCexpect_greenlet_leak)r0rrrvrsrrr*_do_test_throw_to_dead_thread_doesnt_crashs@     z7TestGreenlet._do_test_throw_to_dead_thread_doesnt_crashcCs |dSrrr2rrr&test_throw_to_dead_thread_doesnt_crashsz3TestGreenlet.test_throw_to_dead_thread_doesnt_crashcCs|ddSrRrr2rrr+test_throw_to_dead_thread_doesnt_crash_waitsz8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_waitcCs2Gdddt}|}||ddd|_dS)Nc@s$eZdZddZddZddZdS)z7TestGreenlet.test_recursive_startup..convolutedcSst|d|_dSr)r __init__countr2rrrrs z@TestGreenlet.test_recursive_startup..convoluted.__init__cSs.|dkr"|jdkr"d|_|dt||S)Nr5rr+)rrr rrrrrrs zHTestGreenlet.test_recursive_startup..convoluted.__getattribute__cSs|j|qdSrrrr0rcrrrr5sz;TestGreenlet.test_recursive_startup..convoluted.runN)r r rrrr5rrrr convolutedsrrrT)r r-rr)r0rr!rrrtest_recursive_startups z#TestGreenlet.test_recursive_startupcsttGfdddt}dd}fdd}t}t|g|d_dtj |d}|  | t|| d dS) NcseZdZfddZdS)z;TestGreenlet.test_threaded_updatecurrent..finalizedcsdSrreleaseacquirer2lock1lock2rr__del__szCTestGreenlet.test_threaded_updatecurrent..finalized.__del__Nr r rrrrrr finalizedsrcSstjdSrrrrrr deallocatorsz=TestGreenlet.test_threaded_updatecurrent..deallocatorcs:td=tdSrrrrrrr!rrrrfthreadsz9TestGreenlet.test_threaded_updatecurrent..fthreadrrTr\)rVLockrobjectrrr bombrrWr]rr-r^)r0rrrrrvrrrtest_threaded_updatecurrents"     z(TestGreenlet.test_threaded_updatecurrentcsbgfddddtgdtd}|||ddS)Nc sJtj}d=tj_ztj|W5tXdSr)rrrrr)rc initiatorrrrrr8s  z>TestGreenlet.test_dealloc_switch_args_not_lost..workercSsdSrrrrrrrEszATestGreenlet.test_dealloc_switch_args_not_lost..initiatorrr)r rr|r-rrrr!test_dealloc_switch_args_not_lost6s    z.TestGreenlet.test_dealloc_switch_args_not_lostcsTddGdddt}|tddfdd}t|}||dS) NcSs|||dSrr)rrLkrrr_apply^sz0TestGreenlet.test_tuple_subclass.._applyc@seZdZddZdS)z1TestGreenlet.test_tuple_subclass..mytuplecSstt|Sr)rrrtuple__len__r2rrrrbs z9TestGreenlet.test_tuple_subclass..mytuple.__len__N)r r rrrrrrmytupleasrr)rLcstjjdSrrrrrkwargsrr switchapplygsz5TestGreenlet.test_tuple_subclass..switchapply)rdictr r-r)r0rrr!rrrtest_tuple_subclassPs z TestGreenlet.test_tuple_subclasscCsPtdtfdtddi}Gddd|}Gddd|}||t|dS) NAbstractSubclassr5cSsdSrrr2rrrrprz7TestGreenlet.test_abstract_subclasses..c@s eZdZdS)z:TestGreenlet.test_abstract_subclasses..BadSubclassNr rrrr BadSubclassrsrc@seZdZddZdS)z;TestGreenlet.test_abstract_subclasses..GoodSubclasscSsdSrrr2rrrr5vsz?TestGreenlet.test_abstract_subclasses..GoodSubclass.runN)r r rr5rrrr GoodSubclassusr)rr rr6r)r0rrrrrrtest_abstract_subclasseslsz%TestGreenlet.test_abstract_subclassescsNts dStddkr$dSfdd}tdD]}|r:qJq:dS)Nr2c sttdgfdd}tj|d}|GfdddtGfdddt}g}td }t}|}|D]<}d}d r| d dSt }d rq| |qt d r| d dS|j||D]}|j|qd S) NFcstdSrrrrrranother_threadszWTestGreenlet.test_implicit_parent_with_threads..attempt..another_threadrTcseZdZfddZdS)zTTestGreenlet.test_implicit_parent_with_threads..attempt..gc_callbackcsdd<dS)NTrrr2rrrecycledrrrsz\TestGreenlet.test_implicit_parent_with_threads..attempt..gc_callback.__del__Nrrrrr gc_callbacksrcseZdZfddZdS)zPTestGreenlet.test_implicit_parent_with_threads..attempt..garbagecs||_|_dSr)cyclecallbackr2rrrrszYTestGreenlet.test_implicit_parent_with_threads..attempt..garbage.__init__N)r r rrrrrrgarbagesrr*rr\T)rVrrrWr]rr/rrr^r rrgrhr-r) rrvrlrcurrentr!_lastNr0)rrrrrattempts>     z?TestGreenlet.test_implicit_parent_with_threads..attemptr,)rg isenabledZ get_thresholdr/)r0rrrrr!test_implicit_parent_with_threads|s - z.TestGreenlet.test_implicit_parent_with_threadscs|ddlmddlmGdddt}t|}g_fdd}tdD]}||qP` t||dS) Nrr)ric@s eZdZdS)zTTestGreenlet.test_issue_245_reference_counting_subclass_no_threads..GreenletNr rrrrGreenletsrcs8zjWn"k r2jYnXdSr)rrgletsrrrirr0rr greenlet_mainszYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads..greenlet_mainr\) rrrir rrPrr/rr-)r0r initial_refsrrrrr5test_issue_245_reference_counting_subclass_no_threadss    zBTestGreenlet.test_issue_245_reference_counting_subclass_no_threadsz;The manylinux images appear to hang on this test on 3.13rc2c sddlm}ddlm}ddlmGdddtg|fddfd d }t}g}t|d D]*}|}|||fd }| || qx|D]} | d qdd= | |t|dS)Nr)rW)rurc@s eZdZdS)zSTestGreenlet.test_issue_245_reference_counting_subclass_threads..MyGreenletNr rrrr MyGreenletsr csjdSrrrrrrrszVTestGreenlet.test_issue_245_reference_counting_subclass_threads..greenlet_maincs8}||~|ddS)Nr\)rrrrrs)Zgreenlet_running_eventZminer rrrZ ref_clearedrr thread_mains  zTTestGreenlet.test_issue_245_reference_counting_subclass_threads..thread_main-rr\)rVrWrurrr rrPr/rr]rsrrrr-) r0rWrur r Zthread_ready_eventsreventrrrr r2test_issue_245_reference_counting_subclass_threadss.         z?TestGreenlet.test_issue_245_reference_counting_subclass_threadsc CsDdd}t|}dd}t||}|t|W5QRXdS)NcSsdS)N rrrrrno_argssz\TestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error..no_argscSsdSrrrrrrleaf"szYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error..leaf)r r6rr)r0rparent_never_startedrchildrrr>test_falling_off_end_switches_to_unstarted_parent_raises_errors   zKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_errorcCs:dd}t|}dd}t||}|}||ddS)NcSs|dfSNrrrrrone_arg,szUTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works..one_argcSsdSrrrrrrr1szRTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works..leaf)rrr)r0rrrrrrrr7test_falling_off_end_switches_to_unstarted_parent_works+s  zDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_worksc sGdddt}|}gtfdd|}|t|W5QRX|dg|t|W5QRX|dgdS)Nc@seZdZddZdS)zXTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..ParentcSs|dkr tdSr4)r rrrrr;sziTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..Parent.__getattribute__NrrrrrParent:srcs dSrrrrrrrBrzZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent..r)r r6r rr-)r0rrrrrr;test_switch_to_dead_greenlet_with_unstarted_perverse_parent9s  zHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parentcsfgtfdd}tfdd}||dg||_|}|||ddgdS)Ncs dSrrrrrrrPrzDTestGreenlet.test_switch_to_dead_greenlet_reparent..cs dSrrrrrrrQrrr)r rr-rrC)r0rrrrrr%test_switch_to_dead_greenlet_reparentNs z2TestGreenlet.test_switch_to_dead_greenlet_reparentcstfdd}fddt|}|tdd}|||j||jjjd||jj ||jj jjd| |jj j dS) Ncs dSrrrinnerrrouterbszHTestGreenlet.test_can_access_f_back_of_suspended_greenlet..outercstddSr)rrryrrrrr eszHTestGreenlet.test_can_access_f_back_of_suspended_greenlet..innercSsdSrrrrrrrnrzKTestGreenlet.test_can_access_f_back_of_suspended_greenlet..r r!) rrr rr?r}r-f_codeco_namerzrC)r0r!r unrelatedrr rr,test_can_access_f_back_of_suspended_greenlet\s    z9TestGreenlet.test_can_access_f_back_of_suspended_greenletcsddlmddlmfddt}|d|j}tdD]}||j d||j }qH||j dd| |j ||d d dS) Nr)partialr)_test_extension_cppcs.|dkr ||dStjS)Nrr)Z test_callrrrr)rpr)r(recurserrr+}sz@TestGreenlet.test_get_stack_with_nested_c_calls..recurser,rpr\i) functoolsr(r)r rr}r/r-rrzrC)r0grrrYrr*r"test_get_stack_with_nested_c_callsys     z/TestGreenlet.test_get_stack_with_nested_c_callscsdtfdd}fddt|}|}tdd}|||jjd||jdS)NcstddSr)rryrrrrr!sz6TestGreenlet.test_frames_always_exposed..outercs|dSr)r)rr"rrr sz6TestGreenlet.test_frames_always_exposed..innercSsdSrrrrrrrrz9TestGreenlet.test_frames_always_exposed..r!) rrr rr-r#r$rCrz)r0r!r.rr%rr&rtest_frames_always_exposeds   z'TestGreenlet.test_frames_always_exposedN)F)4r r rr1r3r<r>rBrDrJrQr`rdrfrjrqunittestZskipIfrrrwrrrrrrrrrrrrr rrrrrrrrrr rrrrrr'r/r0rrrrr$2sn  ,      9  /7 Cr$c@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)TestGreenletSetParentErrorsc sittfdd}dd}tj|d}|dt|}||t}d|_ W5QRX | d| t |jddS) Ncs&tddd<ddS)NcSsdSrrrrrrrrzQTestGreenletSetParentErrors.test_threaded_reparent..run..r!r\rrrrrr5sz?TestGreenletSetParentErrors.test_threaded_reparent..runcSstjdSrrrrrrblankszATestGreenletSetParentErrors.test_threaded_reparent..blankrTr\r!z&parent cannot be on a different thread)rVrurWr]rsr rr6rrrrr^r-r9r:)r0r5r3rr!rrrrtest_threaded_reparents    z2TestGreenletSetParentErrors.test_threaded_reparentc sgfdd}tj|d}||d|j|jddGfdddt}|d d }|tj }| W5QRX| t |j d dd=dS) Ncs"tdd}||dS)NcSsdSrrrrrrrrzYTestGreenletSetParentErrors.test_unexpected_reparenting..worker..)r rrrNanotherrrrs  zGTestGreenletSetParentErrors.test_unexpected_reparenting..workerrTr\r)Zinitial_main_greenletscseZdZfddZdS)zKTestGreenletSetParentErrors.test_unexpected_reparenting..convolutedcs|dkrd|_t||SNr5rrr rrr5rrrs z\TestGreenletSetParentErrors.test_unexpected_reparenting..convoluted.__getattribute__Nrrr5rrrsrcSsdSrrrrrrrrzITestGreenletSetParentErrors.test_unexpected_reparenting..r)rVrWr]r^rZmain_greenlets_before_testr r6rrrr-r9r:)r0rrvrr!rrr5rtest_unexpected_reparentings     z7TestGreenletSetParentErrors.test_unexpected_reparentingc sgttfdd}Gfdddt}tj|d}|dzf|dd}|t j }| W5QRX| d t |j| d t |j| d t |jW5|ddd=XdS) Ncs4tdd}||ddS)NcSsdSrrrrrrrrzhTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..worker..r\)r rrrrrsrNr6Zkeep_main_aliveZswitched_to_greenletrrrs   zVTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..workercseZdZfddZdS)zZTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..convolutedcs|dkrd|_t||Sr7r8rr5rrrs zkTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..convoluted.__getattribute__Nrrr5rrrsrrTr\cSsdSrrrrrrrrzXTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running..z#Cannot switch to a different threadZExpectedZCurrent)rVrur rWr]rsrrr^r6rrrr8r9r:)r0rrrvr!rrr:r*test_unexpected_reparenting_thread_runnings$    zFTestGreenletSetParentErrors.test_unexpected_reparenting_thread_runningc CsNtdd}||jt|t }|`W5QRX|t|j ddS)NcSsdSrrrrrrr rzGTestGreenletSetParentErrors.test_cannot_delete_parent..can't delete attribute) r r@rrrr6r7r-r9r:)r0rrrrrtest_cannot_delete_parent s   z5TestGreenletSetParentErrors.test_cannot_delete_parentc Cs4|t}t`W5QRX|t|jddS)Nr<r6r7rrrr-r9r:r0rrrr!test_cannot_delete_parent_of_mains z=TestGreenletSetParentErrors.test_cannot_delete_parent_of_maincCs|tjdSr)rCrrrr2rrr!test_main_greenlet_parent_is_nonesz=TestGreenletSetParentErrors.test_main_greenlet_parent_is_nonecsTdd}fdd}t|}||||||||dS)NcSstjdSrrrrrrbgszCTestGreenletSetParentErrors.test_set_parent_wrong_types..bgc sNdddfD]<}t }||_W5QRXt|jdt|jq dS)NrZ42z4GreenletChecker: Expected any type of greenlet, not )r6rrr-r9r:typer )gletprr2rrcheck#s  zFTestGreenletSetParentErrors.test_set_parent_wrong_types..check)r r~rr|)r0rBrFr!rr2rtest_set_parent_wrong_typess   z7TestGreenletSetParentErrors.test_set_parent_wrong_typesc Cs>tdd}|t }||_W5QRX|t|jddS)NcSsdSrrrrrrr;rz@TestGreenletSetParentErrors.test_trivial_cycle..cyclic parent chain)r r6rrr-r9r:)r0rDrrrrtest_trivial_cycle:s  z.TestGreenletSetParentErrors.test_trivial_cyclec Cs:|t}tt_W5QRX|t|jddS)Nz(cannot set the parent of a main greenletr>r?rrrtest_trivial_cycle_main@s z3TestGreenletSetParentErrors.test_trivial_cycle_mainc Csbtdd}tdd}tdd}||_||_|t }||_W5QRX|t|jddS)NcSsdSrrrrrrrGrz?TestGreenletSetParentErrors.test_deeper_cycle..cSsdSrrrrrrrHrcSsdSrrrrrrrIrrH)r rr6rr-r9r:)r0r"rbZg3rrrrtest_deeper_cycleFs    z-TestGreenletSetParentErrors.test_deeper_cycleN) r r rr4r9r;r=r@rArGrIrJrKrrrrr2s)$r2c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)TestReprcCs|||||fdSr)r|endswith)r0gotsuffixrrrassertEndsWithTszTestRepr.assertEndsWithcCstt}||ddS)N current active started main>)reprrrrPr0rrrrtest_main_while_runningWs z TestRepr.test_main_while_runningcs4tfdd}t|}|}||ddS)NcstSr)rRrr"rrr5]sz-TestRepr.test_main_in_background..run suspended active started main>)rrr rrP)r0r5r!rTrr"rtest_main_in_background[s  z TestRepr.test_main_in_backgroundcCstt}||ddS)Nz pending>)rRr rPrSrrr test_initialds zTestRepr.test_initialcstGfdddtj}|}||d||jd||jdt dD]}t dqZt dD](}| |j jt|j }||dqrdS) Ncs$eZdZdZZdZfddZdS)z/TestRepr.test_main_from_other_thread..TNcs$t|_t|_t|j|_dSr)rR original_mainrr main_gletr r2r"rrr5ns  z3TestRepr.test_main_from_other_thread..T.run)r r rrYr rZr5rr"rrTksr[r\rVrQr%gMbP?z (thread exited) dead>)rrrVrWr]r^rPrYr r/rrr|rZrHrR)r0r[rvrrTrr"rtest_main_from_other_threadhs     z$TestRepr.test_main_from_other_threadcCsXtdd}||t|d|dt||dt||dt|dS)NcSsdSrrrrrrrrz$TestRepr.test_dead..z dead>Z suspendedstartedZactive)r rrPrRZ assertNotInrArrr test_deads  zTestRepr.test_deadcCsXtdd}tdd}t}|||fD](}|d|ft|d|ftq*dS)NcSsdSrrrrrrrrz>TestRepr.test_formatting_produces_native_str..cSsdSrrrrrrrrz%sz%r)r rrassertIsInstancer9)r0Zg_deadZ g_not_startedZg_curr!rrr#test_formatting_produces_native_strs  z,TestRepr.test_formatting_produces_native_strN) r r rrPrUrWrXr\r^r`rrrrrLRs #rLc@s$eZdZddZddZddZdS)TestMainGreenletcCs4dttksttt}dt|ks0t|S)Nr)rRrrAssertionErrorrC)r0rvrrr_check_current_is_mains z'TestMainGreenlet._check_current_is_maincCs$|}td|fi}||dS)Nsubclass)rcrCr?)r0Z main_typerdrrr)test_main_greenlet_type_can_be_subclassedsz:TestMainGreenlet.test_main_greenlet_type_can_be_subclassedcCs||ttdSr)rcr_rrr r2rrrtest_main_greenlet_is_greenletsz/TestMainGreenlet.test_main_greenlet_is_greenletN)r r rrcrerfrrrrrasrac@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)TestBrokenGreenletsc Cs>dd}tj|}d|_|td|W5QRXdS)NcSs tddS)NzNever get here)rbrrrrrsz.funcTz;Failed to switch stacks into a greenlet for the first time.)r _greenletUnswitchableGreenletforce_switch_errorassertRaisesRegex SystemErrorrrrrrtest_failed_to_initialstubs z.TestBrokenGreenlets.test_failed_to_initialstubc sgfdd}tj|}||dg||ddgd|_|td|W5QRXd|_||dddgdS) Ncs>dtjdtjddS)Nrr*r%r&rrunsrrrs   zDTestBrokenGreenlets.test_failed_to_switch_into_running..funcrr*Tz0Failed to switch stacks into a running greenlet.Fr%)rrhrirr-rjrkrlrrrnr"test_failed_to_switch_into_runnings  z6TestBrokenGreenlets.test_failed_to_switch_into_runningcCs.|d}|d|j||j|dS)Nzfail_slp_switch.pyzfail_slp_switch is running)assertScriptRaisesr8output returncodeZ,get_expected_returncodes_for_aborted_processr0exrrr&test_failed_to_slp_switch_into_runnings z:TestBrokenGreenlets.test_failed_to_slp_switch_into_runningcCsV|d}|d||d||d||d||d||d|dS)Nzfail_switch_two_greenlets.pyz In g1_runTRACEz LEAVE TRACEzFalling off end of mainzFalling off end of g1_runzFalling off end of g2 run_scriptr8r0rrrrr#test_reentrant_switch_two_greenletss      z7TestBrokenGreenlets.test_reentrant_switch_two_greenletscCs.|jddd}|d|j|d|jdS)Nzfail_switch_three_greenlets.py)r)Z exitcodesrzpositional arguments)rqr8rrrtrrr%test_reentrant_switch_three_greenletssz9TestBrokenGreenlets.test_reentrant_switch_three_greenletscCs|d}|d|dS)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')]rxrzrrr&test_reentrant_switch_three_greenlets2s  z:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2cCs|d}|d|dS)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)]rxrzrrr4test_reentrant_switch_GreenletAlreadyStartedInPythons  zHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPythoncCs|d}|d|dS)Nzfail_clearing_run_switches.pyzRESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]rxrzrrr*test_reentrant_switch_run_callable_has_del!s  z>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_delN) r r rrmrprvr{r|r}r~rrrrrrgs    rg__main__)rgrrrVr1abcrrrr r-rrrZ leakcheckr rlr rr#r$r2rLrargr rrrrrs:         y.Um