
    g                     F   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlZd dlmZ	 ddl
mZ ddl
mZ ddl
mZ dd	lmZ  G d
 de      Zd Zd Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zedk(  r ej4                          yy)    N)ABCMeta)abstractmethod)greenlet   )TestCase)RUNNING_ON_MANYLINUX)PY313)fails_leakcheckc                       e Zd Zy)	SomeErrorN__name__
__module____qualname__     \/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/greenlet/tests/test_greenlet.pyr   r      s    r   r   c                     	 t        j                         j                  j                          t        #  | j	                  t        j                         d           xY wNr   )r   
getcurrentparentswitchappendsysexc_infor   seens    r   fmainr       sJ    $$++- OCLLN1%&s	   ,4 )Ac                 F    d }t        ||       }|j                  |       y )Nc                     | Nr   )excs    r   crasherzsend_exception.<locals>.crasher,   s    	r   r   RawGreenletr   )gr"   r#   g1s       r   send_exceptionr)   )   s    	WQ	'BIIcNr   c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z ej"                  exr ed      d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z e!d0d       Z"e!d        Z#d Z$e!d        Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+ ej"                  exr ed&      d'        Z,d( Z-d) Z.d* Z/d+ Z0d, Z1d- Z2d. Z3y/)1TestGreenletc                    g fd}t        |      }j                  d       |j                          j                  d       |j                          j                  d       | j                  t	        t        d                   y )Nc                       j                  d       t        j                         j                  j	                           j                  d       y )Nr      r   r   r   r   r   lsts   r   fz'TestGreenlet._do_simple_test.<locals>.f7   s4    JJqM!((//1JJqMr   r            )r&   r   r   assertEquallistrange)selfr2   r'   r1   s      @r   _do_simple_testzTestGreenlet._do_simple_test4   sc    	 N

1	


1	


1d58n-r   c                 $    | j                          y r!   )r:   r9   s    r   test_simplezTestGreenlet.test_simpleC   s    r   c                     t               }| j                  t              5 }|j                          d d d        | j	                  dt        j                               y # 1 sw Y   /xY wNrun)r&   assertRaisesAttributeErrorr   assertInstr	exceptionr9   r'   r"   s      r   (test_switch_no_run_raises_AttributeErrorz5TestGreenlet.test_switch_no_run_raises_AttributeErrorF   sI    M~.#HHJ / 	eS/0 /.s   AA(c                     t               }| j                  t              5 }|j                  t               d d d        | j                  dt        j                               y # 1 sw Y   /xY wr?   )r&   rA   rB   throwr   rC   rD   rE   rF   s      r   'test_throw_no_run_raises_AttributeErrorz4TestGreenlet.test_throw_no_run_raises_AttributeErrorM   sL    M~.#GGI / 	eS/0 /.s   A$$A-c                     t        d       }| j                  |       | j                  |j                  t	        j
                                y )Nr$   )r&   assertIsNotNoneassertIsr   r   r   r9   r'   s     r   test_parent_equals_Nonez$TestGreenlet.test_parent_equals_NoneT   s5    t$Qahh 3 3 56r   c                 t    t        d       }| j                  |       | j                  |j                         y )N)r@   )r&   rL   assertIsNoner@   rN   s     r   test_run_equals_Nonez!TestGreenlet.test_run_equals_NoneY   s,    D!Q!%% r   c                    g fd}t        |      }t        |      }|j                          | j                  t              d       |j                          | j                  t              d       |j                          | j                  t              d       | j                  |j                  d       |j                          | j                  t              d       | j                  |j                  d       y )Nc                       j                  d       t        j                         j                  j	                           j                  ddg       y )Nr   )r   r   r   r   r   extendr0   s   r   r2   z)TestGreenlet.test_two_children.<locals>.fa   s9    JJqM!((//1JJ1vr   r   r3   r4   T   )r&   r   r6   lendead)r9   r2   r'   hr1   s       @r   test_two_childrenzTestGreenlet.test_two_children^   s    	 NN	
