
    h{                     ^   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 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j8                          yy)    N)ABCMeta)abstractmethod)greenlet   )TestCase)RUNNING_ON_MANYLINUX)PY313)PY314)RUNNING_ON_FREETHREAD_BUILD)fails_leakcheckc                       e Zd Zy)	SomeErrorN__name__
__module____qualname__     Z/var/www/html/eduruby.in/venv/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>.f9   s4    JJqM!((//1JJqMr   r            )r(   r   r   assertEquallistrange)selfr4   r)   r3   s      @r   _do_simple_testzTestGreenlet._do_simple_test6   sc    	 N

1	


1	


1d58n-r   c                 $    | j                          y r#   )r<   r;   s    r   test_simplezTestGreenlet.test_simpleE   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_AttributeErrorH   sP    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rA   )r(   rC   rD   throwr   rE   rF   rG   rH   s      r   'test_throw_no_run_raises_AttributeErrorz4TestGreenlet.test_throw_no_run_raises_AttributeErrorO   sS    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_NoneV   s5    t$Qahh 3 3 56r   c                 t    t        d       }| j                  |       | j                  |j                         y )N)rB   )r(   rN   assertIsNonerB   rP   s     r   test_run_equals_Nonez!TestGreenlet.test_run_equals_None[   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   extendr2   s   r   r4   z)TestGreenlet.test_two_children.<locals>.fc   s9    JJqM!((//1JJ1vr   r   r5   r6   T   )r(   r   r8   lendead)r;   r4   r)   hr3   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br1   r2   s   r   r4   z3TestGreenlet.test_two_recursive_children.<locals>.fw   s)    JJsO!((//1r   c                      j                  d       t              } | j                          j                  d       y )Nac)r   r(   r   )r)   r4   r3   s    r   r)   z3TestGreenlet.test_two_recursive_children.<locals>.g{   s+    JJsOAAHHJJJsOr   r5   r   )ra   r_   rb   )r8   r   getrefcountr
   r(   r   )r;   r)   r4   r3   s     @@r   test_two_recursive_childrenz(TestGreenlet.test_two_recursive_childrent   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   r4   z$TestGreenlet.test_threads.<locals>.f   s      "NN4 r   
   target)r:   	threadingThreadstartjoinr8   rY   )r;   r4   ithsthrh   s   `    @r   test_threadszTestGreenlet.test_threads   s    	! 499=ayq)== 	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   r8   rC   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   rC   KeyErrorr+   r8   )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   r8   gccollectr   GreenletExit)r;   r   r*   rv   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   rB   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   getvaluerE   )r;   rB   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                 2   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        s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 )Nr0   )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   r4   z1TestGreenlet.test_dealloc_other_thread.<locals>.f   sn    U#BIIdONN2JJL;??A  #M""$ %%a(Mr   rj   ri   r   r0   )rl   Eventrm   rn   r   r8   rY   r   r}   r~   r   r   r   ro   )	r;   r4   tr   r   r   r   r   r   s	      @@@@@@r   test_dealloc_other_threadz&TestGreenlet.test_dealloc_other_thread   sF    :C//:K7#//+&__.(0	 	 A&		7<<R@r"Wq)AJ* JJL 	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   	_getframer8   f_backr   r   r   r   )r4   r;   s    r   f1z#TestGreenlet.test_frame.<locals>.f1"  sE    a AQXXt,!((//2$r   r   )r(   r   
assertTruegr_frameassertFalser8   )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>3  s    DJJqM r   r'   )r   r)   s   ` r   runnerz,TestGreenlet.test_thread_bug.<locals>.runner2  s    12AHHJr   )g?rk   args)g333333?ri   )rl   rm   rn   ro   )r;   r   t1t2s       r   test_thread_bugzTestGreenlet.test_thread_bug1  sU    	 V&9V&9





