
    h                     R   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 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j6                          yy)    N)ABCMeta)abstractmethod)greenlet   )TestCase)RUNNING_ON_MANYLINUX)PY313)PY314)fails_leakcheckc                       e Zd Zy)	SomeErrorN__name__
__module____qualname__     ED:\EasyAligner\venv\Lib\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>.f8   s4    JJqM!((//1JJqMr   r            )r'   r   r   assertEquallistrange)selfr3   r(   r2   s      @r   _do_simple_testzTestGreenlet._do_simple_test5   sc    	 N

1	


1	


1d58n-r   c                 $    | j                          y r"   )r;   r:   s    r   test_simplezTestGreenlet.test_simpleD   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r:   r(   r#   s      r   (test_switch_no_run_raises_AttributeErrorz5TestGreenlet.test_switch_no_run_raises_AttributeErrorG   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'   rB   rC   throwr   rD   rE   rF   rG   s      r   'test_throw_no_run_raises_AttributeErrorz4TestGreenlet.test_throw_no_run_raises_AttributeErrorN   sL    M~.#GGI / 	eS/0 /.s   A$$A-c                     t        d       }| j                  |       | j                  |j                  t	        j
                                y )Nr%   )r'   assertIsNotNoneassertIsr   r   r   r:   r(   s     r   test_parent_equals_Nonez$TestGreenlet.test_parent_equals_NoneU   s5    t$Qahh 3 3 56r   c                 t    t        d       }| j                  |       | j                  |j                         y )N)rA   )r'   rM   assertIsNonerA   rO   s     r   test_run_equals_Nonez!TestGreenlet.test_run_equals_NoneZ   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   extendr1   s   r   r3   z)TestGreenlet.test_two_children.<locals>.fb   s9    JJqM!((//1JJ1vr   r   r4   r5   T   )r'   r   r7   lendead)r:   r3   r(   hr2   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}| j                  t        j                  |      t        sdnd       t	        |      }| j                  t        j                  |      t        sdnd       |j                          | j                  g d       | j                  t        j                  |      t        sd       y d       y )Nc                       j                  d       t        j                         j                  j	                          y )Nbr0   r1   s   r   r3   z3TestGreenlet.test_two_recursive_children.<locals>.fv   s)    JJsO!((//1r   c                      j                  d       t              } | j                          j                  d       y )Nac)r   r'   r   )r(   r3   r2   s    r   r(   z3TestGreenlet.test_two_recursive_children.<locals>.gz   s+    JJsOAAHHJJJsOr   r4   r   )r`   r^   ra   )r7   r   getrefcountr
   r'   r   )r:   r(   r3   r2   s     @@r   test_two_recursive_childrenz(TestGreenlet.test_two_recursive_childrens   s    	2	
 	+eQCN 	+eQC	
o.+eQCCr   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   )r:   successs   r   r3   z$TestGreenlet.test_threads.<locals>.f   s      "NN4 r   
   target)r9   	threadingThreadstartjoinr7   rX   )r:   r3   ithsthrg   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   r7   rB   r   )r:   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   rB   KeyErrorr*   r7   )r:   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   r7   gccollectr   GreenletExit)r:   r   r)   ru   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   rA   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   getvaluerD   )r:   rA   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   r3   z1TestGreenlet.test_dealloc_other_thread.<locals>.f   sn    U#BIIdONN2JJL;??A  #M""$ %%a(Mr   ri   rh   r   r/   )rk   Eventrl   rm   r   r7   rX   r|   r}   r   r   r~   rn   )	r:   r3   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   	_getframer7   f_backr   r   r   r   )r3   r:   s    r   f1z#TestGreenlet.test_frame.<locals>.f1  sE    a AQXXt,!((//2$r   r   )r'   r   