S1%	
S1%	
S1%&	
S1%&r   c                    g fdfd}t        |      }| j                  t        j                  |      d       |j	                          | j                  g d       | j                  t        j                  |      d       y )Nc                       j                  d       t        j                         j                  j	                          y )Nbr/   r0   s   r   r2   z3TestGreenlet.test_two_recursive_children.<locals>.fu   s)    JJsO!((//1r   c                      j                  d       t              } | j                          j                  d       y )Nac)r   r&   r   )r'   r2   r1   s    r   r'   z3TestGreenlet.test_two_recursive_children.<locals>.gy   s+    JJsOAAHHJJJsOr   r3   )r_   r]   r`   )r&   r6   r   getrefcountr   )r9   r'   r2   r1   s     @@r   test_two_recursive_childrenz(TestGreenlet.test_two_recursive_childrenr   sh    	2	 N+Q/	
o.+Q/r   c                      g  fd}t        d      D cg c]  }t        j                  |       }}|D ]  }|j                           |D ]  }|j	                  d         j                  t              t        |             y c c}w )Nc                  H     j                          j                  d       y NT)r:   r   )r9   successs   r   r2   z$TestGreenlet.test_threads.<locals>.f   s      "NN4 r   
   target)r8   	threadingThreadstartjoinr6   rW   )r9   r2   ithsthrf   s   `    @r   test_threadszTestGreenlet.test_threads   sw    	! 499=9ayq)9=BHHJ BGGBK Ws3x0 >s   Bc                    g }t        t              }t        t              }|j                  |       |j                  |       ||_        | j	                  |g        | j                  t        |j                         | j	                  |t        g       |j                         }| j	                  |d       | j	                  |t        g       |j                  d      }| j	                  |d       | j	                  |t        g       y )Nr      )r&   r   r   r   r6   rA   r   )r9   r   r(   g2values        r   test_exceptionzTestGreenlet.test_exception   s    
		$
		$	r" 	)RYY/	{+		#	{+		"#	{+r   c                     g }t        t              }|j                  |       | j                  t        t
        |t               | j                  |t        g       y r!   )r&   r   r   rA   KeyErrorr)   r6   )r9   r   r(   s      r   test_send_exceptionz TestGreenlet.test_send_exception   sB    
		$(NBAz*r   c                    g }t        t              }t        t              }|j                  |       |j                  |       | j                  |g        ~t	        j
                          | j                  |t        j                  g       ~t	        j
                          | j                  |t        j                  t        j                  g       y r!   )r&   r   r   r6   gccollectr   GreenletExit)r9   r   r(   rt   s       r   test_dealloczTestGreenlet.test_dealloc   s    
		$
		$r"


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


 5 5x7L7LMNr   c                 V   d }t        |      }|j                          t        j                  }ddlm}  |       x}t        _        	 ~|t        _        |j                         }| j                  d|       | j                  d|       | j                  d|       y # |t        _        w xY w)Nc                      	 t        j                         j                  j                          y # t         j                  $ r t
        d w xY wr!   )r   r   r   r   r}   r   r   r   r   r@   zHTestGreenlet.test_dealloc_catches_GreenletExit_throws_other.<locals>.run   s?    *##%,,335(( *T)*s	   ,/ A
r   )StringIO	Exceptionignoredr   )r&   r   r   stderrior   getvaluerC   )r9   r@   r'   	oldstderrr   r   vs          r   .test_dealloc_catches_GreenletExit_throws_otherz;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                 &   g g t        j                         t        j                         t        j                         t        j                         fd}t        j                  |      }|j                          j	                  d       | j                  g        | j                  t              d       d d = t        j                          | j                  g        j                          j	                  d       	 | j                  t        j                  g       j                          |j                  d       d d = d d = y # j                          |j                  d       d d = d d = w xY w)Nc                  >   t        t              } | j                         j                  |        ~ t	        j
                          j                          j                  d       t                j                          j                  d       t                y )Nr.   )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   r2   z1TestGreenlet.test_dealloc_other_thread.<locals>.f   sn    U#BIIdONN2JJL;??A  #M""$ %%a(Mr   rh   rg   r   r.   )rj   Eventrk   rl   r   r6   rW   r{   r|   r   r   r}   rm   )	r9   r2   tr   r   r   r   r   r   s	      @@@@@@r   test_dealloc_other_threadz&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                 @     fd}t        |      }|j                         } j                  ||j                  u         j                  |       |j                         } j	                  |        j                  |d        j                  |j                  d        y )Nc                      t        j                  d      } j                  | j                  d        t	        j
                         j                  j                  |        y)Nr   meaning of life)r   	_getframer6   f_backr   r   r   r   )r2   r9   s    r   f1z#TestGreenlet.test_frame.<locals>.f1  sE    a AQXXt,!((//2$r   r   )r&   r   
assertTruegr_frameassertFalser6   )r9   r   r'   framefrom_gs   `    r   
test_framezTestGreenlet.test_frame  s}    	%
 O
+,!23T*r   c                     d }t        j                  |d      }t        j                  |d      }|j                          |j                          |j                  d       |j                  d       y )Nc                 B     t         fd      }|j                          y )Nc                  .    t        j                         S r!   )timesleepxs   r   <lambda>z>TestGreenlet.test_thread_bug.<locals>.runner.<locals>.<lambda>$  s    DJJqMr   r%   )r   r'   s   ` r   runnerz,TestGreenlet.test_thread_bug.<locals>.runner#  s    12AHHJr   )g?ri   args)g333333?rg   )rj   rk   rl   rm   )r9   r   t1t2s       r   test_thread_bugzTestGreenlet.test_thread_bug"  sU    	 V&9V&9