r   c                 l      fd}t        |      j                  dd      } j                  |d       y )Nc                 N    j                  | d       j                  |d       y)Nr6   r5   *   )r8   )ra   r_   r;   s     r   rB   z,TestGreenlet.test_switch_kwargs.<locals>.run=  s&    Q"Q"r   r6   r5   )ra   r_   r   r(   r   r8   )r;   rB   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   r5   r0   r   r   r   r   r   s    r   rB   z6TestGreenlet.test_switch_kwargs_to_parent.<locals>.runE  sR    !((//!/4!((//Q/7a1f9r   r   r0   )r5   )r0   	   )r(   r8   r   )r;   rB   r)   s      r   test_switch_kwargs_to_parentz)TestGreenlet.test_switch_kwargs_to_parentD  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>T      r   r)   ri   r(   r   r   created_eventdata
done_events   r   rB   z7TestGreenlet.test_switch_to_another_thread.<locals>.runS  )    #L1DIOOBr   rj   ri   r)   )rl   r   rm   rn   r   rC   r   errorr   r   ro   clear)r;   rB   threadr   r   r   s      @@@r   test_switch_to_another_threadz*TestGreenlet.test_switch_to_another_threadN  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   r8   )r   r[   r;   s    r   r4   z&TestGreenlet.test_exc_state.<locals>.fb  sK    ; '';<<>A%%'  3<<>:s
    AA#c                  N     j                  t        j                         d       y )N)NNN)r8   r   r   r>   s   r   r[   z&TestGreenlet.test_exc_state.<locals>.hj  s    S\\^-?@r   r'   )r;   r4   r[   s   ` @r   test_exc_statezTestGreenlet.test_exc_statea  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   r4   z*TestGreenlet.test_instance_dict.<locals>.fp  s    )+H!&r   c                     | ` y r#   __dict__)r)   s    r   deldictz0TestGreenlet.test_instance_dict.<locals>.deldictr  s    
r   c                     || _         y r#   r   )r)   rw   s     r   setdictz0TestGreenlet.test_instance_dict.<locals>.setdictt  s	    AJr   r   r   )r(   r8   r   r   r   rC   	TypeError)r;   r4   r   r   r)   s        r   test_instance_dictzTestGreenlet.test_instance_dicto  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 rA   )r   hasattrr   r   )has_runs   r   funcz;TestGreenlet.test_running_greenlet_has_no_run.<locals>.func  s"    NN++-u5r   Fr   )r;   r   r)   r   s      @r    test_running_greenlet_has_no_runz-TestGreenlet.test_running_greenlet_has_no_run  s4    	
 	
5'*r   c                     dd l }| j                  t        |j                   t                      | j                  t        |j                  t                      y r   )copyrC   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>  r   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   rO   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&   )r(   rC   rD   r   )r;   r*   rv   s      r   test_parent_return_failurez'TestGreenlet.test_parent_return_failure  sA    ]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>  r   r   )r(   rC   r   rK   )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   rj   ri   r   Bcannot switch to a different thread (which happens to have exited)zCannot switchr   T)rl   rm   rn   ro   wait_for_pending_cleanupsrC   r   r   rK   r   rF   rG   r   r8   r   r   RuntimeErrorr   f_localsrS   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	""((*+  vay))22G<q	""++113fQi0011I %)!C	' 	'"+ +s   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 rg   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 )NrB   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;   rw   s     r   rB   z;TestGreenlet.test_recursive_startup.<locals>.convoluted.run  s    KK&&u- r   N)r   r   r   r  r   rB   r   r   r   
convolutedr    s    @
.r   r  r   r  T)r(   r8   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   rj   ri   )rl   Lockr   objectr   r   r(   bombr   rm   rn   r  r8   ro   )	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   )rw   	initiatorr   r   s    r   r   z>TestGreenlet.test_dealloc_switch_args_not_lost.<locals>.workerG  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>.initiatorT      r   r   r   )r(   r   r   r8   )r;   rw   r2  r   r   s     @@@r   !test_dealloc_switch_args_not_lostz.TestGreenlet.test_dealloc_switch_args_not_lostE  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   ra   ks      r   _applyz0TestGreenlet.test_tuple_subclass.<locals>._applym  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__q  s&    ##%,,.}}T**r   N)r   r   r   r>  r   r   r   mytupler;  p  s    +r   r?  r   )ra   c                  f      t        j                         j                  j                         y r#   r   )r9  r   kwargss   r   switchapplyz5TestGreenlet.test_tuple_subclass.<locals>.switchapplyv  s$    8&&(//66fEr   )r=  dictr(   r8   r   )r;   r?  rB  r)   r9  r   rA  s       @@@r   test_tuple_subclassz TestGreenlet.test_tuple_subclass_  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AbstractSubclassrB   c                      y r#   r   r>   s    r   r   z7TestGreenlet.test_abstract_subclasses.<locals>.<lambda>  r   r   c                       e Zd Zy):TestGreenlet.test_abstract_subclasses.<locals>.BadSubclassNr   r   r   r   BadSubclassrI        r   rJ  c                       e Zd Zd Zy);TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclassc                      y r#   r   r>   s    r   rB   z?TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclass.run  s    r   N)r   r   r   rB   r   r   r   GoodSubclassrM    s    r   rO  )r   r(   r   rC   r   )r;   rF  rJ  rO  s       r   test_abstract_subclassesz%TestGreenlet.test_abstract_subclasses{  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   rj   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"  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)r;   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`  r5   r   ri   T)rl   r,  r   rm   rn   r-  r:   r   r   ro   r(   r   r}   r~   r8   r   )rU  r   r`  lr   currentr)   _lastrZ  r!  r"  rY  Nr;   s            @@@@r   attemptz?TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt  s9   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 4  734r   r7   )r}   	isenabledget_thresholdr:   )r;   rf  rc  re  s   `  @r   !test_implicit_parent_with_threadsz.TestGreenlet.test_implicit_parent_with_threads  sO    ||~q!r6,	Z q 	Ay	r   c                 x    ddl m ddl m  G d dt              }t	        j
                  |      }g  _         fd}t        d      D ]  } ||      j                            `t        r& j                  t	        j
                  |      |       y  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   r;   s   r   greenlet_mainzYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.greenlet_main  s?    0##**, 0

!!*,/0s   # %A
Ari   )r   r   r   r(   r   rc   rp  r:   r   r   assertGreaterEqualr8   )r;   rn  initial_refsrq  rc  r   r   s   `    @@r   5test_issue_245_reference_counting_subclass_no_threadszBTestGreenlet.test_issue_245_reference_counting_subclass_no_threads  s     	()	{ 	 x0 
	0 r 	-A]#**,	- J& ##COOH$=|LS__X6Er   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 }|d	z   }t        rd
}t        |      D ]5  } |       } |||f      }	|j                  |       |	j                          7 |D ]  }
|
j                  d        d d = j                          | j                          | j                  t        j                        |       y )Nr   )rm   )r   rk  c                       e Zd Zy)STestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.MyGreenletNr   r   r   r   
MyGreenletrw    rK  r   rx  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 )Nri   )r   r   r   r   )greenlet_running_eventminerx  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   -   rR  r   ri   )rl   rm   r   r   r   r(   r   rc   r   r:   r   rn   r   r   r  r8   )r;   rm   r   r~  rs  thread_ready_eventsthread_countrc  eventr   r   rx  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 #b(& L|$ 	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(   rC   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_error9  sV    	  +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_argI  s    r7Nr   c                       yr   r   r   r   r   r  zRTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.leafN  r4  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_worksH  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 rA   )r   r   s     r   r   ziTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parent.__getattribute__X  s    5=#O !r   Nr   r   r   r   Parentr  W  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>_      DKKO r   r   )r(   rC   r   r   r8   )r;   r  r  r  r   s       @r   ;test_switch_to_dead_greenlet_with_unstarted_perverse_parentzHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parentV  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>m  s    4;;r? r   c                  &     j                  d      S r   r  r   s   r   r   zDTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>n  r  r   r   r  )r(   r   r8   r   rS   )r;   r  r  r   r   s       @r   %test_switch_to_dead_greenlet_reparentz2TestGreenlet.test_switch_to_dead_greenlet_reparentk  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>.outer  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>.inner  s    KKa()r   c                       y r#   r   r   r   r   r   zKTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.<lambda>  r   r   r  r  )r   r   r(   r   rN   r   r8   f_codeco_namer   rS   )r;   r  r   	unrelatedr  r   s       @@r   ,test_can_access_f_back_of_suspended_greenletz9TestGreenlet.test_can_access_f_back_of_suspended_greenlety  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   r7   r   ri   i  )	functoolsr   r  r(   r   r   r:   r8   r  r   rS   )r;   grr   rp   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   r8   r  r  rS   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?   rI   rL   rQ   rT   r\   rd   rs   rx   r{   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  rt  r  r  r  r  r  r  r  r  r   r   r   r-   r-   4   se   .117
!
'(D,1,8+O&6 X__&&G55n+ 	 -& 5"	+C
6	; 7) 7)r : :> ) )*-^$4-82 5n(FT X__&&EDDDDL+%*)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)   ri   r   r   s   r   rB   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   rj   ri   r)   z&parent cannot be on a different thread)rl   r   rm   rn   r   r(   r   rC   r   r   r   ro   r8   rF   rG   )	r;   rB   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>  r   r   )r(   r   r   )r)   anothers    r   r   zGTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker  s"    L)ANN1HHJr   rj   ri   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 NrB   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  )rl   rm   rn   ro   r  main_greenlets_before_testr(   rC   r   r   r   r8   rF   rG   )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   ri   )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  rj   ri   c                       y r#   r   r   r   r   r   zXTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.<lambda>  r   r   z#Cannot switch to a different threadExpectedCurrent)rl   r   r(   rm   rn   r   rC   r   r   r   rE   rF   rG   r   ro   )	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>>2 c
MM?S]]ASTMM*c#--&89MM)S%78!FF2J
  !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>*  r   r   can't delete attribute)