assertTruegr_frameassertFalser7   )r:   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?rj   args)g333333?rh   )rk   rl   rm   rn   )r:   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)Nr5   r4   *   )r7   )r`   r^   r:   s     r   rA   z,TestGreenlet.test_switch_kwargs.<locals>.run1  s&    Q"Q"r   r5   r4   )r`   r^   r   r'   r   r7   )r:   rA   r   s   `  r   test_switch_kwargszTestGreenlet.test_switch_kwargs0  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   r4   r/   r   r   r   r   r   s    r   rA   z6TestGreenlet.test_switch_kwargs_to_parent.<locals>.run9  sR    !((//!/4!((//Q/7a1f9r   r   r/   )r4   )r/   	   )r'   r7   r   )r:   rA   r(   s      r   test_switch_kwargs_to_parentz)TestGreenlet.test_switch_kwargs_to_parent8  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>H      Dr   r(   rh   r'   r   r   created_eventdata
done_events   r   rA   z7TestGreenlet.test_switch_to_another_thread.<locals>.runG  )    #L1DIOOBr   ri   rh   r(   )rk   r   rl   rm   r   rB   r   errorr   r   rn   clear)r:   rA   threadr   r   r   s      @@@r   test_switch_to_another_threadz*TestGreenlet.test_switch_to_another_threadB  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   r7   )r   rZ   r:   s    r   r3   z&TestGreenlet.test_exc_state.<locals>.fV  sK    ; '';<<>A%%'  3<<>:s
    AA#c                  N     j                  t        j                         d       y )N)NNN)r7   r   r   r=   s   r   rZ   z&TestGreenlet.test_exc_state.<locals>.h^  s    S\\^-?@r   r&   )r:   r3   rZ   s   ` @r   test_exc_statezTestGreenlet.test_exc_stateU  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   r3   z*TestGreenlet.test_instance_dict.<locals>.fd  s    )+H!&r   c                     | ` y r"   __dict__)r(   s    r   deldictz0TestGreenlet.test_instance_dict.<locals>.deldictf  s    
r   c                     || _         y r"   r   )r(   rv   s     r   setdictz0TestGreenlet.test_instance_dict.<locals>.setdicth  s	    AJr   r   r   )r'   r7   r   r   r   rB   	TypeError)r:   r3   r   r   r(   s        r   test_instance_dictzTestGreenlet.test_instance_dictc  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>.funcv  s"    NN++-u5r   Fr   )r:   r   r(   r   s      @r    test_running_greenlet_has_no_runz-TestGreenlet.test_running_greenlet_has_no_runt  s4    	
 	
5'*r   c                     dd l }| j                  t        |j                   t                      | j                  t        |j                  t                      y r   )copyrB   r   r'   deepcopy)r:   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   rN   r   )r:   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'   rB   rC   r   )r:   r)   ru   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__r:   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'   rB   r   rJ   )r:   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   ri   rh   r   Bcannot switch to a different thread (which happens to have exited)zCannot switchr   T)rk   rl   rm   rn   wait_for_pending_cleanupsrB   r   r   rJ   r   rE   rF   r   r7   r   r   RuntimeErrorr   f_localsrR   expect_greenlet_leak)r:   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 rf   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 )NrA   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   )r:   rv   s     r   rA   z;TestGreenlet.test_recursive_startup.<locals>.convoluted.run  s    KK&&u- r   N)r   r   r   r  r   rA   r   r   r   
convolutedr    s    @
.r   r  r   r  T)r'   r7   r   r  )r:   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)r:   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   ri   rh   )rk   Lockr!  objectr   r   r'   bombr   rl   rm   r   r7   rn   )	r:   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   )rv   	initiatorr   r   s    r   r   z>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                       yr   r   r   r   r   r3  zATestGreenlet.test_dealloc_switch_args_not_lost.<locals>.initiatorH      r   r   r   )r'   r   r   r7   )r:   rv   r3  r   r   s     @@@r   !test_dealloc_switch_args_not_lostz.TestGreenlet.test_dealloc_switch_args_not_lost9  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>._applya  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__e  s&    ##%,,.}}T**r   N)r   r   r   r?  r   r   r   mytupler<  d  s    +r   r@  r   )r`   c                  f      t        j                         j                  j                         y r"   r   )r:  r   kwargss   r   switchapplyz5TestGreenlet.test_tuple_subclass.<locals>.switchapplyj  s$    8&&(//66fEr   )r>  dictr'   r7   r   )r:   r@  rC  r(   r:  r   rB  s       @@@r   test_tuple_subclassz TestGreenlet.test_tuple_subclassS  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AbstractSubclassrA   c                      y r"   r   r=   s    r   r   z7TestGreenlet.test_abstract_subclasses.<locals>.<lambda>s  s    r   c                       e Zd Zy):TestGreenlet.test_abstract_subclasses.<locals>.BadSubclassNr   r   r   r   BadSubclassrJ  u      r   rK  c                       e Zd Zd Zy);TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclassc                      y r"   r   r=   s    r   rA   z?TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclass.runy  s    r   N)r   r   r   rA   r   r   r   GoodSubclassrN  x  s    r   rP  )r   r'   r   rB   r   )r:   rG  rK  rP  s       r   test_abstract_subclassesz%TestGreenlet.test_abstract_subclasseso  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   ri   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  )r:   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#  rZ  s   r   gc_callbackrX    s    'r   r[  c                       e Zd Z fdZy)PTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbagec                 ,    | | _                 | _        y r"   )cyclecallback)r:   r[  s    r   r  zYTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbage.__init__  s    !%DJ$/MDMr   N)r   r   r   r  )r[  s   r   garbager]    s    2r   ra  r4   r   rh   T)rk   r-  r!  rl   rm   r.  r9   r   r   rn   r'   r   r|   r}   r7   r   )rV  r   ra  lr   currentr(   _lastr[  r"  r#  rZ  Nr:   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   r6   )r|   	isenabledget_thresholdr9   )r:   rg  rd  rf  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   Greenletrn    rL  r   ro  c                      	         j                   j                          y #  $ r# j                  j                                 Y y w xY wr"   )r   r   gletsr   )r~   r   r:   s   r   greenlet_mainzYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.greenlet_main  s?    0##**, 0