r   c                 l      fd}t        |      j                  dd      } j                  |d       y )Nc                 N    j                  | d       j                  |d       y)Nr4   r3   *   )r6   )r_   r]   r9   s     r   r@   z,TestGreenlet.test_switch_kwargs.<locals>.run.  s&    Q"Q"r   r4   r3   )r_   r]   r   r&   r   r6   )r9   r@   r   s   `  r   test_switch_kwargszTestGreenlet.test_switch_kwargs-  s4    	 ##a1#-Br   c                     d }t        |      }| j                  ddi|j                  d             | j                  dddif|j                                | j                  d|j                                y )Nc                     t        j                         j                  j                  |        t        j                         j                  j                  dd       | | dz  fS )Nr   r3   r.   r   r   r   r   r   s    r   r@   z6TestGreenlet.test_switch_kwargs_to_parent.<locals>.run6  sR    !((//!/4!((//Q/7a1f9r   r   r.   )r3   )r.   	   )r&   r6   r   )r9   r@   r'   s      r   test_switch_kwargs_to_parentz)TestGreenlet.test_switch_kwargs_to_parent5  sd    	 #q188A;/$a)188:6,r   c                    i t        j                         t        j                         fd}t        j                  |      }|j                          j	                  d       | j                  t        j                        5  d   j                          d d d        j                          |j                  d       j                          y # 1 sw Y   ;xY w)Nc                  f    t        d       d<    j                          j                  d       y )Nc                       y r!   r   r   r   r   r   zITestGreenlet.test_switch_to_another_thread.<locals>.run.<locals>.<lambda>E      Dr   r'   rg   r&   r   r   created_eventdata
done_events   r   r@   z7TestGreenlet.test_switch_to_another_thread.<locals>.runD  )    #L1DIOOBr   rh   rg   r'   )rj   r   rk   rl   r   rA   r   errorr   r   rm   clear)r9   r@   threadr   r   r   s      @@@r   test_switch_to_another_threadz*TestGreenlet.test_switch_to_another_thread?  s    !)__&
	  !!-2x~~.I /B

 /.s   CC"c                 P      fd} fdt        |      j                          y )Nc                      	 t        d      #  t        j                         } t              j	                          j                  | t        j                                Y y xY w)Nfun)
ValueErrorr   r   r&   r   r6   )r   rY   r9   s    r   r2   z&TestGreenlet.test_exc_state.<locals>.fS  sK    ; '';<<>A%%'  3<<>:s
    AA#c                  N     j                  t        j                         d       y )N)NNN)r6   r   r   r<   s   r   rY   z&TestGreenlet.test_exc_state.<locals>.h[  s    S\\^-?@r   r%   )r9   r2   rY   s   ` @r   test_exc_statezTestGreenlet.test_exc_stateR  s     	;	A 	Ar   c                    d }d }d }t        |      }| j                  |j                  i        |j                          | j                  |j                  d       | j                  |j                  ddi       |j                  |_        | j                  |j                  ddi       | j                  t        ||       | j                  t        ||d       y )Nc                  6    dt        j                         _        y Nr   )r   r   testr   r   r   r2   z*TestGreenlet.test_instance_dict.<locals>.fa  s    )+H!&r   c                     | ` y r!   __dict__)r'   s    r   deldictz0TestGreenlet.test_instance_dict.<locals>.deldictc  s    
r   c                     || _         y r!   r   )r'   ru   s     r   setdictz0TestGreenlet.test_instance_dict.<locals>.setdicte  s	    AJr   r   r   )r&   r6   r   r   r   rA   	TypeError)r9   r2   r   r   r'   s        r   test_instance_dictzTestGreenlet.test_instance_dict`  s    	,		NR(	
$fb\2ZZ
fb\2)Wa0)Wa4r   c                 p    g fd}t        |      }|j                          | j                  dg       y )Nc                  `     j                  t        t        j                         d             y r?   )r   hasattrr   r   )has_runs   r   funcz;TestGreenlet.test_running_greenlet_has_no_run.<locals>.funcs  s"    NN++-u5r   Fr   )r9   r   r'   r   s      @r    test_running_greenlet_has_no_runz-TestGreenlet.test_running_greenlet_has_no_runq  s4    	
 	
5'*r   c                     dd l }| j                  t        |j                   t                      | j                  t        |j                  t                      y r   )copyrA   r   r&   deepcopy)r9   r   s     r   test_deepcopyzTestGreenlet.test_deepcopy|  s5    )TYY>)T]]KMBr   c                 4   t        d       t        j                         g fd}t        |      }|j                          ~| j	                         | j                  d          | j                  d   j                         d d = d d y )Nc                       y r!   r   r   r   r   r   z;TestGreenlet.test_parent_restored_on_kill.<locals>.<lambda>  s    $r   c                     	 j                          y # t        j                  $ rc j                  t        j                         j
                         j                  t        j                                 j                          Y y w xY wr!   )r   r   r}   r   r   r   )hubmainresults   r   workerz9TestGreenlet.test_parent_restored_on_kill.<locals>.worker  s_    (( h113::;h1134

	s    A3B
	B
r$   r   r   )r&   r   r   r   r   rM   r   )r9   r   r'   r   r   r   s      @@@r   test_parent_restored_on_killz)TestGreenlet.test_parent_restored_on_kill  s    ,'""$	 s+	
fQi&fQi&&, 1Ir   c                     t               }t        d |      }| j                  t              5  |j                          d d d        y # 1 sw Y   y xY w)Nc                       y r!   r   r   r   r   r   z9TestGreenlet.test_parent_return_failure.<locals>.<lambda>      r   r$   )r&   rA   rB   r   )r9   r(   rt   s      r   test_parent_return_failurez'TestGreenlet.test_parent_return_failure  s8    ]b1~.IIK /..s   AAc                      G d dt               } |d       }| j                  t        |j                  t                      y )Nc                       e Zd Zd Zy)>TestGreenlet.test_throw_exception_not_lost.<locals>.mygreenletc                 J    	 t         #  Y nxY wt        j                  | |      S r!   )r   r&   __getattribute__r9   names     r   r   zOTestGreenlet.test_throw_exception_not_lost.<locals>.mygreenlet.__getattribute__  s)    #O"33D$??s    Nr   r   r   r   r   r   r   
mygreenletr     s    @r   r   c                       y r!   r   r   r   r   r   z<TestGreenlet.test_throw_exception_not_lost.<locals>.<lambda>      tr   )r&   rA   r   rI   )r9   r   r'   s      r   test_throw_exception_not_lostz*TestGreenlet.test_throw_exception_not_lost  s4    	@ 	@ |$)QWWik:r   c                    g d fd}t        j                  |      }|j                          |j                  d       ~r| j	                          | j                  t        j                        5 }d   j                  t               d d d        s0t        j                        }| j                  |dk(  xs d|v        n%| j                  t        j                        d       t        d   j                  d      r;| j                  t               5  d   j                  j#                          d d d        sKt        d   j                  j$                  d      rFd   j                  j$                  j#                          n| j'                  d   j                         ~d d d = d	| _        y # 1 sw Y   0xY w# 1 sw Y   xY w)
Nc                  \    t        j                         j                  j                          y r!   r   r   r   r   r   zGTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.worker      !((//1r   c                      t              } | j                          j                  |        r%| j                          t        j                          y y r!   )r&   r   r   r   r   )r'   r   wait_for_cleanupr   s    r   creatorzHTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.creator  s?    F#AHHJMM!
##%  r   rh   rg   r   Bcannot switch to a different thread (which happens to have exited)zCannot switchr   T)rj   rk   rl   rm   wait_for_pending_cleanupsrA   r   r   rI   r   rD   rE   r   r6   r   r   RuntimeErrorr   f_localsrQ   expect_greenlet_leak)r9   r   r  r   r"   sr   r   s    `    @@r   *_do_test_throw_to_dead_thread_doesnt_crashz7TestGreenlet._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   9G G G
Gc                 $    | j                          y r!   r  r<   s    r   &test_throw_to_dead_thread_doesnt_crashz3TestGreenlet.test_throw_to_dead_thread_doesnt_crash  s    779r   c                 &    | j                  d       y re   r
  r<   s    r   +test_throw_to_dead_thread_doesnt_crash_waitz8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_wait  s    77=r   c                      G d dt               } |       }| j                  |j                  d      d       d| _        y )Nc                       e Zd Zd Zd Zd Zy)7TestGreenlet.test_recursive_startup.<locals>.convolutedc                 <    t        j                  |        d| _        y r   )r&   __init__countr<   s    r   r  z@TestGreenlet.test_recursive_startup.<locals>.convoluted.__init__  s    $$T*
