
    Yh                     T   S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SKrS SKJr	  SSK
Jr  SSK
Jr  SSK
Jr  SS	K
Jr  SS
KJr   " S S\5      rS rS r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\S:X  a  \R6                  " 5         gg)    N)ABCMeta)abstractmethod)greenlet   )TestCase)RUNNING_ON_MANYLINUX)PY313)PY314)fails_leakcheckc                       \ rS rSrSrg)	SomeError    N__name__
__module____qualname____firstlineno____static_attributes__r       N/var/www/html/env/lib/python3.13/site-packages/greenlet/tests/test_greenlet.pyr   r      s    r   r   c                      [         R                  " 5       R                  R                  5         [        e!   U R	                  [
        R                  " 5       S   5        e = fNr   )r   
getcurrentparentswitchappendsysexc_infor   seens    r   fmainr"   !   sJ    $$++- OCLLN1%&s	   -5 *Ac                 >    S n[        X S9nUR                  U5        g )Nc                     U eNr   )excs    r   crashersend_exception.<locals>.crasher-   s    	r   r   RawGreenletr   )gr&   r'   g1s       r   send_exceptionr.   *   s    	W	'BIIcNr   c                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS r\R$                  " \=(       a    \S5      S 5       rS rS rS rS rS rS rS rS rS rS rS r S r!\"S2S j5       r#\"S 5       r$S r%\"S  5       r&S! r'S" r(S# r)S$ r*S% r+S& r,\R$                  " \=(       a    \S'5      S( 5       r-S) r.S* r/S+ r0S, r1S- r2S. r3S/ r4S0r5g1)3TestGreenlet3   c                   ^ / mU4S jn[        U5      nTR                  S5        UR                  5         TR                  S5        UR                  5         TR                  S5        U R                  T[	        [        S5      5      5        g )Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         T R                  S5        g )Nr      r   r   r   r   r   lsts   r   f'TestGreenlet._do_simple_test.<locals>.f8   s4    JJqM!((//1JJqMr   r            )r+   r   r   assertEquallistrange)selfr8   r,   r7   s      @r   _do_simple_testTestGreenlet._do_simple_test5   sc    	 N

1	


1	


1d58n-r   c                 $    U R                  5         g r%   )rA   r@   s    r   test_simpleTestGreenlet.test_simpleD   s    r   c                     [        5       nU R                  [        5       nUR                  5         S S S 5        U R	                  S[        WR                  5      5        g ! , (       d  f       N4= fNrun)r+   assertRaisesAttributeErrorr   assertInstr	exceptionr@   r,   r&   s      r   (test_switch_no_run_raises_AttributeError5TestGreenlet.test_switch_no_run_raises_AttributeErrorG   sI    M~.#HHJ / 	eS/0 /.s   A
A-c                     [        5       nU R                  [        5       nUR                  [        5        S S S 5        U R                  S[        WR                  5      5        g ! , (       d  f       N4= frH   )r+   rJ   rK   throwr   rL   rM   rN   rO   s      r   'test_throw_no_run_raises_AttributeError4TestGreenlet.test_throw_no_run_raises_AttributeErrorN   sL    M~.#GGI / 	eS/0 /.s   A$$
A2c                     [        S S9nU R                  U5        U R                  UR                  [        R
                  " 5       5        g )Nr)   )r+   assertIsNotNoneassertIsr   r   r   r@   r,   s     r   test_parent_equals_None$TestGreenlet.test_parent_equals_NoneU   s5    t$Qahh 3 3 56r   c                 n    [        S S9nU R                  U5        U R                  UR                  5        g )N)rI   )r+   rW   assertIsNonerI   rY   s     r   test_run_equals_None!TestGreenlet.test_run_equals_NoneZ   s,    D!Q!%% r   c                 
  ^ / mU4S jn[        U5      n[        U5      nUR                  5         U R                  [        T5      S5        UR                  5         U R                  [        T5      S5        UR                  5         U R                  [        T5      S5        U R                  UR                  S5        UR                  5         U R                  [        T5      S5        U R                  UR                  S5        g )Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         T R                  SS/5        g )Nr   )r   r   r   r   r   extendr6   s   r   r8   )TestGreenlet.test_two_children.<locals>.fb   s9    JJqM!((//1JJ1vr   r   r:   r;   T   )r+   r   r=   lendead)r@   r8   r,   hr7   s       @r   test_two_childrenTestGreenlet.test_two_children_   s    	 NN	
S1%	
S1%	
S1%&	
S1%&r   c                   ^^ / mU4S jmUU4S jnU R                  [        R                  " U5      [        (       d  SOS5        [	        U5      nU R                  [        R                  " U5      [        (       d  SOS5        UR                  5         U R                  T/ SQ5        U R                  [        R                  " U5      [        (       d  S5        g S5        g )Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         g )Nbr5   r6   s   r   r8   3TestGreenlet.test_two_recursive_children.<locals>.fv   s)    JJsO!((//1r   c                     > TR                  S5        [        T5      n U R                  5         TR                  S5        g )Nac)r   r+   r   )r,   r8   r7   s    r   r,   3TestGreenlet.test_two_recursive_children.<locals>.gz   s+    JJsOAAHHJJJsOr   r:   r   )ro   rl   rp   )r=   r   getrefcountr
   r+   r   )r@   r,   r8   r7   s     @@r   test_two_recursive_children(TestGreenlet.test_two_recursive_childrens   s    	2	
 	+eeQCN 	+eeQC	
o.+eeQCCr   c                 ,  ^ ^ / mU U4S jn[        S5       Vs/ s H  n[        R                  " US9PM     nnU H  nUR                  5         M     U H  nUR	                  S5        M     T R                  [        T5      [        U5      5        g s  snf )Nc                  H   > T R                  5         TR                  S5        g NT)rA   r   )r@   successs   r   r8   $TestGreenlet.test_threads.<locals>.f   s      "NN4 r   
   target)r?   	threadingThreadstartjoinr=   re   )r@   r8   ithsthrx   s   `    @r   test_threadsTestGreenlet.test_threads   sw    	! 499=9ayq)9=BHHJ BGGBK Ws3x0 >s   Bc                    / n[        [        5      n[        [        5      nUR                  U5        UR                  U5        X#l        U R	                  U/ 5        U R                  [        UR                  5        U R	                  U[        /5        UR                  5       nU R	                  US5        U R	                  U[        /5        UR                  S5      nU R	                  US5        U R	                  U[        /5        g )Nr      )r+   r"   r   r   r=   rJ   r   )r@   r!   r-   g2values        r   test_exceptionTestGreenlet.test_exception   s    
		$
		$	r" 	)RYY/	{+		#	{+		"#	{+r   c                     / n[        [        5      nUR                  U5        U R                  [        [
        U[        5        U R                  U[        /5        g r%   )r+   r"   r   rJ   KeyErrorr.   r=   )r@   r!   r-   s      r   test_send_exception TestGreenlet.test_send_exception   sB    
		$(NBAz*r   c                    / n[        [        5      n[        [        5      nUR                  U5        UR                  U5        U R                  U/ 5        A[        R
                  " 5         U R                  U[        R                  /5        A[        R
                  " 5         U R                  U[        R                  [        R                  /5        g r%   )r+   r"   r   r=   gccollectr   GreenletExit)r@   r!   r-   r   s       r   test_deallocTestGreenlet.test_dealloc   s    
		$
		$r"


 5 567


 5 5x7L7LMNr   c                 V   S n[        U5      nUR                  5         [        R                  nSSKJn  U" 5       =n[        l         AU[        l        UR                  5       nU R                  SU5        U R                  SU5        U R                  SU5        g ! U[        l        f = f)Nc                       [         R                  " 5       R                  R                  5         g ! [         R                   a    [
        S ef = fr%   )r   r   r   r   r   r   r   r   r   rI   HTestGreenlet.test_dealloc_catches_GreenletExit_throws_other.<locals>.run   s?    *##%,,335(( *T)*s	   -0 Ar   )StringIO	Exceptionignoredr   )r+   r   r   stderrior   getvaluerL   )r@   rI   r,   	oldstderrr   r   vs          r   .test_dealloc_catches_GreenletExit_throws_other;TestGreenlet.test_dealloc_catches_GreenletExit_throws_other   s    	* 	

 JJ	&j(	#"CJOOk1%i#k1% #CJs   B B(z=Sometimes flaky (getting one GreenletExit in the second list)c                 .  ^^^^^^ / m/ m[         R                  " 5       m[         R                  " 5       m[         R                  " 5       m[         R                  " 5       mUUUUUU4S jn[         R                  " US9nUR                  5         TR	                  S5        U R                  T/ 5        U R                  [        T5      S5        TS S 2	 [        R                  " 5         U R                  T/ 5        TR                  5         TR	                  S5         U R                  T[        R                  /5        TR                  5         UR                  S5        TS S 2	 TS S 2	 g ! TR                  5         UR                  S5        TS S 2	 TS S 2	 f = f)Nc                  @  > [        [        5      n U R                  T5        TR                  U 5        A [        R
                  " 5         TR                  5         TR                  S5        [        5         TR                  5         TR                  S5        [        5         g )Nr4   )r+   r"   r   r   r   r   setwait)r-   /bg_glet_created_running_and_no_longer_ref_in_bgbg_should_be_clearfg_ref_releasedok_to_exit_bg_threadr!   somerefs    r   r8   1TestGreenlet.test_dealloc_other_thread.<locals>.f   sn    U#BIIdONN2JJL;??A  #M""$ %%a(Mr   r{   rz   r   r4   )r}   Eventr~   r   r   r=   re   r   r   r   r   r   r   )	r@   r8   tr   r   r   r   r!   r   s	      @@@@@@r   test_dealloc_other_thread&TestGreenlet.test_dealloc_other_thread   s?    :C//:K7#//+&__.(0	 	 A&		7<<R@r"Wq)AJ


r""	TH$9$9#:; $$&FF2JQ
 !$$&FF2JQ
s   !E' '-Fc                 @  ^  U 4S jn[        U5      nUR                  5       nT R                  X2R                  L 5        T R                  U5        UR                  5       nT R	                  U5        T R                  US5        T R                  UR                  S 5        g )Nc                     > [         R                  " S5      n TR                  U R                  S 5        [        R
                  " 5       R                  R                  U 5        g)Nr   meaning of life)r   	_getframer=   f_backr   r   r   r   )r8   r@   s    r   f1#TestGreenlet.test_frame.<locals>.f1  sE    a AQXXt,!((//2$r   r   )r+   r   
assertTruegr_frameassertFalser=   )r@   r   r,   framefrom_gs   `    r   
test_frameTestGreenlet.test_frame  s{    	%
 O
+,!23T*r   c                     S n[         R                  " USS9n[         R                  " USS9nUR                  5         UR                  5         UR                  S5        UR                  S5        g )Nc                 D   ^  [        U 4S j5      nUR                  5         g )Nc                  0   > [         R                  " T 5      $ r%   )timesleepxs   r   <lambda>>TestGreenlet.test_thread_bug.<locals>.runner.<locals>.<lambda>'  s    DJJqMr   r*   )r   r,   s   ` r   runner,TestGreenlet.test_thread_bug.<locals>.runner&  s    12AHHJr   )g?r|   args)g333333?rz   )r}   r~   r   r   )r@   r   t1t2s       r   test_thread_bugTestGreenlet.test_thread_bug%  sU    	 V&9V&9





r   c                 h   ^  U 4S jn[        U5      R                  SSS9nT R                  US5        g )Nc                 N   > TR                  U S5        TR                  US5        g)Nr;   r:   *   )r=   )ro   rl   r@   s     r   rI   ,TestGreenlet.test_switch_kwargs.<locals>.run1  s&    Q"Q"r   r;   r:   )ro   rl   r   r+   r   r=   )r@   rI   r   s   `  r   test_switch_kwargsTestGreenlet.test_switch_kwargs0  s4    	 ##a1#-Br   c                     S n[        U5      nU R                  SS0UR                  S5      5        U R                  SSS04UR                  5       5        U R                  SUR                  5       5        g )Nc                     [         R                  " 5       R                  R                  U S9  [         R                  " 5       R                  R                  SSS9  X S-  4$ )Nr   r:   r4   r   r   r   r   r   s    r   rI   6TestGreenlet.test_switch_kwargs_to_parent.<locals>.run9  sP    !((//!/4!((//Q/71f9r   r   r4   )r:   )r4   	   )r+   r=   r   )r@   rI   r,   s      r   test_switch_kwargs_to_parent)TestGreenlet.test_switch_kwargs_to_parent8  sd    	 #q188A;/$a)188:6,r   c                   ^^^ 0 m[         R                  " 5       m[         R                  " 5       mUUU4S jn[         R                  " US9nUR                  5         TR	                  S5        U R                  [        R                  5         TS   R                  5         S S S 5        TR                  5         UR                  S5        TR                  5         g ! , (       d  f       N@= f)Nc                  f   > [        S 5      TS'   T R                  5         TR                  S5        g )Nc                      g r%   r   r   r   r   r   ITestGreenlet.test_switch_to_another_thread.<locals>.run.<locals>.<lambda>H      Dr   r,   rz   r+   r   r   created_eventdata
done_events   r   rI   7TestGreenlet.test_switch_to_another_thread.<locals>.runG  )    #L1DIOOBr   r{   rz   r,   )r}   r   r~   r   r   rJ   r   errorr   r   r   clear)r@   rI   threadr   r   r   s      @@@r   test_switch_to_another_thread*TestGreenlet.test_switch_to_another_threadB  s    !)__&
	  !!-2x~~.I /B

 /.s   C
C(c                 T   ^ ^ UU 4S jnU 4S jm[        U5      R                  5         g )Nc                     >  [        S5      e!   [        R                  " 5       n [        T5      R	                  5         TR                  U [        R                  " 5       5         g = f)Nfun)
ValueErrorr   r   r+   r   r=   )r   rg   r@   s    r   r8   &TestGreenlet.test_exc_state.<locals>.fV  sK    ; '';<<>A%%'  3<<>:s
    AA%c                  P   > T R                  [        R                  " 5       S5        g )N)NNN)r=   r   r   rD   s   r   rg   &TestGreenlet.test_exc_state.<locals>.h^  s    S\\^-?@r   r*   )r@   r8   rg   s   ` @r   test_exc_stateTestGreenlet.test_exc_stateU  s     	;	A 	Ar   c                    S nS nS n[        U5      nU R                  UR                  0 5        UR                  5         U R                  UR                  S5        U R                  UR                  SS05        UR                  Ul        U R                  UR                  SS05        U R                  [        X$5        U R                  [        X4S5        g )Nc                  8    S[         R                  " 5       l        g Nr   )r   r   testr   r   r   r8   *TestGreenlet.test_instance_dict.<locals>.fd  s    )+H!&r   c                     U ? g r%   __dict__)r,   s    r   deldict0TestGreenlet.test_instance_dict.<locals>.deldictf  s    
r   c                     Xl         g r%   r   )r,   r   s     r   setdict0TestGreenlet.test_instance_dict.<locals>.setdicth  s    Jr   r   r   )r+   r=   r   r   r   rJ   	TypeError)r@   r8   r   r  r,   s        r   test_instance_dictTestGreenlet.test_instance_dictc  s    	,		NR(	
$fb\2ZZ
fb\2)W0)W4r   c                 r   ^ / mU4S jn[        U5      nUR                  5         U R                  TS/5        g )Nc                  b   > T R                  [        [        R                  " 5       S5      5        g rH   )r   hasattrr   r   )has_runs   r   func;TestGreenlet.test_running_greenlet_has_no_run.<locals>.funcv  s"    NN++-u5r   Fr   )r@   r  r,   r  s      @r    test_running_greenlet_has_no_run-TestGreenlet.test_running_greenlet_has_no_runt  s4    	
 	
5'*r   c                     SS K nU R                  [        UR                   [        5       5        U R                  [        UR                  [        5       5        g r   )copyrJ   r  r+   deepcopy)r@   r  s     r   test_deepcopyTestGreenlet.test_deepcopy  s5    )TYY>)T]]KMBr   c                 2  ^^^ [        S 5      m[        R                  " 5       m/ mUUU4S jn[        UTS9nUR                  5         AU R	                  T5        U R                  TS   T5        U R                  TS   R                  T5        TS S 2	 S mS mg )Nc                      g r%   r   r   r   r   r   ;TestGreenlet.test_parent_restored_on_kill.<locals>.<lambda>  s    $r   c                     >  TR                  5         g ! [        R                   ae    TR                  [        R                  " 5       R
                  5        TR                  [        R                  " 5       5        T R                  5          g f = fr%   )r   r   r   r   r   r   )hubmainresults   r   worker9TestGreenlet.test_parent_restored_on_kill.<locals>.worker  s_    (( h113::;h1134

	s    A6BBr)   r   r   )r+   r   r   r   r   rX   r   )r@   r  r,   r  r  r  s      @@@r   test_parent_restored_on_kill)TestGreenlet.test_parent_restored_on_kill  s    ,'""$	 s+	
fQi&fQi&&, 1Ir   c                     [        5       n[        S US9nU R                  [        5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nc                      g r%   r   r   r   r   r   9TestGreenlet.test_parent_return_failure.<locals>.<lambda>      r   r)   )r+   rJ   rK   r   )r@   r-   r   s      r   test_parent_return_failure'TestGreenlet.test_parent_return_failure  s8    ]b1~.IIK /..s   A
Ac                      " S S[         5      nU" S 5      nU R                  [        UR                  [        5       5        g )Nc                       \ rS rSrS rSrg)>TestGreenlet.test_throw_exception_not_lost.<locals>.mygreenleti  c                 J     [         e!    O= f[        R                  " X5      $ r%   )r   r+   __getattribute__r@   names     r   r*  OTestGreenlet.test_throw_exception_not_lost.<locals>.mygreenlet.__getattribute__  s'    #O"33D??s    r   Nr   r   r   r   r*  r   r   r   r   
mygreenletr(    s    @r   r/  c                      g r%   r   r   r   r   r   <TestGreenlet.test_throw_exception_not_lost.<locals>.<lambda>      tr   )r+   rJ   r   rS   )r@   r/  r,   s      r   test_throw_exception_not_lost*TestGreenlet.test_throw_exception_not_lost  s4    	@ 	@ |$)QWWik:r   c                   ^^^ / mS mUUU4S jn[         R                  " US9nUR                  5         UR                  S5        AT(       a  U R	                  5         U R                  [        R                  5       nTS   R                  [        5        S S S 5        T(       d6  [        WR                  5      nU R                  US:H  =(       d    SU;   5        O%U R                  [        WR                  5      S5        [        TS   R                  S5      (       a;  U R                  [         5         TS   R                  R#                  5         S S S 5        T(       dP  [        TS   R                  R$                  S5      (       a'  TS   R                  R$                  R#                  5         OU R'                  TS   R                  5        AS mTS S 2	 S	U l        g ! , (       d  f       GNO= f! , (       d  f       N= f)
Nc                  ^    [         R                  " 5       R                  R                  5         g r%   r   r   r   r   r  GTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.worker      !((//1r   c                     > [        T5      n U R                  5         TR                  U 5        T(       a&  U R                  5         [        R                  " 5         g g r%   )r+   r   r   r   r   )r,   r  wait_for_cleanupr  s    r   creatorHTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.creator  s?    F#AHHJMM!
##%  r   r{   rz   r   Bcannot switch to a different thread (which happens to have exited)zCannot switchr   T)r}   r~   r   r   wait_for_pending_cleanupsrJ   r   r   rS   r   rM   rN   r   r=   r
  r   RuntimeErrorr   f_localsr]   expect_greenlet_leak)r@   r:  r;  r   r&   sr  r  s    `    @@r   *_do_test_throw_to_dead_thread_doesnt_crash7TestGreenlet._do_test_throw_to_dead_thread_doesnt_crash  s   	2	& G,			r
 **,x~~.#1IOOI& /  CMM"AOOYY ("a'
 CMM"T
 6!9%%w//""<0q	""((* 1  vay))22G<<q	""++113fQi0011I %)!C /." 10s   =G3G0
G-0
G>c                 $    U R                  5         g r%   rC  rD   s    r   &test_throw_to_dead_thread_doesnt_crash3TestGreenlet.test_throw_to_dead_thread_doesnt_crash  s    779r   c                 &    U R                  S5        g rw   rF  rD   s    r   +test_throw_to_dead_thread_doesnt_crash_wait8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_wait  s    77=r   c                      " S S[         5      nU" 5       nU R                  UR                  S5      S5        SU l        g )Nc                   &    \ rS rSrS rS rS rSrg)7TestGreenlet.test_recursive_startup.<locals>.convolutedi  c                 >    [         R                  " U 5        SU l        g r   )r+   __init__countrD   s    r   rP  @TestGreenlet.test_recursive_startup.<locals>.convoluted.__init__  s    $$T*
r   c                     US:X  a(  U R                   S:X  a  SU l         U R                  S5        [        R                  " X5      $ )NrI   r   r   +   )rQ  r   r+   r*  r+  s     r   r*  HTestGreenlet.test_recursive_startup.<locals>.convoluted.__getattribute__  s6    5=TZZ1_!"DJKKO"33D??r   c                 >     U R                   R                  U5        M  r%   r   r   )r@   r   s     r   rI   ;TestGreenlet.test_recursive_startup.<locals>.convoluted.run  s    KK&&u- r   )rQ  N)r   r   r   r   rP  r*  rI   r   r   r   r   
convolutedrN    s    @
.r   rY  r   rT  T)r+   r=   r   rA  )r@   rY  r,   s      r   test_recursive_startup#TestGreenlet.test_recursive_startup  s9    	. 	. L"r*
 %)!r   c                 T  ^^^ [         R                  " 5       mTR                  5         [         R                  " 5       mTR                  5          " UU4S jS[        5      nS nUUU4S jn[        R
                  " 5       n[        U5      /mU" 5       TS   l        TS   R                  5         [         R                  " US9nUR                  5         TR                  5         TR                  5         U R                  [        R
                  " 5       U5        UR                  S5        g )Nc                   $   > \ rS rSrU U4S jrSrg);TestGreenlet.test_threaded_updatecurrent.<locals>.finalizedi  c                 F   > TR                  5         TR                  5         g r%   releaseacquire)r@   lock1lock2s    r   __del__CTestGreenlet.test_threaded_updatecurrent.<locals>.finalized.__del__  s     r   r   Nr   r   r   r   re  r   rc  rd  s   r   	finalizedr^    s       r   ri  c                  ^    [         R                  " 5       R                  R                  5         g r%   r   r   r   r   deallocator=TestGreenlet.test_threaded_updatecurrent.<locals>.deallocator  r8  r   c                     > TR                  5         [        R                  " 5         T S	 TR                  5         TR                  5         [        R                  " 5         TR                  5         g r   rb  r   r   ra  )r,   rc  rd  s   r   fthread9TestGreenlet.test_threaded_updatecurrent.<locals>.fthread  sF    MMO!!MMOMMO!MMOr   r   r{   rz   )r}   Lockrb  objectr   r   r+   bombr   r~   r   ra  r=   r   )	r@   ri  rk  ro  r  r   r,   rc  rd  s	         @@@r   test_threaded_updatecurrent(TestGreenlet.test_threaded_updatecurrent
  s      	  	  	 	2	 ""$%&K!		!G,		 	,,.5	r
r   c                    ^^^ / mUUU4S jmS m[        T5      /mTS   R                  5         [        TTS   5      mTR                  5       nU R                  T5        U R                  US5        g )Nc                    > [         R                  " 5       R                  R                  5       n TS	 [         R                  " 5       R                  Tl         [         R                  " 5       R                  R                  U 5        TR	                  [         R                  " 5       5        g ! TR	                  [         R                  " 5       5        f = fr   )r   r   r   r   r   )r   	initiatorr!   r  s    r   r  >TestGreenlet.test_dealloc_switch_args_not_lost.<locals>.worker;  s    '')00779Eq	'224;;I3##%,,33E:H//12H//12s   .B* *&Cc                      gr   r   r   r   r   rx  ATestGreenlet.test_dealloc_switch_args_not_lost.<locals>.initiatorH      r   r   r   )r+   r   r   r=   )r@   r   rx  r!   r  s     @@@r   !test_dealloc_switch_args_not_lost.TestGreenlet.test_dealloc_switch_args_not_lost9  sk    	3	 f%&q		6!95	  "#r   c                    ^^^ S m " S S[         5      nU" 5       m[        SS9mUUU4S jn[        U5      nU R                  UR	                  5       T5        g )Nc                     U " U0 UD6  g r%   r   )r  ro   ks      r   _apply0TestGreenlet.test_tuple_subclass.<locals>._applya  s    !MqMr   c                       \ rS rSrS rSrg)1TestGreenlet.test_tuple_subclass.<locals>.mytupleid  c                 r    [         R                  " 5       R                  5         [        R	                  U 5      $ r%   )r   r   r   tuple__len__rD   s    r   r  9TestGreenlet.test_tuple_subclass.<locals>.mytuple.__len__e  s&    ##%,,.}}T**r   r   N)r   r   r   r   r  r   r   r   r   mytupler  d  s    +r   r  r   )ro   c                  h   > T " [         R                  " 5       R                  R                  TT5        g r%   r   )r  r   kwargss   r   switchapply5TestGreenlet.test_tuple_subclass.<locals>.switchapplyj  s$    8&&(//66fEr   )r  dictr+   r=   r   )r@   r  r  r,   r  r   r  s       @@@r   test_tuple_subclass TestGreenlet.test_tuple_subclassS  sL    		+e 	+ y	F$V,r   c                     [        S[        4S[        S 5      05      n " S SU5      n " S SU5      nU" 5         U R                  [        U5        g )NAbstractSubclassrI   c                     g r%   r   rD   s    r   r   7TestGreenlet.test_abstract_subclasses.<locals>.<lambda>s  s    r   c                       \ rS rSrSrg):TestGreenlet.test_abstract_subclasses.<locals>.BadSubclassiu  r   Nr   r   r   r   BadSubclassr  u      r   r  c                       \ rS rSrS rSrg);TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclassix  c                     g r%   r   rD   s    r   rI   ?TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclass.runy  s    r   r   N)r   r   r   r   rI   r   r   r   r   GoodSubclassr  x  s    r   r  )r   r+   r   rJ   r  )r@   r  r  r  s       r   test_abstract_subclasses%TestGreenlet.test_abstract_subclasseso  sT    "NN#4568
	* 		+ 	 	)[1r   c                    ^ ^ [         R                  " 5       (       d  g [         R                  " 5       S   mTS:  a  g UU 4S jn[        S5       H  nU" 5       (       d  M    g    g )Nr   2   c                  $  >^	^
^^ [         R                  " 5       m
T
R                  5         [         R                  " 5       mTR                  5         S/mU
U4S jn [         R                  " U S9nUR	                  5          " U
UU4S jS[
        5      m	 " U	4S jS[
        5      n/ n[        TS-  5      n[        R                  " 5       nU" 5       nU HI  nS nTS	   (       a  UR                  S
5          g[        5       nTS	   (       a    OFUR                  U5        MK     [        R                  " 5         TS	   (       a  UR                  S
5        gTR                  UR                  U5        U H  nTR                  UR                  U5        M!     g)NFc                  p   > T R                  5         [        R                  " 5         TR                  5         g r%   rn  rh  s   r   another_threadWTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.another_thread  s!    ##%r   r{   c                   &   > \ rS rSrU UU4S jrSrg)TTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callbacki  c                 P   > TR                  5         TR                  5         STS'   g )NTr   r`  )r@   rc  rd  recycleds    r   re  \TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callback.__del__  s    MMOMMO"&HQKr   r   Nrg  )rc  rd  r  s   r   gc_callbackr    s    ' 'r   r  c                   "   > \ rS rSrU 4S jrSrg)PTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbagei  c                 *   > X l         T" 5       U l        g r%   )cyclecallback)r@   r  s    r   rP  YTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbage.__init__  s    !%J$/MDMr   )r  r  N)r   r   r   r   rP  r   )r  s   r   garbager    s    2 2r   r  r:   r   rz   T)r}   rq  rb  r~   r   rr  r?   r   r   r   r+   r   r   r   r=   r   )r  r   r  lr   currentr,   _lastr  rc  rd  r  Nr@   s            @@@@r   attempt?TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt  s/   NN$EMMONN$EMMOwH    7AGGI' 'f '
2& 2 Aac
A))+G	AA;FF2J "}A;  

A;FF2JT[['2  73 r   r<   )r   	isenabledget_thresholdr?   )r@   r  r  r  s   `  @r   !test_implicit_parent_with_threads.TestGreenlet.test_implicit_parent_with_threads  sN    ||~~q!r6,	Z qAyy r   c                 *  ^ ^^ SSK Jm  SSK Jm   " S S[        5      n[        R
                  " U5      n/ T l        UUU 4S jn[        S5       H  nU" U5      R                  5         M     T ?T R                  [        R
                  " U5      U5        g )Nr   r   )r   c                       \ rS rSrSrg)TTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.Greenleti  r   Nr   r   r   r   Greenletr    r  r   r  c                     >  T" 5       R                   R                  5         g ! T  a#    TR                  R                  T" 5       5         g f = fr%   )r   r   gletsr   )r   r   r@   s   r   greenlet_mainYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.greenlet_main  s?    0##**, 0

!!*,/0s   # &AArz   )
r   r   r   r+   r   rr   r  r?   r   r=   )r@   r  initial_refsr  r  r   r   s   `    @@r   5test_issue_245_reference_counting_subclass_no_threadsBTestGreenlet.test_issue_245_reference_counting_subclass_no_threads  sv     	()	{ 	 x0 
	0 rA]#**,  J2LAr   z;The manylinux images appear to hang on this test on 3.13rc2c                   ^
^^^^ SSK Jn  SSK Jn  SSKJm   " S S[
        5      m
/ mU" 5       mU4S jmU
UUUU4S jn[        R                  " T
5      n/ n[        US	-   5       H2  nU" 5       nU" X74S
9nUR                  U5        UR                  5         M4     U H  n	U	R                  S5        M     TS S 2	 TR                  5         U R                  5         U R                  [        R                  " T
5      U5        g )Nr   )r~   )r   r  c                       \ rS rSrSrg)STestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.MyGreenleti  r   Nr   r   r   r   
MyGreenletr    r  r   r  c                  D   > T " 5       R                   R                  5         g r%   rW  r  s   r   r  VTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.greenlet_main  s    L&&(r   c                    > T" T5      nTR                  U5        UR                  5         AU R                  5         TR                  S5        T" 5         g )Nrz   )r   r   r   r   )greenlet_running_eventminer  r   r  r  ref_cleareds     r   thread_mainTTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.thread_main  sH    m,DLLKKM"&&( R  Lr   -   r   rz   )r}   r~   r   r   r   r+   r   rr   r?   r   r   r   r   r>  r=   )r@   r~   r   r  r  thread_ready_eventsr  eventr   r   r  r   r  r  r  s             @@@@@r   2test_issue_245_reference_counting_subclass_threads?TestGreenlet.test_issue_245_reference_counting_subclass_threads  s     	%#'	 	 g	)	 	8 z2 r!
A GE;X>F&&u-LLN
 .JOOB . !H 	&&(4lCr   c                     S n[        U5      nS n[        X25      nU R                  [        5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nc                      g)N   r   r   r   r   no_args\TestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.no_args   r|  r   c                      gr   r   r   r   r   leafYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.leaf%  r|  r   )r+   rJ   r  r   )r@   r  parent_never_startedr  childs        r   >test_falling_off_end_switches_to_unstarted_parent_raises_errorKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error  sJ    	  +73	 D7 y)LLN *))s   A
Ac                     S n[        U5      nS n[        X25      nUR                  5       nU R                  US5        g )Nc                 
    U S4$ N   r   r   s    r   one_argUTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.one_arg/  s    r7Nr   c                      gr   r   r   r   r   r  RTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.leaf4  r|  r   )r   r  r   )r@   r  r  r  r  r  s         r   7test_falling_off_end_switches_to_unstarted_parent_worksDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.  s@    	  +73	 D7*r   c                   ^  " S S[         5      nU" 5       n/ m[        U4S jU5      nU R                  [        5         UR                  5         S S S 5        U R	                  TS/5        U R                  [        5         UR                  5         S S S 5        U R	                  TS/5        g ! , (       d  f       Nc= f! , (       d  f       N3= f)Nc                       \ rS rSrS rSrg)XTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parenti=  c                     US:X  a  [         eg rH   )r   r+  s     r   r*  iTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parent.__getattribute__>  s    5=#O !r   r   Nr.  r   r   r   Parentr  =  s    $r   r  c                  &   > T R                  S5      $ r   r   r    s   r   r   ZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.<lambda>E      DKKOr   r   )r+   rJ   r   r   r=   )r@   r  r  r  r!   s       @r   ;test_switch_to_dead_greenlet_with_unstarted_perverse_parentHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent<  s    	$[ 	$  &x35IJ y)LLN * 	t$y)LLN *t$ *)
 *)s   B- B>-
B;>
Cc                   ^ / m[        U4S j5      n[        U4S j5      nUR                  5         U R                  TS/5        Xl        UR                  5       nU R	                  U5        U R                  TSS/5        g )Nc                  &   > T R                  S5      $ r  r  r    s   r   r   DTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>S  s    4;;r?r   c                  &   > T R                  S5      $ r   r  r    s   r   r   r   T  r  r   r   r  )r+   r   r=   r   r]   )r@   r  r  r  r!   s       @r   %test_switch_to_dead_greenlet_reparent2TestGreenlet.test_switch_to_dead_greenlet_reparentQ  sl    *+BC34t$+&!Bx(r   c                 j  ^^ [         R                  " 5       mU4S jnU4S jm[        U5      nUR                  5         [        S 5      nUR                  5         U R	                  UR
                  5        U R                  UR
                  R                  R                  S5        U R	                  UR
                  R                  5        U R                  UR
                  R                  R                  R                  S5        U R                  UR
                  R                  R                  5        g )Nc                     > T " 5         g r%   r   inners   r   outerHTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.outere  s    Gr   c                  P   > T R                  [        R                  " S5      5        g r   )r   r   r   r  s   r   r  HTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.innerh  s    KKa()r   c                      g r%   r   r   r   r   r   KTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.<lambda>q      r   r  r  )r   r   r+   r   rW   r   r=   f_codeco_namer   r]   )r@   r  r  	unrelatedr  r  s       @@r   ,test_can_access_f_back_of_suspended_greenlet9TestGreenlet.test_can_access_f_back_of_suspended_greenlet_  s     ""$		* % 

  -	 	S\\*,,44g>S\\001,,33;;WE#,,--445r   c                   ^^^ SSK Jm  SSKJm  UUU4S jm[	        T5      nUR                  S5        UR                  n[        S5       H.  nU R                  UR                  S   U5        UR                  nM0     U R                  UR                  S   S5        U R                  UR                  5        U R                  UR                  S5      S	5        g )
Nr   )partialr   )_test_extension_cppc                    > U S:  a  U TR                  T" TU S-
  5      5      -  $ [        R                  " 5       R                  R	                  5       $ )Nr   r   )	test_callr   r   r   r   )r   r  r  recurses    r   r  @TestGreenlet.test_get_stack_with_nested_c_calls.<locals>.recurse  sJ    1u.88!a%9PQQQ&&(//6688r   r<   r   rz   i  )	functoolsr   r  r+   r   r   r?   r=   r@  r   r]   )r@   grr   r   r  r  r  s       @@@r   "test_get_stack_with_nested_c_calls/TestGreenlet.test_get_stack_with_nested_c_calls|  s    %)	9
 !
		!qAU^^C0!4LLE  	,a0%,,'2-r   c                 :  ^^ [         R                  " 5       mU4S jnU4S jm[        U5      nUR                  5       n[        S 5      nUR                  5         U R	                  UR
                  R                  S5        U R                  UR                  5        g )Nc                  >   > T " [         R                  " S5      5        g r   )r   r   r  s   r   r  6TestGreenlet.test_frames_always_exposed.<locals>.outer  s    #--"#r   c                 (   > TR                  U 5        g r%   )r   )r   r  s    r   r  6TestGreenlet.test_frames_always_exposed.<locals>.inner  s    KKr   c                      g r%   r   r   r   r   r   9TestGreenlet.test_frames_always_exposed.<locals>.<lambda>  r  r   r  )	r   r   r+   r   r=   r  r  r]   r   )r@   r  r  r   r  r  r  s        @@r   test_frames_always_exposed'TestGreenlet.test_frames_always_exposed  sx     ""$	$	 		  -	--w7%,,'r   )rA  r  N)F)6r   r   r   r   rA   rE   rP   rT   rZ   r^   rh   rs   r   r   r   r   r   unittestskipIfr	   r   r   r   r   r   r   r   r   r  r  r  r  r$  r3  r   rC  rG  rJ  rZ  rt  r}  r  r  r  r  r  r  r  r  r  r  r  r(  r   r   r   r   r0   r0   3   s`   .117
!
'(D,1,8+O&6 __&&G**X+ 	 -& 5"	+C
6	; 7) 7)r : :> ) )*-^$4-82 5nB> __&&EADADF+%*)6:.&(r   r0   c                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)TestGreenletSetParentErrorsi  c                   ^^^ 0 m[         R                  " 5       m[         R                  " 5       mUUU4S jnS n[         R                  " US9nUR                  5         TR	                  S5        [        U5      nUR                  5         U R                  [        5       nTS   Ul	        S S S 5        TR                  5         UR                  S5        U R                  [        WR                  5      S5        g ! , (       d  f       NU= f)Nc                  f   > [        S 5      TS'   T R                  5         TR                  S5        g )Nc                      g r%   r   r   r   r   r   QTestGreenletSetParentErrors.test_threaded_reparent.<locals>.run.<locals>.<lambda>  r   r   r,   rz   r   r   s   r   rI   ?TestGreenletSetParentErrors.test_threaded_reparent.<locals>.run  r   r   c                  ^    [         R                  " 5       R                  R                  5         g r%   r   r   r   r   blankATestGreenletSetParentErrors.test_threaded_reparent.<locals>.blank  r8  r   r{   rz   r,   z&parent cannot be on a different thread)r}   r   r~   r   r   r+   r   rJ   r   r   r   r   r=   rM   rN   )	r@   rI   r4  r   r,   r&   r   r   r   s	         @@@r   test_threaded_reparent2TestGreenletSetParentErrors.test_threaded_reparent  s    !)__&
	 
	2 !!-2	
z*cCyAH +BS]]+-UV +*s    C::
Dc                   ^ / mU4S jn[         R                  " US9nUR                  5         UR                  S5        U R	                  U R
                  S-   S9   " U4S jS[        5      nU" S 5      nU R                  [        R                  5       nUR                  5         S S S 5        U R                  [        WR                  5      S	5        TS S 2	 g ! , (       d  f       N9= f)
Nc                  `   > [        S 5      n TR                  U 5        U R                  5         g )Nc                      g r%   r   r   r   r   r   YTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker.<locals>.<lambda>      Dr   )r+   r   r   )r,   anothers    r   r  GTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker  s"    L)ANN1HHJr   r{   rz   r   )initial_main_greenletsc                   "   > \ rS rSrU 4S jrSrg)KTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convolutedi  c                 P   > US:X  a
  TS   U l         [        R                  " X5      $ NrI   r   r   r+   r*  r@   r,  r=  s     r   r*  \TestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convoluted.__getattribute__  &    5=")!*DK"33D??r   r)   Nr.  r=  s   r   rY  rA        @ @r   rY  c                      g r%   r   r   r   r   r   ITestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.<lambda>  r2  r   r=  )r}   r~   r   r   r>  main_greenlets_before_testr+   rJ   r   r   r   r=   rM   rN   )r@   r  r   rY  r,   r&   r=  s         @r   test_unexpected_reparenting7TestGreenletSetParentErrors.test_unexpected_reparenting  s    	 F+			r
& 	&&d>]>]`a>a&b	@ 	@
 |$x~~.#HHJ /S]]+]	_AJ	 /.s   C
C'c                 &  ^^^ / m[         R                  " 5       m[         R                  " 5       mUUU4S jn " U4S jS[        5      n[         R                  " US9nUR	                  5         TR                  S5         U" S 5      nU R                  [        R                  5       nUR                  5         S S S 5        U R                  S[        WR                  5      5        U R                  S[        UR                  5      5        U R                  S	[        UR                  5      5        TR                  5         UR                  S5        TS S 2	 g ! , (       d  f       N= f! TR                  5         UR                  S5        TS S 2	 f = f)
Nc                     > [        S 5      n TR                  U 5        U R                  5         TR                  5         TR	                  S5        g )Nc                      g r%   r   r   r   r   r   hTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.worker.<locals>.<lambda>  r<  r   rz   )r+   r   r   r   r   )r,   r=  keep_main_aliveswitched_to_greenlets    r   r  VTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.worker  s<    L)ANN1HHJ $$&  $r   c                   "   > \ rS rSrU 4S jrSrg)ZTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convolutedi  c                 P   > US:X  a
  TS   U l         [        R                  " X5      $ rC  rD  rE  s     r   r*  kTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convoluted.__getattribute__  rG  r   r)   Nr.  rH  s   r   rY  rW    rI  r   rY  r{   rz   c                      g r%   r   r   r   r   r   XTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.<lambda>      4r   z#Cannot switch to a different threadExpectedCurrent)r}   r   r+   r~   r   r   rJ   r   r   r   rL   rM   rN   r   r   )	r@   r  rY  r   r,   r&   r=  rS  rT  s	         @@@r   *test_unexpected_reparenting_thread_runningFTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running  s    (0#//+	%	@ 	@ F+		!!"%	<(A""8>>2c
 3MM?S]]ASTMM*c#--&89MM)S%78!FF2J
 32 !FF2J
s%    (E( (E9A7E( 
E%!E( ((Fc                 &   [        S 5      nU R                  UR                  [        R                  " 5       5        U R                  [        5       nU?S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nc                      g r%   r   r   r   r   r   GTestGreenletSetParentErrors.test_cannot_delete_parent.<locals>.<lambda>      Tr   can't delete attribute)
r+   rX   r   r   r   rJ   rK   r=   rM   rN   )r@   r  r&   s      r   test_cannot_delete_parent5TestGreenletSetParentErrors.test_cannot_delete_parent  sd    \*fmmX%8%8%:;~.# /S]]+-EF /.s   B
Bc                     U R                  [        5       n[        R                  " 5       ?S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nre  rJ   rK   r   r   r   r=   rM   rN   r@   r&   s     r   !test_cannot_delete_parent_of_main=TestGreenletSetParentErrors.test_cannot_delete_parent_of_main  sI    ~.###%, /S]]+-EF /.s   A
A(c                 `    U R                  [        R                  " 5       R                  5        g r%   )r]   r   r   r   rD   s    r   !test_main_greenlet_parent_is_none=TestGreenletSetParentErrors.test_main_greenlet_parent_is_none  s    (--/667r   c                    ^  S nU 4S jn[        U5      nT R                  U5        U" U5        UR                  5         T R                  U5        U" U5        UR                  5         g )Nc                  ^    [         R                  " 5       R                  R                  5         g r%   r   r   r   r   bgCTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.bg"  s    !((//1r   c                    > S STS4 Hb  nTR                  [        5       nXl        S S S 5        TR                  [	        WR
                  5      S[        U5      R                  -   5        Md     g ! , (       d  f       NN= f)Nr   42z4GreenletChecker: Expected any type of greenlet, not )rJ   r  r   r=   rM   rN   typer   )gletpr&   r@   s      r   checkFTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.check&  sg    1dD(&&y1S"#K 2   &JTRSWM]M]]_	 )11s   A//
A=	)r+   r   r   r   )r@   rr  ry  r,   s   `   r   test_set_parent_wrong_types7TestGreenletSetParentErrors.test_set_parent_wrong_types!  sW    	2	_ Oa 	

a 	

r   c                     [        S 5      nU R                  [        5       nXl        S S S 5        U R	                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nc                      g r%   r   r   r   r   r   @TestGreenletSetParentErrors.test_trivial_cycle.<locals>.<lambda>>  r\  r   cyclic parent chain)r+   rJ   r   r   r=   rM   rN   )r@   rw  r&   s      r   test_trivial_cycle.TestGreenletSetParentErrors.test_trivial_cycle=  sI    <(z*cK +S]]+-BC +*s   A
A%c                    U R                  [        5       n[        R                  " 5       [        R                  " 5       l        S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nz(cannot set the parent of a main greenletri  rj  s     r   test_trivial_cycle_main3TestGreenletSetParentErrors.test_trivial_cycle_mainC  sT    ~.#+3+>+>+@H!( /S]]+-WX /.s   .A22
B c                    [        S 5      n[        S 5      n[        S 5      nX!l        X2l        U R                  [        5       nXl        S S S 5        U R	                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nc                      g r%   r   r   r   r   r   ?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>J  r#  r   c                      g r%   r   r   r   r   r   r  K  r#  r   c                      g r%   r   r   r   r   r   r  L  r#  r   r  )r+   r   rJ   r   r=   rM   rN   )r@   r-   r   g3r&   s        r   test_deeper_cycle-TestGreenletSetParentErrors.test_deeper_cycleI  sg    &&&		z*cI +S]]+-BC +*s   A;;
B	r   N)r   r   r   r   r6  rM  r_  rf  rk  rn  r{  r  r  r  r   r   r   r   r-  r-    s<    W2'R"HGG88DY	Dr   r-  c                   >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)TestRepriU  c                 H    U R                  UR                  U5      X45        g r%   )r   endswith)r@   gotsuffixs      r   assertEndsWithTestRepr.assertEndsWithW  s    V,sm<r   c                 d    [        [        R                  " 5       5      nU R                  US5        g )N current active started main>)reprr   r   r  r@   rs     r   test_main_while_running TestRepr.test_main_while_runningZ  s&    $$&'A>?r   c                    ^ [         R                  " 5       mU4S jn[        U5      nUR                  5       nU R	                  US5        g )Nc                     > [        T 5      $ r%   )r  r  s   r   rI   -TestRepr.test_main_in_background.<locals>.run`  s    :r    suspended active started main>)r   r   r+   r   r  )r@   rI   r,   r  r  s       @r   test_main_in_background TestRepr.test_main_in_background^  s>    ""$	 HHJA@Ar   c                 N    [        [        5       5      nU R                  US5        g )Nz	 pending>)r  r+   r  r  s     r   test_initialTestRepr.test_initialg  s    A{+r   c                 4  ^ [         R                  " 5       m " U4S jS[        R                  5      nU" 5       nUR	                  5         UR                  S5        U R                  UR                  S5        U R                  UR                  S5        [        S5       H  n[        R                  " S5        M     [        S5       HO  nU R                  UR                  R                  5        [        UR                  5      nU R                  US5        MQ     g )	Nc                   .   > \ rS rSrS=rrSrU 4S jrSrg)/TestRepr.test_main_from_other_thread.<locals>.Tin  Nc                    > [        T5      U l        [        R                  " 5       U l        [        U R                  5      U l        g r%   )r  original_mainr   r   	main_gletr  )r@   r  s    r   rI   3TestRepr.test_main_from_other_thread.<locals>.T.runq  s0    %)$Z"!)!4!4!6#'#7 r   )r  r  r  )	r   r   r   r   r  r  r  rI   r   r  s   r   Tr  n  s    *..MKI8 8r   r  rz   r  r  r4   gMbP?z (thread exited) dead>)r   r   r}   r~   r   r   r  r  r  r?   r   r   r   r  rf   r  )r@   r  r   r  r  r  s        @r   test_main_from_other_thread$TestRepr.test_main_from_other_threadk  s    ""$	8	   	8 C			r
AOO-NOAMM+JK qAJJu  qAOOAKK,,-Q[[!A#;< r   c                    [        S 5      nUR                  5         U R                  [        U5      S5        U R	                  S[        U5      5        U R	                  S[        U5      5        U R	                  S[        U5      5        g )Nc                      g r%   r   r   r   r   r   $TestRepr.test_dead.<locals>.<lambda>  s    r   z dead>	suspendedstartedactive)r+   r   r  r  assertNotInrY   s     r   	test_deadTestRepr.test_dead  se    %	
DGX.d1g.DG,47+r   c                     [        S 5      n[        S 5      n[        R                  " 5       nXU4 H3  nU R                  U< [        5        U R                  U< [        5        M5     g )Nc                      g r%   r   r   r   r   r   >TestRepr.test_formatting_produces_native_str.<locals>.<lambda>  rd  r   c                      g r%   r   r   r   r   r   r    r   r   )r+   r   r   assertIsInstancerM   )r@   g_deadg_not_startedg_curr,   s        r   #test_formatting_produces_native_str,TestRepr.test_formatting_produces_native_str  s_     \*#L1##%-A!! !! .r   r   N)r   r   r   r   r  r  r  r  r  r  r  r   r   r   r   r  r  U  s(    =@B,!=F,r   r  c                   &    \ rS rSrS rS rS rSrg)TestMainGreenleti  c                     S[        [        R                  " 5       5      ;   d   e[        [        R                  " 5       5      nS[        U5      ;  d   eU$ )Nr  )r  r   r   rv  )r@   r   s     r   _check_current_is_main'TestMainGreenlet._check_current_is_main  sH    h1134444$$&'T!W$$$r   c                 b    U R                  5       n[        SU40 5      nU R                  U5        g )Nsubclass)r  rv  rW   )r@   	main_typer  s      r   )test_main_greenlet_type_can_be_subclassed:TestMainGreenlet.test_main_greenlet_type_can_be_subclassed  s.    //1	
YL"5X&r   c                 v    U R                  5         U R                  [        R                  " 5       [        5        g r%   )r  r  r   r   r+   rD   s    r   test_main_greenlet_is_greenlet/TestMainGreenlet.test_main_greenlet_is_greenlet  s'    ##%h113[Ar   r   N)r   r   r   r   r  r  r  r   r   r   r   r  r    s    '
Br   r  c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)TestBrokenGreenletsi  c                     S n[         R                  R                  U5      nSUl        U R	                  [
        S5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nc                      [        S5      e)NzNever get here)AssertionErrorr   r   r   r  <TestBrokenGreenlets.test_failed_to_initialstub.<locals>.func  s     !122r   Tz;Failed to switch stacks into a greenlet for the first time.)r   	_greenletUnswitchableGreenletforce_switch_errorassertRaisesRegexSystemErrorr   )r@   r  r,   s      r   test_failed_to_initialstub.TestBrokenGreenlets.test_failed_to_initialstub  sW    	3 33D9###K$acHHJc c cs    A
A(c                   ^ / mU4S jn[         R                  R                  U5      nUR                  5         U R	                  TS/5        UR                  5         U R	                  TSS/5        SUl        U R                  [        S5         UR                  5         S S S 5        SUl        UR                  5         U R	                  T/ SQ5        g ! , (       d  f       N:= f)Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         T R                  S5        [        R                  " 5       R                  R	                  5         T R                  S5        g )Nr   r:   r4   r5   )runss   r   r  DTestBrokenGreenlets.test_failed_to_switch_into_running.<locals>.func  sZ    KKN!((//1KKN!((//1KKNr   r   r:   Tz0Failed to switch stacks into a running greenlet.F)r   r:   r4   )r   r  r  r   r=   r  r  r  )r@   r  r,   r  s      @r   "test_failed_to_switch_into_running6TestBrokenGreenlets.test_failed_to_switch_into_running  s    	 33D9	
s#	
1v&###K$VXHHJX  %	
y)X Xs   C
C c                     U R                  S5      nU R                  SUR                  5        U R                  UR                  U R	                  5       5        g )Nzfail_slp_switch.pyzfail_slp_switch is running)assertScriptRaisesrL   output
returncode,get_expected_returncodes_for_aborted_processr@   exs     r   &test_failed_to_slp_switch_into_running:TestBrokenGreenlets.test_failed_to_slp_switch_into_running  sA    $$%9:2BII>bmmT%V%V%XYr   c                     U R                  S5      nU R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        g )Nzfail_switch_two_greenlets.pyz	In g1_runTRACEzLEAVE TRACEzFalling off end of mainzFalling off end of g1_runzFalling off end of g2
run_scriptrL   r@   r  s     r   #test_reentrant_switch_two_greenlets7TestBrokenGreenlets.test_reentrant_switch_two_greenlets  sh    !?@k6*gv&mV,/816:-v6r   c                     U R                  SSS9nU R                  SUR                  5        U R                  SUR                  5        g )Nzfail_switch_three_greenlets.py)r   )	exitcodesr  zpositional arguments)r  rL   r  r  s     r   %test_reentrant_switch_three_greenlets9TestBrokenGreenlets.test_reentrant_switch_three_greenlets  s@     $$%EQU$Vk299-,bii8r   c                 J    U R                  S5      nU R                  SU5        g )Nzfail_switch_three_greenlets2.pya  RESULTS: [('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')]r  r  s     r   &test_reentrant_switch_three_greenlets2:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2  s)     !BC= 		
r   c                 J    U R                  S5      nU R                  SU5        g )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)]r  r  s     r   4test_reentrant_switch_GreenletAlreadyStartedInPythonHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPython  s'    !FG1
 	
r   c                 J    U R                  S5      nU R                  SU5        g )Nzfail_clearing_run_switches.pyzRESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]r  r  s     r   *test_reentrant_switch_run_callable_has_del>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_del$  s'    !@A 	
r   r   N)r   r   r   r   r  r  r  r  r  r  r  r  r   r   r   r   r  r    s+    
*8Z79
$


r   r  __main__)r   r   r   r}   r*  abcr   r   r   r+   r  r   r   r	   r
   	leakcheckr   r   r   r"   r.   r0   r-  r  r  r  r   r  r   r   r   <module>r     s    	 
       ,  "   &		 	r(8 r(jjD( jDZRx RjBx B.k
( k
Z zMMO r   