!!*,/0s   # %A
Arh   )
r   r   r~   r'   r   rb   rq  r9   r   r7   )r:   ro  initial_refsrr  rd  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   )rl   )r   rl  c                       e Zd Zy)STestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.MyGreenletNr   r   r   r   
MyGreenletrw    rL  r   rx  c                  D             j                   j                          y r"   r  rl  s   r   rr  zVTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.greenlet_main  s    L&&(r   c                            }j                  |       |j                          ~| j                          j                  d                y )Nrh   )r   r   r   r   )greenlet_running_eventminerx  r   rq  rr  ref_cleareds     r   thread_mainzTTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.thread_main  sH    m,DLLKKM"&&( R  Lr   -   r   rh   )rk   rl   r   r   r   r'   r   rb   r9   r   rm   r   r   r  r7   )r:   rl   r   r~  rs  thread_ready_eventsrd  eventr   r   rx  r   rq  rr  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   r5  r   c                       yr   r   r   r   r   leafzYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.leaf%  r5  r   )r'   rB   r   r   )r:   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>.leaf4  r5  r   )r   r  r   )r:   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>E      DKKOr   r   )r'   rB   r   r   r7   )r:   r  r  r  r   s       @r   ;test_switch_to_dead_greenlet_with_unstarted_perverse_parentzHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent<  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>S  s    4;;r?r   c                  &     j                  d      S r   r  r   s   r   r   zDTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>T  r  r   r   r  )r'   r   r7   r   rR   )r:   r  r  r   r   s       @r   %test_switch_to_dead_greenlet_reparentz2TestGreenlet.test_switch_to_dead_greenlet_reparentQ  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>.outere  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>.innerh  s    KKa()r   c                       y r"   r   r   r   r   r   zKTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.<lambda>q      r   r  r  )r   r   r'   r   rM   r   r7   f_codeco_namer   rR   )r:   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   r6   r   rh   i  )	functoolsr   r  r'   r   r   r9   r7   r  r   rR   )r:   grr   ro   r  r  r  s       @@@r   "test_get_stack_with_nested_c_callsz/TestGreenlet.test_get_stack_with_nested_c_calls|  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   r7   r  r  rR   r   )r:   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>   rH   rK   rP   rS   r[   rc   rr   rw   rz   r   r   unittestskipIfr	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r  r0  r6  rE  rQ  rj  rt  r  r  r  r  r  r  r  r  r   r   r   r,   r,   3   sd   .117
!
'(D,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(   rh   r   r   s   r   rA   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   ri   rh   r(   z&parent cannot be on a different thread)rk   r   rl   rm   r   r'   r   rB   r   r   r   rn   r7   rE   rF   )	r:   rA   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   ri   rh   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 NrA   r   r   r'   r   r:   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  )rk   rl   rm   rn   r  main_greenlets_before_testr'   rB   r   r   r   r7   rE   rF   )r:   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   rh   )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  ri   rh   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)rk   r   r'   rl   rm   r   rB   r   r   r   rD   rE   rF   r   rn   )	r:   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'   rN   r   r   r   rB   rC   r7   rE   rF   )r:   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  rB   rC   r   r   r   r7   rE   rF   r:   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"   )rR   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 )rB   r   r   r7   rE   rF   typer   )gletpr#   r:   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   )r:   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'   rB   r   r   r7   rE   rF   )r:   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_mainC  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>J  r   r   c                       y r"   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>K  r   r   c                       y r"   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>L  r   r   r  )r'   r   rB   r   r7   rE   rF   )r:   r)   ru   g3r#   s        r   test_deeper_cyclez-TestGreenletSetParentErrors.test_deeper_cycleI  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)r:   gotsuffixs      r   assertEndsWithzTestRepr.assertEndsWithW  s    V,sFm<r   c                 b    t        t        j                               }| j                  |d       y )N current active started main>)reprr   r   r  r:   rs     r   test_main_while_runningz TestRepr.test_main_while_runningZ  s&    $$&'A>?r   c                     t        j                         fd}t        |      }|j                         }| j	                  |d       y )Nc                      t               S r"   )r  r  s   r   rA   z-TestRepr.test_main_in_background.<locals>.run`  s    :r    suspended active started main>)r   r   r'   r   r  )r:   rA   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_initialg  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~  )r:   r   s    r   rA   z3TestRepr.test_main_from_other_thread.<locals>.T.runq  s0    %)$Z"!)!4!4!6#'#7 r   )r   r   r   r  r~  r  rA   r  s   r   Tr  n  s    *..MKI8r   r  rh   r  r  r/   gMbP?z (thread exited) dead>)r   r   rk   rl   rm   rn   r  r  r~  r9   r   r   r   r  rY   r  )r:   r  r   rd  r  r   s        @r   test_main_from_other_threadz$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                    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  assertNotInrO   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   assertIsInstancerE   )r:   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  U  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  )r:   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)r3  r  rM   )r:   	main_typer5  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"   )r3  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   r3  r7  r9  r   r   r   r1  r1    s    '
Br   r1  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   )r:   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   r4   r/   r0   )runss   r   r   zDTestBrokenGreenlets.test_failed_to_switch_into_running.<locals>.func  sZ    KKN!((//1KKN!((//1KKNr   r   r4   Tz0Failed to switch stacks into a running greenlet.F)r   r4   r/   )r   r?  r@  r   r7   rA  rB  rC  )r:   r   r(   rG  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)assertScriptRaisesrD   output
returncode,get_expected_returncodes_for_aborted_processr:   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_scriptrD   r:   rK  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)rJ  rD   rK  rN  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')]rS  rU  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)]rS  rU  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')]rS  rU  s     r   *test_reentrant_switch_run_callable_has_delz>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_del$  s'    !@A 	
r   N)r   r   r   rD  rH  rP  rV  rY  r[  r]  r_  r   r   r   r;  r;    s+    
*8Z79
$


r   r;  __main__)r|   r   r   rk   r  abcr   r   r   r'   r  r   r   r	   r
   	leakcheckr   r   r   r   r*   r,   r  r  r1  r;  r   r   r   r   r   <module>rc     s    	 
       ,  "   &		 	r(8 r(jjD( jDZRx RjBx B.k
( k
Z zHMMO r   