r   c                     |dk(  r'| j                   dk(  rd| _         | j                  d       t        j                  | |      S )Nr@   r   r   +   )r  r   r&   r   r   s     r   r   zHTestGreenlet.test_recursive_startup.<locals>.convoluted.__getattribute__  s8    5=TZZ1_!"DJKKO"33D$??r   c                 <    	 | j                   j                  |       r!   r   r   )r9   ru   s     r   r@   z;TestGreenlet.test_recursive_startup.<locals>.convoluted.run  s    KK&&u- r   N)r   r   r   r  r   r@   r   r   r   
convolutedr    s    @
.r   r  r   r  T)r&   r6   r   r  )r9   r  r'   s      r   test_recursive_startupz#TestGreenlet.test_recursive_startup  s9    	. 	. L"r*
 %)!r   c                 L   t        j                         j                          t        j                         j                           G fddt              }d }fd}t	        j
                         }t        |      g |       d   _        d   j                          t        j                  |      }|j                          j                          j                          | j                  t	        j
                         |       |j                  d       y )Nc                       e Zd Z fdZy);TestGreenlet.test_threaded_updatecurrent.<locals>.finalizedc                 F    j                          j                          y r!   releaseacquire)r9   lock1lock2s    r   __del__zCTestGreenlet.test_threaded_updatecurrent.<locals>.finalized.__del__  s     r   Nr   r   r   r#  r!  r"  s   r   	finalizedr    s     r   r&  c                  \    t        j                         j                  j                          y r!   r   r   r   r   deallocatorz=TestGreenlet.test_threaded_updatecurrent.<locals>.deallocator  r   r   c                      j                          t        j                           d= j                          j                          t        j                          j                          y r   r   r   r   r  )r'   r!  r"  s   r   fthreadz9TestGreenlet.test_threaded_updatecurrent.<locals>.fthread  sF    MMO!!MMOMMO!MMOr   r   rh   rg   )rj   Lockr   objectr   r   r&   bombr   rk   rl   r  r6   rm   )	r9   r&  r(  r+  r   r   r'   r!  r"  s	         @@@r   test_threaded_updatecurrentz(TestGreenlet.test_threaded_updatecurrent  s      	  	 	2	 ""$%&K!		!G,		 	,,.5	r
r   c                     g fdd t              gd   j                          t        d         j                         }| j                         | j                  |d       y )Nc                     t        j                         j                  j                         } d= t        j                         j                  _        	 t        j                         j                  j                  |        j	                  t        j                                y # j	                  t        j                                w xY wr   )r   r   r   r   r   )ru   	initiatorr   r   s    r   r   z>TestGreenlet.test_dealloc_switch_args_not_lost.<locals>.worker8  s    '')00779Eq	'224;;I3##%,,33E:H//12H//12s   -B& &%Cc                       yr   r   r   r   r   r2  zATestGreenlet.test_dealloc_switch_args_not_lost.<locals>.initiatorE      r   r   r   )r&   r   r   r6   )r9   ru   r2  r   r   s     @@@r   !test_dealloc_switch_args_not_lostz.TestGreenlet.test_dealloc_switch_args_not_lost6  sk    	3	 f%&q		6!95	  "#r   c                     d  G d dt               } |       t        d      fd}t        |      }| j                  |j	                                y )Nc                      | |i | y r!   r   )r   r_   ks      r   _applyz0TestGreenlet.test_tuple_subclass.<locals>._apply^  s    !MqMr   c                       e Zd Zd Zy)1TestGreenlet.test_tuple_subclass.<locals>.mytuplec                 p    t        j                         j                          t        j	                  |       S r!   )r   r   r   tuple__len__r<   s    r   r>  z9TestGreenlet.test_tuple_subclass.<locals>.mytuple.__len__b  s&    ##%,,.}}T**r   N)r   r   r   r>  r   r   r   mytupler;  a  s    +r   r?  r   )r_   c                  f      t        j                         j                  j                         y r!   r   )r9  r   kwargss   r   switchapplyz5TestGreenlet.test_tuple_subclass.<locals>.switchapplyg  s$    8&&(//66fEr   )r=  dictr&   r6   r   )r9   r?  rB  r'   r9  r   rA  s       @@@r   test_tuple_subclassz TestGreenlet.test_tuple_subclassP  sL    		+e 	+ y	F$V,r   c                     t        dt        fdt        d       i      } G d d|      } G d d|      } |        | j                  t        |       y )NAbstractSubclassr@   c                      y r!   r   r<   s    r   r   z7TestGreenlet.test_abstract_subclasses.<locals>.<lambda>p  s    r   c                       e Zd Zy):TestGreenlet.test_abstract_subclasses.<locals>.BadSubclassNr   r   r   r   BadSubclassrI  r      r   rJ  c                       e Zd Zd Zy);TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclassc                      y r!   r   r<   s    r   r@   z?TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclass.runv  s    r   N)r   r   r   r@   r   r   r   GoodSubclassrM  u  s    r   rO  )r   r&   r   rA   r   )r9   rF  rJ  rO  s       r   test_abstract_subclassesz%TestGreenlet.test_abstract_subclassesl  sT    "NN#4568
	* 		+ 	 	)[1r   c                      t        j                         sy t        j                         d   dk  ry  fd}t        d      D ]  } |       s y  y )Nr   2   c                    	
 t        j                         