r(   rO   r   r   r   rC   rD   r8   rF   rG   )r;   r   r$   s      r   test_cannot_delete_parentz5TestGreenletSetParentErrors.test_cannot_delete_parent)  sk    \*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  rC   rD   r   r   r   r8   rF   rG   r;   r$   s     r   !test_cannot_delete_parent_of_mainz=TestGreenletSetParentErrors.test_cannot_delete_parent_of_main1  sP    ~. 	-###%,	-S]]+-EF	- 	-s   AA"c                 ^    | j                  t        j                         j                         y r#   )rS   r   r   r   r>   s    r   !test_main_greenlet_parent_is_nonez=TestGreenletSetParentErrors.test_main_greenlet_parent_is_none7  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 )rC   r   r   r8   rF   rG   typer   )gletpr$   r;   s      r   checkzFTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.check@  sy    1dD( _&&y1 $S"#DK$   &JTRSWM]M]]_	_$ $s   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>X  r   r   cyclic parent chain)r(   rC   r   r   r8   rF   rG   )r;   r  r$   s      r   test_trivial_cyclez.TestGreenletSetParentErrors.test_trivial_cycleW  sR    <(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]  s_    ~. 	A#+3+>+>+@H!(	AS]]+-WX	A 	A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>d  r   r   c                       y r#   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>e  r   r   c                       y r#   r   r   r   r   r   z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>f  r   r   r  )r(   r   rC   r   r8   rF   rG   )r;   r*   rv   g3r$   s        r   test_deeper_cyclez-TestGreenletSetParentErrors.test_deeper_cyclec  st    &&&		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.assertEndsWithq  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_runningt  s&    $$&'A>?r   c                     t        j                         fd}t        |      }|j                         }| j	                  |d       y )Nc                      t               S r#   )r  r  s   r   rB   z-TestRepr.test_main_in_background.<locals>.runz  s    :r    suspended active started main>)r   r   r(   r   r	  )r;   rB   r)   r  r   s       @r   test_main_in_backgroundz TestRepr.test_main_in_backgroundx  s>    ""$	 HHJA@Ar   c                 N    t        t                     }| j                  |d       y )Nz	 pending>)r  r(   r	  r  s     r   test_initialzTestRepr.test_initial  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   rB   z3TestRepr.test_main_from_other_thread.<locals>.T.run  s0    %)$Z"!)!4!4!6#'#7 r   )r   r   r   r  r~  r  rB   r  s   r   Tr    s    *..MKI8r   r  ri   r  r  r0   gMbP?z (thread exited) dead>)r   r   rl   rm   rn   ro   r	  r  r~  r:   r   r   r   r  rZ   r  )r;   r  r   rc  r  r   s        @r   test_main_from_other_threadz$TestRepr.test_main_from_other_thread  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>  r   r   z dead>	suspendedstartedactive)r(   r   r	  r  assertNotInrP   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   assertIsInstancerF   )r;   g_deadg_not_startedg_curr)   s        r   #test_formatting_produces_native_strz,TestRepr.test_formatting_produces_native_str  sf     \*#L1##%- 		A!! !!		r   N)
r   r   r   r	  r  r  r  r  r$  r,  r   r   r   r  r  o  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)r0  r  rN   )r;   	main_typer2  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#   )r0  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   r0  r4  r6  r   r   r   r.  r.    s    '
Br   r.  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  sY    	3 33D9###K$ac 	HHJ	 	 	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   r5   r0   r1   )runss   r   r   zDTestBrokenGreenlets.test_failed_to_switch_into_running.<locals>.func  sZ    KKN!((//1KKN!((//1KKNr   r   r5   Tz0Failed to switch stacks into a running greenlet.F)r   r5   r0   )r   r<  r=  r   r8   r>  r?  r@  )r;   r   r)   rD  s      @r   "test_failed_to_switch_into_runningz6TestBrokenGreenlets.test_failed_to_switch_into_running  s    	 33D9	
s#	
1v&###K$VX 	HHJ	  %	
y)	 	s   CCc                     | j                  d      }| j                  d|j                         | j                  |j                  | j	                                y )Nzfail_slp_switch.pyzfail_slp_switch is running)assertScriptRaisesrE   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_scriptrE   r;   rH  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)rG  rE   rH  rK  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')]rP  rR  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)]rP  rR  s     r   4test_reentrant_switch_GreenletAlreadyStartedInPythonzHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPython2  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')]rP  rR  s     r   *test_reentrant_switch_run_callable_has_delz>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_del>  s'    !@A 	
r   N)r   r   r   rA  rE  rM  rS  rV  rX  rZ  r\  r   r   r   r8  r8    s+    
*8Z79
$


r   r8  __main__)r}   r   r   rl   r  abcr   r   r   r(   r  r   r   r	   r
   r   	leakcheckr   r   r   r    r+   r-   r  r  r.  r8  r   r   r   r   r   <module>r`     s    	 
       ,  "   ) &		 	K(8 K(\jD( jDZRx RjBx B.k
( k
Z zHMMO r   