j                          t        j                         j                          dg
fd} t        j                  |       }|j	                           G 
fddt
              	 G 	fddt
              }g }t        dz        }t        j                         } |       }|D ]>  }d }d	   r|j                  d
        yt               }d	   r n>|j                  |       @ t        j                          d	   r|j                  d
       yj                  |j                  |       |D ]  }j                  |j                  |         y)NFc                  n     j                          t        j                          j                          y r!   r*  r%  s   r   another_threadzWTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.another_thread  s!    ##%r   rh   c                       e Zd Z fdZy)TTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callbackc                 P    j                          j                          dd<   y )NTr   r  )r9   r!  r"  recycleds    r   r#  z\TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callback.__del__  s    MMOMMO"&HQKr   Nr$  )r!  r"  rY  s   r   gc_callbackrW    s    'r   rZ  c                       e Zd Z fdZy)PTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbagec                 ,    | | _                 | _        y r!   )cyclecallback)r9   rZ  s    r   r  zYTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbage.__init__  s    !%DJ$/MDMr   N)r   r   r   r  )rZ  s   r   garbager\    s    2r   r`  r3   r   rg   T)rj   r,  r   rk   rl   r-  r8   r   r   rm   r&   r   r{   r|   r6   r   )rU  r   r`  lr   currentr'   _lastrZ  r!  r"  rY  Nr9   s            @@@@r   attemptz?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   r5   )r{   	isenabledget_thresholdr8   )r9   rf  rc  re  s   `  @r   !test_implicit_parent_with_threadsz.TestGreenlet.test_implicit_parent_with_threads|  sJ    ||~q!r6,	Z qAy r   c                      ddl m ddl m  G d dt              }t	        j
                  |      }g  _         fd}t        d      D ]  } ||      j                            ` j                  t	        j
                  |      |       y )Nr   r   )r}   c                       e Zd Zy)TTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.GreenletNr   r   r   r   Greenletrm    rK  r   rn  c                      	         j                   j                          y #  $ r# j                  j                                 Y y w xY wr!   )r   r   gletsr   )r}   r   r9   s   r   greenlet_mainzYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.greenlet_main  s?    0##**, 0

!!*,/0s   # %A
Arg   )
r   r   r}   r&   r   ra   rp  r8   r   r6   )r9   rn  initial_refsrq  rc  r}   r   s   `    @@r   5test_issue_245_reference_counting_subclass_no_threadszBTestGreenlet.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                   
 ddl m} ddl m} ddlm  G d dt
              
g  |       fd
fd}t        j                  
      }g }t        |d	z         D ]5  } |       } |||f
      }|j                  |       |j                          7 |D ]  }	|	j                  d        d d = j                          | j                          | j                  t        j                  
      |       y )Nr   )rk   )r   rk  c                       e Zd Zy)STestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.MyGreenletNr   r   r   r   
MyGreenletrv    rK  r   rw  c                  D             j                   j                          y r!   r  rk  s   r   rq  zVTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.greenlet_main  s    L&&(r   c                            }j                  |       |j                          ~| j                          j                  d                y )Nrg   )r   r   r   r   )greenlet_running_eventminerw  r   rp  rq  ref_cleareds     r   thread_mainzTTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.thread_main  sH    m,DLLKKM"&&( R  Lr   -   r   rg   )rj   rk   r   r   r   r&   r   ra   r8   r   rl   r   r   r  r6   )r9   rk   r   r}  rr  thread_ready_eventsrc  eventr   r   rw  r   rp  rq  r|  s             @@@@@r   2test_issue_245_reference_counting_subclass_threadsz?TestGreenlet.test_issue_245_reference_counting_subclass_threads  s     	%#'	 	 g	)	 	8 z2 r!
A GE;eX>F&&u-LLN
 .JOOB . !H 	&&(4lCr   c                     d }t        |      }d }t        ||      }| j                  t              5  |j                          d d d        y # 1 sw Y   y xY w)Nc                       y)N   r   r   r   r   no_argsz\TestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.no_args  r4  r   c                       yr   r   r   r   r   leafzYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.leaf"  r4  r   )r&   rA   r   r   )r9   r  parent_never_startedr  childs        r   >test_falling_off_end_switches_to_unstarted_parent_raises_errorzKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error  sM    	  +73	 D"67 y)LLN *))s   AAc                     d }t        |      }d }t        ||      }|j                         }| j                  |d       y )Nc                 
    | dfS N   r   r   s    r   one_argzUTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.one_arg,  s    r7Nr   c                       yr   r   r   r   r   r  zRTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.leaf1  r4  r   )r   r  r   )r9   r  r  r  r  r   s         r   7test_falling_off_end_switches_to_unstarted_parent_workszDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works+  sC    	  +73	 D"67*r   c                     G d dt               } |       }g t        fd|      }| j                  t              5  |j                          d d d        | j	                  dg       | j                  t              5  |j                          d d d        | j	                  dg       y # 1 sw Y   ^xY w# 1 sw Y   )xY w)Nc                       e Zd Zd Zy)XTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parentc                     |dk(  rt         y r?   )r   r   s     r   r   ziTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parent.__getattribute__;  s    5=#O !r   Nr   r   r   r   Parentr  :  s    $r   r  c                  &     j                  d      S r   r   r   s   r   r   zZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.<lambda>B      DKKOr   r   )r&   rA   r   r   r6   )r9   r  r  r  r   s       @r   ;test_switch_to_dead_greenlet_with_unstarted_perverse_parentzHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent9  s    	$[ 	$  &x35IJ y)LLN * 	t$y)LLN *t$ *)
 *)s   B,?B8,B58Cc                     g t        fd      }t        fd      }|j                          | j                  dg       ||_        |j                         }| j	                  |       | j                  ddg       y )Nc                  &     j                  d      S r  r  r   s   r   r   zDTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>P  s    4;;r?r   c                  &     j                  d      S r   r  r   s   r   r   zDTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>Q  r  r   r   r  )r&   r   r6   r   rQ   )r9   r  r  r   r   s       @r   %test_switch_to_dead_greenlet_reparentz2TestGreenlet.test_switch_to_dead_greenlet_reparentN  sn    *+BC34t$+&!Bx(r   c                 d   t        j                         fd}fdt        |      }|j                          t        d       }|j                          | j	                  |j
                         | j                  |j
                  j                  j                  d       | j	                  |j
                  j                         | j                  |j
                  j                  j                  j                  d       | j                  |j
                  j                  j                         y )Nc                                y r!   r   inners   r   outerzHTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.outerb  s    Gr   c                  N     j                  t        j                  d             y r   )r   r   r   r   s   r   r  zHTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.innere  s    KKa()r   c                       y r!   r   r   r   r   r   zKTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.<lambda>n      r   r  r  )r   r   r&   r   rL   r   r6   f_codeco_namer   rQ   )r9   r  r   	unrelatedr  r   s       @@r   ,test_can_access_f_back_of_suspended_greenletz9TestGreenlet.test_can_access_f_back_of_suspended_greenlet\  s     ""$		* % 

  -	 	S\\*,,44g>S\\001,,33;;WE#,,--445r   c                    ddl m ddlm fdt	              }|j                  d       |j                  }t        d      D ]-  }| j                  |j                  d   |       |j                  }/ | j                  |j                  d   d       | j                  |j                         | j                  |j                  d      d	       y )
Nr   )partialr   )_test_extension_cppc                     | dkD  r| j                   | dz
              z  S t        j                         j                  j	                         S )Nr   r   )	test_callr   r   r   r   )r   r  r  recurses    r   r  z@TestGreenlet.test_get_stack_with_nested_c_calls.<locals>.recurse}  sJ    1u.88!a%9PQQQ&&(//6688r   r5   r   rg   i  )	functoolsr   r  r&   r   r   r8   r6   r  r   rQ   )r9   grr   rn   r  r  r  s       @@@r   "test_get_stack_with_nested_c_callsz/TestGreenlet.test_get_stack_with_nested_c_callsy  s    %)	9
 !
		!qAU^^C0!4LLE  	,a0%,,'2-r   c                 4   t        j                         fd}fdt        |      }|j                         }t        d       }|j                          | j	                  |j
                  j                  d       | j                  |j                         y )Nc                  <      t        j                  d             y r   )r   r   r  s   r   r  z6TestGreenlet.test_frames_always_exposed.<locals>.outer  s    #--"#r   c                 (    j                  |        y r!   )r   )r   r   s    r   r  z6TestGreenlet.test_frames_always_exposed.<locals>.inner  s    KKr   c                       y r!   r   r   r   r   r   z9TestGreenlet.test_frames_always_exposed.<locals>.<lambda>  r  r   r  )	r   r   r&   r   r6   r  r  rQ   r   )r9   r  r  r   r  r  r   s        @@r   test_frames_always_exposedz'TestGreenlet.test_frames_always_exposed  sx     ""$	$	 		  -	--w7%,,'r   N)F)4r   r   r   r:   r=   rG   rJ   rO   rR   rZ   rb   rq   rv   ry   r~   r   unittestskipIfr	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r  r  r  r  r/  r5  rD  rP  ri  rs  r  r  r  r  r  r  r  r  r   r   r   r+   r+   2   sc   .117
!
'(0(1,8+O&6 X__&&G**X+ 	 -& 5"	+C
6	; 7) 7)r : :> ) )*-^$4-82 5nB> X__&&EADADF+%*)6:.&(r   r+   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestGreenletSetParentErrorsc                 
   i t        j                         t        j                         fd}d }t        j                  |      }|j                          j	                  d       t        |      }|j                          | j                  t              5 }d   |_	        d d d        j                          |j                  d       | j                  t        j                        d       y # 1 sw Y   PxY w)Nc                  f    t        d       d<    j                          j                  d       y )Nc                       y r!   r   r   r   r   r   zQTestGreenletSetParentErrors.test_threaded_reparent.<locals>.run.<locals>.<lambda>  r   r   r'   rg   r   r   s   r   r@   z?TestGreenletSetParentErrors.test_threaded_reparent.<locals>.run  r   r   c                  \    t        j                         j                  j                          y r!   r   r   r   r   blankzATestGreenletSetParentErrors.test_threaded_reparent.<locals>.blank  r   r   rh   rg   r'   z&parent cannot be on a different thread)rj   r   rk   rl   r   r&   r   rA   r   r   r   rm   r6   rD   rE   )	r9   r@   r  r   r'   r"   r   r   r   s	         @@@r   test_threaded_reparentz2TestGreenletSetParentErrors.test_threaded_reparent  s    !)__&
	 
	2 !!-2	
z*cCyAH +BS]]+-UV +*s   C99Dc                    g fd}t        j                  |      }|j                          |j                  d       | j	                  | j
                  dz           G fddt              } |d       }| j                  t        j                        5 }|j                          d d d        | j                  t        j                        d	       d d = y # 1 sw Y   4xY w)
Nc                  `    t        d       } j                  |        | j                          y )Nc                       y r!   r   r   r   r   r   zYTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker.<locals>.<lambda>      Dr   )r&   r   r   )r'   anothers    r   r   zGTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker  s"    L)ANN1HHJr   rh   rg   r   )initial_main_greenletsc                       e Zd Z fdZy)KTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convolutedc                 N    |dk(  r
d   | _         t        j                  | |      S Nr@   r   r   r&   r   r9   r   r  s     r   r   z\TestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convoluted.__getattribute__  (    5=")!*DK"33D$??r   Nr   r  s   r   r  r    	    @r   r  c                       y r!   r   r   r   r   r   zITestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.<lambda>  r   r   r  )rj   rk   rl   rm   r  main_greenlets_before_testr&   rA   r   r   r   r6   rD   rE   )r9   r   r   r  r'   r"   r  s         @r   test_unexpected_reparentingz7TestGreenletSetParentErrors.test_unexpected_reparenting  s    	 F+			r
& 	&&d>]>]`a>a&b	@ 	@
 |$x~~.#HHJ /S]]+]	_AJ	 /.s   CC%c                    g t        j                         t        j                         fd} G fddt              }t        j                  |      }|j	                          j                  d       	  |d       }| j                  t        j                        5 }|j                          d d d        | j                  dt        j                               | j                  dt        |j                               | j                  d	t        |j                               j                          |j                  d       d d = y # 1 sw Y   xY w# j                          |j                  d       d d = w xY w)
Nc                      t        d       } j                  |        | j                          j                          j	                  d       y )Nc                       y r!   r   r   r   r   r   zhTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.worker.<locals>.<lambda>  r  r   rg   )r&   r   r   r   r   )r'   r  keep_main_aliveswitched_to_greenlets    r   r   zVTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.worker  s<    L)ANN1HHJ $$&  $r   c                       e Zd Z fdZy)ZTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convolutedc                 N    |dk(  r
d   | _         t        j                  | |      S r  r  r  s     r   r   zkTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convoluted.__getattribute__  r  r   Nr   r  s   r   r  r    r  r   r  rh   rg   c                       y r!   r   r   r   r   r   zXTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.<lambda>      4r   z#Cannot switch to a different threadExpectedCurrent)rj   r   r&   rk   rl   r   rA   r   r   r   rC   rD   rE   r   rm   )	r9   r   r  r   r'   r"   r  r  r  s	         @@@r   *test_unexpected_reparenting_thread_runningzFTestGreenletSetParentErrors.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7A7E! EE! !(F	c                    t        d       }| j                  |j                  t        j                                | j                  t              5 }|`d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nc                       y r!   r   r   r   r   r   zGTestGreenletSetParentErrors.test_cannot_delete_parent.<locals>.<lambda>      Tr   can't delete attribute)
r&   rM   r   r   r   rA   rB   r6   rD   rE   )r9   r   r"   s      r   test_cannot_delete_parentz5TestGreenletSetParentErrors.test_cannot_delete_parent  sd    \*fmmX%8%8%:;~.# /S]]+-EF /.s   BB
c                     | j                  t              5 }t        j                         `d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nr  rA   rB   r   r   r   r6   rD   rE   r9   r"   s     r   !test_cannot_delete_parent_of_mainz=TestGreenletSetParentErrors.test_cannot_delete_parent_of_main  sI    ~.###%, /S]]+-EF /.s   AA"c                 ^    | j                  t        j                         j                         y r!   )rQ   r   r   r   r<   s    r   !test_main_greenlet_parent_is_nonez=TestGreenletSetParentErrors.test_main_greenlet_parent_is_none  s    (--/667r   c                      d } fd}t        |      } j                  |        ||       |j                           j                  |        ||       |j                          y )Nc                  \    t        j                         j                  j                          y r!   r   r   r   r   bgzCTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.bg  s    !((//1r   c                     d ddfD ]b  }j                  t              5 }|| _        d d d        j                  t	        j
                        dt        |      j                  z          d y # 1 sw Y   GxY w)Nr   42z4GreenletChecker: Expected any type of greenlet, not )rA   r   r   r6   rD   rE   typer   )gletpr"   r9   s      r   checkzFTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.check#  si    1dD(&&y1S"#DK 2   &JTRSWM]M]]_	 )11s   A..A7	)r&   r   r   r   )r9   r  r  r'   s   `   r   test_set_parent_wrong_typesz7TestGreenletSetParentErrors.test_set_parent_wrong_types  sW    	2	_ Oa 	

a 	

r   c                     t        d       }| j                  t              5 }||_        d d d        | j	                  t        j                        d       y # 1 sw Y   /xY w)Nc                       y r!   r   r   r   r   r   z@TestGreenletSetParentErrors.test_trivial_cycle.<locals>.<lambda>;  r  r   cyclic parent chain)r&   rA   r   r   r6   rD   rE   )r9   r  r"   s      r   test_trivial_cyclez.TestGreenletSetParentErrors.test_trivial_cycle:  sK    <(z*cDK +S]]+-BC +*s   AA!c                     | j                  t              5 }t        j                         t        j                         _        d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz(cannot set the parent of a main greenletr  r  s     r   test_trivial_cycle_mainz3TestGreenletSetParentErrors.test_trivial_cycle_main@  sT    ~.#+3+>+>+@H!( /S]]+-WX /.s   ,A00A9c                    t        d       }t        d       }t        d       }||_        ||_        | j                  t              5 }||_        d d d        | j	                  t        j                        d       y # 1 sw Y   /xY w)Nc                       y r!   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>G  r   r   c                       y r!   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>H  r   r   c                       y r!   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>I  r   r   r  )r&   r   rA   r   r6   rD   rE   )r9   r(   rt   g3r"   s        r   test_deeper_cyclez-TestGreenletSetParentErrors.test_deeper_cycleF  sm    &&&		z*cBI +S]]+-BC +*s   A>>BN)r   r   r   r  r  r  r  r  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                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestReprc                 J    | j                  |j                  |      ||f       y r!   )r   endswith)r9   gotsuffixs      r   assertEndsWithzTestRepr.assertEndsWithT  s    V,sFm<r   c                 b    t        t        j                               }| j                  |d       y )N current active started main>)reprr   r   r  r9   rs     r   test_main_while_runningz TestRepr.test_main_while_runningW  s&    $$&'A>?r   c                     t        j                         fd}t        |      }|j                         }| j	                  |d       y )Nc                      t               S r!   )r  r  s   r   r@   z-TestRepr.test_main_in_background.<locals>.run]  s    :r    suspended active started main>)r   r   r&   r   r  )r9   r@   r'   r  r   s       @r   test_main_in_backgroundz TestRepr.test_main_in_background[  s>    ""$	 HHJA@Ar   c                 N    t        t                     }| j                  |d       y )Nz	 pending>)r  r&   r  r  s     r   test_initialzTestRepr.test_initiald  s    A{+r   c                 &   t        j                          G fddt        j                        } |       }|j	                          |j                  d       | j                  |j                  d       | j                  |j                  d       t        d      D ]  }t        j                  d        t        d      D ]N  }| j                  |j                  j                         t        |j                        }| j                  |d       P y )	Nc                   $    e Zd ZdxZZdZ fdZy)/TestRepr.test_main_from_other_thread.<locals>.TNc                     t              | _        t        j                         | _        t        | j                        | _        y r!   )r  original_mainr   r   	main_gletr}  )r9   r   s    r   r@   z3TestRepr.test_main_from_other_thread.<locals>.T.runn  s0    %)$Z"!)!4!4!6#'#7 r   )r   r   r   r  r}  r  r@   r  s   r   Tr  k  s    *..MKI8r   r  rg   r  r  r.   gMbP?z (thread exited) dead>)r   r   rj   rk   rl   rm   r  r  r}  r8   r   r   r   r  rX   r  )r9   r  r   rc  r  r   s        @r   test_main_from_other_threadz$TestRepr.test_main_from_other_threadh  s    ""$	8	   	8 C			r
AOO-NOAMM+JK qAJJu  qAOOAKK,,-Q[[!A#;< r   c                    t        d       }|j                          | j                  t        |      d       | j	                  dt        |             | j	                  dt        |             | j	                  dt        |             y )Nc                       y r!   r   r   r   r   r   z$TestRepr.test_dead.<locals>.<lambda>  s    r   z dead>	suspendedstartedactive)r&   r   r  r  assertNotInrN   s     r   	test_deadzTestRepr.test_dead  se    %	
DGX.d1g.DG,47+r   c                     t        d       }t        d       }t        j                         }|||fD ]0  }| j                  |t               | j                  |t               2 y )Nc                       y r!   r   r   r   r   r   z>TestRepr.test_formatting_produces_native_str.<locals>.<lambda>  r  r   c                       y r!   r   r   r   r   r   z>TestRepr.test_formatting_produces_native_str.<locals>.<lambda>  r   r   )r&   r   r   assertIsInstancerD   )r9   g_deadg_not_startedg_curr'   s        r   #test_formatting_produces_native_strz,TestRepr.test_formatting_produces_native_str  sa     \*#L1##%-A!! !! .r   N)
r   r   r   r  r  r  r  r  r&  r.  r   r   r   r  r  R  s(    =@B,!=F,r   r  c                       e Zd Zd Zd Zd Zy)TestMainGreenletc                     dt        t        j                               v sJ t        t        j                               }dt        |      vsJ |S )Nr   )r  r   r   r  )r9   r   s     r   _check_current_is_mainz'TestMainGreenlet._check_current_is_main  sH    h1134444$$&'T!W$$$r   c                 b    | j                         }t        d|fi       }| j                  |       y )Nsubclass)r2  r  rL   )r9   	main_typer4  s      r   )test_main_greenlet_type_can_be_subclassedz:TestMainGreenlet.test_main_greenlet_type_can_be_subclassed  s.    //1	
YL"5X&r   c                 t    | j                          | j                  t        j                         t               y r!   )r2  r*  r   r   r&   r<   s    r   test_main_greenlet_is_greenletz/TestMainGreenlet.test_main_greenlet_is_greenlet  s'    ##%h113[Ar   N)r   r   r   r2  r6  r8  r   r   r   r0  r0    s    '
Br   r0  c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestBrokenGreenletsc                     d }t         j                  j                  |      }d|_        | j	                  t
        d      5  |j                          d d d        y # 1 sw Y   y xY w)Nc                      t        d      )NzNever get here)AssertionErrorr   r   r   r   z<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   )r9   r   r'   s      r   test_failed_to_initialstubz.TestBrokenGreenlets.test_failed_to_initialstub  sW    	3 33D9###K$acHHJc c cs    AA#c                    g fd}t         j                  j                  |      }|j                          | j	                  dg       |j                          | j	                  ddg       d|_        | j                  t        d      5  |j                          d d d        d|_        |j                          | j	                  g d       y # 1 sw Y   5xY w)Nc                      j                  d       t        j                         j                  j	                           j                  d       t        j                         j                  j	                           j                  d       y )Nr   r3   r.   r/   )runss   r   r   zDTestBrokenGreenlets.test_failed_to_switch_into_running.<locals>.func  sZ    KKN!((//1KKN!((//1KKNr   r   r3   Tz0Failed to switch stacks into a running greenlet.F)r   r3   r.   )r   r>  r?  r   r6   r@  rA  rB  )r9   r   r'   rF  s      @r   "test_failed_to_switch_into_runningz6TestBrokenGreenlets.test_failed_to_switch_into_running  s    	 33D9	
s#	
1v&###K$VXHHJX  %	
y)X Xs   CCc                     | j                  d      }| j                  d|j                         | j                  |j                  | j	                                y )Nzfail_slp_switch.pyzfail_slp_switch is running)assertScriptRaisesrC   output
returncode,get_expected_returncodes_for_aborted_processr9   exs     r   &test_failed_to_slp_switch_into_runningz:TestBrokenGreenlets.test_failed_to_slp_switch_into_running  sA    $$%9:2BII>bmmT%V%V%XYr   c                     | j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y )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_scriptrC   r9   rJ  s     r   #test_reentrant_switch_two_greenletsz7TestBrokenGreenlets.test_reentrant_switch_two_greenlets  sh    !?@k6*gv&mV,/816:-v6r   c                     | j                  dd      }| j                  d|j                         | j                  d|j                         y )Nzfail_switch_three_greenlets.py)r   )	exitcodesr   zpositional arguments)rI  rC   rJ  rM  s     r   %test_reentrant_switch_three_greenletsz9TestBrokenGreenlets.test_reentrant_switch_three_greenlets  s@     $$%EQU$Vk299-,bii8r   c                 J    | j                  d      }| j                  d|       y )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')]rR  rT  s     r   &test_reentrant_switch_three_greenlets2z:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2  s)     !BC= 		
r   c                 J    | j                  d      }| j                  d|       y )Nz#fail_initialstub_already_started.pya!  RESULTS: ['Begin C', 'Switch to b from B.__getattribute__ in C', ('Begin B', ()), '_B_run switching to main', ('main from c', 'From B'), 'B.__getattribute__ back from main in C', ('Begin A', (None,)), ('A dead?', True, 'B dead?', True, 'C dead?', False), 'C done', ('main from c.2', None)]rR  rT  s     r   4test_reentrant_switch_GreenletAlreadyStartedInPythonzHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPython  s'    !FG1
 	
r   c                 J    | j                  d      }| j                  d|       y )Nzfail_clearing_run_switches.pyzRESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]rR  rT  s     r   *test_reentrant_switch_run_callable_has_delz>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_del!  s'    !@A 	
r   N)r   r   r   rC  rG  rO  rU  rX  rZ  r\  r^  r   r   r   r:  r:    s+    
*8Z79
$


r   r:  __main__)r{   r   r   rj   r  abcr   r   r   r&   r  r   r   r	   	leakcheckr
   r   r   r   r)   r+   r  r  r0  r:  r   r   r   r   r   <module>rb     s    	 
       ,  "  &		 	p(8 p(fjD( jDZRx RjBx B.k
( k
Z zHMMO r   