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

1	


1	


1d58n-r   c                 $    U R                  5         g r'   )rC   rB   s    r   test_simpleTestGreenlet.test_simpleF   s    r   c                     [        5       nU R                  [        5       nUR                  5         S S S 5        U R	                  S[        WR                  5      5        g ! , (       d  f       N4= fNrun)r-   assertRaisesAttributeErrorr   assertInstr	exceptionrB   r.   r(   s      r   (test_switch_no_run_raises_AttributeError5TestGreenlet.test_switch_no_run_raises_AttributeErrorI   sI    M~.#HHJ / 	eS/0 /.s   A
A-c                     [        5       nU R                  [        5       nUR                  [        5        S S S 5        U R                  S[        WR                  5      5        g ! , (       d  f       N4= frJ   )r-   rL   rM   throwr   rN   rO   rP   rQ   s      r   'test_throw_no_run_raises_AttributeError4TestGreenlet.test_throw_no_run_raises_AttributeErrorP   sL    M~.#GGI / 	eS/0 /.s   A$$
A2c                     [        S S9nU R                  U5        U R                  UR                  [        R
                  " 5       5        g )Nr+   )r-   assertIsNotNoneassertIsr   r   r   rB   r.   s     r   test_parent_equals_None$TestGreenlet.test_parent_equals_NoneW   s5    t$Qahh 3 3 56r   c                 n    [        S S9nU R                  U5        U R                  UR                  5        g )N)rK   )r-   rY   assertIsNonerK   r[   s     r   test_run_equals_None!TestGreenlet.test_run_equals_None\   s,    D!Q!%% r   c                 
  ^ / mU4S jn[        U5      n[        U5      nUR                  5         U R                  [        T5      S5        UR                  5         U R                  [        T5      S5        UR                  5         U R                  [        T5      S5        U R                  UR                  S5        UR                  5         U R                  [        T5      S5        U R                  UR                  S5        g )Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         T R                  SS/5        g )Nr   )r   r   r   r   r   extendr8   s   r   r:   )TestGreenlet.test_two_children.<locals>.fd   s9    JJqM!((//1JJ1vr   r   r<   r=   T   )r-   r   r?   lendead)rB   r:   r.   hr9   s       @r   test_two_childrenTestGreenlet.test_two_childrena   s    	 NN	
S1%	
S1%	
S1%&	
S1%&r   c                   ^^ / mU4S jmUU4S jnU R                  [        R                  " U5      [        (       d  SOS5        [	        U5      nU R                  [        R                  " U5      [        (       d  SOS5        UR                  5         U R                  T/ SQ5        U R                  [        R                  " U5      [        (       d  S5        g S5        g )Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         g )Nbr7   r8   s   r   r:   3TestGreenlet.test_two_recursive_children.<locals>.fx   s)    JJsO!((//1r   c                     > TR                  S5        [        T5      n U R                  5         TR                  S5        g )Nac)r   r-   r   )r.   r:   r9   s    r   r.   3TestGreenlet.test_two_recursive_children.<locals>.g|   s+    JJsOAAHHJJJsOr   r<   r   )rq   rn   rr   )r?   r    getrefcountr
   r-   r   )rB   r.   r:   r9   s     @@r   test_two_recursive_children(TestGreenlet.test_two_recursive_childrenu   s    	2	
 	+eeQCN 	+eeQC	
o.+eeQCCr   c                 ,  ^ ^ / mU U4S jn[        S5       Vs/ s H  n[        R                  " US9PM     nnU H  nUR                  5         M     U H  nUR	                  S5        M     T R                  [        T5      [        U5      5        g s  snf )Nc                  H   > T R                  5         TR                  S5        g NT)rC   r   )rB   successs   r   r:   $TestGreenlet.test_threads.<locals>.f   s      "NN4 r   
   target)rA   	threadingThreadstartjoinr?   rg   )rB   r:   ithsthrz   s   `    @r   test_threadsTestGreenlet.test_threads   sw    	! 499=9ayq)9=BHHJ BGGBK Ws3x0 >s   Bc                    ^^ S mS mSUU4S jjn[        S5       H  nU" 5         [        R                  " 5         M!     g )Nc                     S n[         R                   " U5      nUR                  5         U R                  U5        UR                  5         g )Nc                  b     [         R                  " 5       R                  R                  5         M/  r'   r   r   r   r   r   r   r   bodyPTestGreenlet.test_switching_many_threads.<locals>.creates_greenlet.<locals>.body   s%    '')00779 r   )r   r   r   wait)	greenletswait_to_die_untilr   r.   s       r   creates_greenletBTestGreenlet.test_switching_many_threads.<locals>.creates_greenlet   s<    : !!$'AHHJQ""$r   c                     UR                  5         UR                  5       (       dN  [        U 5       H'  n UR                  (       d  UR	                  5         M'  M)     UR                  5       (       d  MM  g g ! [
        R                   a     M[  f = fr'   )r   is_setr@   rh   r   r   error)r   wait_to_check_until
quit_afterr.   s       r   switches_from_other_threadLTestGreenlet.test_switching_many_threads.<locals>.switches_from_other_thread   sp    $$& ''))iA vvHHJ  & ) !''))
 $>>  s   !A55BBc           	      |  > / n[         R                  " 5       n[         R                  " 5       n[        U 5       Vs/ s H  n[         R                  " TUU4S9PM     nn[        U 5       Vs/ s H  n[         R                  " T	XU4S9PM     nnXV-    H  nUR	                  5         M     [        U5      U :  a'  [        R                  " S5        [        U5      U :  a  M'  UR                  5         U H  nUR                  S5        M     UR                  5         U H  nUR                  S5        M     g s  snf s  snf )Nr~   argsg-C6?g      ?)
r   EventrA   r   r   rg   timesleepsetr   )
thread_countr   greenlets_all_createdall_threads_dead_creators	switcherstr   r   s
           r   run_it8TestGreenlet.test_switching_many_threads.<locals>.run_it   s>   I$-OO$5!(0 &	 '    (8	@U@W X '	   &
 '    (B'0'7'9: '   *	 + i.</

6" i.</!%%'s   "s 5s   !D4+!D9   )   )rA   gccollect)rB   r   r   r   r   s      @@r   test_switching_many_threads(TestGreenlet.test_switching_many_threads   s6    	%
	 	  	H rAHJJL r   c                    / n[        [        5      n[        [        5      nUR                  U5        UR                  U5        X#l        U R	                  U/ 5        U R                  [        UR                  5        U R	                  U[        /5        UR                  5       nU R	                  US5        U R	                  U[        /5        UR                  S5      nU R	                  US5        U R	                  U[        /5        g )Nr      )r-   r$   r   r   r?   rL   r   )rB   r#   r/   g2values        r   test_exceptionTestGreenlet.test_exception   s    
		$
		$	r" 	)RYY/	{+		#	{+		"#	{+r   c                     / n[        [        5      nUR                  U5        U R                  [        [
        U[        5        U R                  U[        /5        g r'   )r-   r$   r   rL   KeyErrorr0   r?   )rB   r#   r/   s      r   test_send_exception TestGreenlet.test_send_exception   sB    
		$(NBAz*r   c                    / n[        [        5      n[        [        5      nUR                  U5        UR                  U5        U R                  U/ 5        A[        R
                  " 5         U R                  U[        R                  /5        A[        R
                  " 5         U R                  U[        R                  [        R                  /5        g r'   )r-   r$   r   r?   r   r   r   GreenletExit)rB   r#   r/   r   s       r   test_deallocTestGreenlet.test_dealloc   s    
		$
		$r"


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


 5 5x7L7LMNr   c                 >  ^ S n[        U5      nUR                  5         / m[        R                  nU4S jnU[        l         AU[        l        U R	                  [        T5      S5        U R                  TS   R                  [        5        g ! U[        l        f = f)Nc                       [         R                  " 5       R                  R                  5         g ! [         R                   a    [
        S ef = fr'   )r   r   r   r   r   r   r   r   r   rK   HTestGreenlet.test_dealloc_catches_GreenletExit_throws_other.<locals>.run
  s?    *##%,,335(( *T)*s	   -0 Ac                 (   > TR                  U 5        g r'   r   )
unraisableunraisable_eventss    r   _captureMTestGreenlet.test_dealloc_catches_GreenletExit_throws_other.<locals>._capture  s    $$Z0r   r   r   )	r-   r   r    unraisablehookr?   rg   assertIsInstance	exc_valuer   )rB   rK   r.   old_hookr   r   s        @r   .test_dealloc_catches_GreenletExit_throws_other;TestGreenlet.test_dealloc_catches_GreenletExit_throws_other	  s    	* 	
%%	1%	*!)C./3/2<<iH "*Cs   B Bz=Sometimes flaky (getting one GreenletExit in the second list)c                 D  ^^^^^^ / m/ m[         R                  " 5       m[         R                  " 5       m[         R                  " 5       m[         R                  " 5       mUUUUUU4S jn[         R                  " US9nUR                  5         TR	                  S5        U R                  T/ 5        U R                  [        T5      S5        TS S 2	 [        (       d  [        R                  " 5         U R                  T/ 5        TR                  5         TR	                  S5         U R                  T[        R                  /5        TR                  5         UR                  S5        TS S 2	 TS S 2	 g ! TR                  5         UR                  S5        TS S 2	 TS S 2	 f = f)Nc                  @  > [        [        5      n U R                  T5        TR                  U 5        A [        R
                  " 5         TR                  5         TR                  S5        [        5         TR                  5         TR                  S5        [        5         g )Nr6   )r-   r$   r   r   r   r   r   r   )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   r:   1TestGreenlet.test_dealloc_other_thread.<locals>.f1  sn    U#BIIdONN2JJL;??A  #M""$ %%a(Mr   r}   r|   r   r6   )r   r   r   r   r   r?   rg   r   r   r   r   r   r   r   )	rB   r:   r   r   r   r   r   r#   r   s	      @@@@@@r   test_dealloc_other_thread&TestGreenlet.test_dealloc_other_thread!  sI    :C//:K7#//+&__.(0	 	 A&		7<<R@r"Wq)AJ** JJL 	r""	TH$9$9#:; $$&FF2JQ
 !$$&FF2JQ
s   %!E2 2-Fc                 @  ^  U 4S jn[        U5      nUR                  5       nT R                  X2R                  L 5        T R                  U5        UR                  5       nT R	                  U5        T R                  US5        T R                  UR                  S 5        g )Nc                     > [         R                  " S5      n TR                  U R                  S 5        [        R
                  " 5       R                  R                  U 5        g)Nr   meaning of life)r    	_getframer?   f_backr   r   r   r   )r:   rB   s    r   f1#TestGreenlet.test_frame.<locals>.f1`  sE    a AQXXt,!((//2$r   r   )r-   r   
assertTruegr_frameassertFalser?   )rB   r   r.   framefrom_gs   `    r   
test_frameTestGreenlet.test_frame_  s{    	%
 O
+,!23T*r   c                     S n[         R                  " USS9n[         R                  " USS9nUR                  5         UR                  5         UR                  S5        UR                  S5        g )Nc                 D   ^  [        U 4S j5      nUR                  5         g )Nc                  0   > [         R                  " T 5      $ r'   )r   r   xs   r   <lambda>>TestGreenlet.test_thread_bug.<locals>.runner.<locals>.<lambda>q  s    DJJqMr   r,   )r   r.   s   ` r   runner,TestGreenlet.test_thread_bug.<locals>.runnerp  s    12AHHJr   )g?r   )g333333?r|   )r   r   r   r   )rB   r   t1t2s       r   test_thread_bugTestGreenlet.test_thread_bugo  sU    	 V&9V&9





r   c                 h   ^  U 4S jn[        U5      R                  SSS9nT R                  US5        g )Nc                 N   > TR                  U S5        TR                  US5        g)Nr=   r<   *   )r?   )rq   rn   rB   s     r   rK   ,TestGreenlet.test_switch_kwargs.<locals>.run{  s&    Q"Q"r   r=   r<   )rq   rn   r   r-   r   r?   )rB   rK   r   s   `  r   test_switch_kwargsTestGreenlet.test_switch_kwargsz  s4    	 ##a1#-Br   c                     S n[        U5      nU R                  SS0UR                  S5      5        U R                  SSS04UR                  5       5        U R                  SUR                  5       5        g )Nc                     [         R                  " 5       R                  R                  U S9  [         R                  " 5       R                  R                  SSS9  X S-  4$ )Nr   r<   r6   r   r   s    r   rK   6TestGreenlet.test_switch_kwargs_to_parent.<locals>.run  sP    !((//!/4!((//Q/71f9r   r   r6   )r<   )r6   	   )r-   r?   r   )rB   rK   r.   s      r   test_switch_kwargs_to_parent)TestGreenlet.test_switch_kwargs_to_parent  sd    	 #q188A;/$a)188:6,r   c                   ^^^ 0 m[         R                  " 5       m[         R                  " 5       mUUU4S jn[         R                  " US9nUR                  5         TR	                  S5        U R                  [        R                  5         TS   R                  5         S S S 5        TR                  5         UR                  S5        TR                  5         g ! , (       d  f       N@= f)Nc                  f   > [        S 5      TS'   T R                  5         TR                  S5        g )Nc                      g r'   r   r   r   r   r   ITestGreenlet.test_switch_to_another_thread.<locals>.run.<locals>.<lambda>      Dr   r.   r|   r-   r   r   created_eventdata
done_events   r   rK   7TestGreenlet.test_switch_to_another_thread.<locals>.run  )    #L1DIOOBr   r}   r|   r.   )r   r   r   r   r   rL   r   r   r   r   r   clear)rB   rK   threadr  r  r  s      @@@r   test_switch_to_another_thread*TestGreenlet.test_switch_to_another_thread  s    !)__&
	  !!-2x~~.I /B

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

	s    A6BBr+   r   r   )r-   r   r   r   r   rZ   r   )rB   r<  r.   r9  r:  r;  s      @@@r   test_parent_restored_on_kill)TestGreenlet.test_parent_restored_on_kill  s    ,'""$	 s+	
fQi&fQi&&, 1Ir   c                     [        5       n[        S US9nU R                  [        5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nc                      g r'   r   r   r   r   r   9TestGreenlet.test_parent_return_failure.<locals>.<lambda>      r   r+   )r-   rL   rM   r   )rB   r/   r   s      r   test_parent_return_failure'TestGreenlet.test_parent_return_failure  s8    ]b1~.IIK /..s   A
Ac                      " S S[         5      nU" S 5      nU R                  [        UR                  [        5       5        g )Nc                       \ rS rSrS rSrg)>TestGreenlet.test_throw_exception_not_lost.<locals>.mygreenleti  c                 J     [         e!    O= f[        R                  " X5      $ r'   )	Exceptionr-   __getattribute__rB   names     r   rK  OTestGreenlet.test_throw_exception_not_lost.<locals>.mygreenlet.__getattribute__  s'    #O"33D??s    r   Nr   r   r   r   rK  r   r   r   r   
mygreenletrH    s    @r   rP  c                      g r'   r   r   r   r   r   <TestGreenlet.test_throw_exception_not_lost.<locals>.<lambda>      tr   )r-   rL   r   rU   )rB   rP  r.   s      r   test_throw_exception_not_lost*TestGreenlet.test_throw_exception_not_lost  s4    	@ 	@ |$)QWWik:r   c                   ^^^ / mS mUUU4S jn[         R                  " US9nUR                  5         UR                  S5        AT(       a  U R	                  5         U R                  [        R                  5       nTS   R                  [        5        S S S 5        T(       d6  [        WR                  5      nU R                  US:H  =(       d    SU;   5        O%U R                  [        WR                  5      S5        [        TS   R                  S5      (       a;  U R                  [         5         TS   R                  R#                  5         S S S 5        T(       dP  [        TS   R                  R$                  S5      (       a'  TS   R                  R$                  R#                  5         OU R'                  TS   R                  5        AS mTS S 2	 S	U l        g ! , (       d  f       GNO= f! , (       d  f       N= f)
Nc                  ^    [         R                  " 5       R                  R                  5         g r'   r   r   r   r   r<  GTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.worker       !((//1r   c                     > [        T5      n U R                  5         TR                  U 5        T(       a&  U R                  5         [        R                  " 5         g g r'   )r-   r   r   r   r   )r.   r;  wait_for_cleanupr<  s    r   creatorHTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.creator  s?    F#AHHJMM!
##%  r   r}   r|   r   Bcannot switch to a different thread (which happens to have exited)zCannot switchr  T)r   r   r   r   wait_for_pending_cleanupsrL   r   r   rU   r   rO   rP   r   r?   r*  r   RuntimeErrorr  f_localsr_   expect_greenlet_leak)rB   r[  r\  r   r(   sr;  r<  s    `    @@r   *_do_test_throw_to_dead_thread_doesnt_crash7TestGreenlet._do_test_throw_to_dead_thread_doesnt_crash  s   	2	& G,			r
 **,x~~.#1IOOI& /  CMM"AOOYY ("a'
 CMM"T
 6!9%%w//""<0q	""((* 1  vay))22G<<q	""++113fQi0011I %)!C /." 10s   =G3G0
G-0
G>c                 $    U R                  5         g r'   rd  rF   s    r   &test_throw_to_dead_thread_doesnt_crash3TestGreenlet.test_throw_to_dead_thread_doesnt_crash7  s    779r   c                 &    U R                  S5        g ry   rg  rF   s    r   +test_throw_to_dead_thread_doesnt_crash_wait8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_wait;  s    77=r   c                      " S S[         5      nU" 5       nU R                  UR                  S5      S5        SU l        g )Nc                   &    \ rS rSrS rS rS rSrg)7TestGreenlet.test_recursive_startup.<locals>.convolutedi@  c                 >    [         R                  " U 5        SU l        g r   )r-   __init__countrF   s    r   rq  @TestGreenlet.test_recursive_startup.<locals>.convoluted.__init__A  s    $$T*
r   c                     US:X  a(  U R                   S:X  a  SU l         U R                  S5        [        R                  " X5      $ )NrK   r   r   +   )rr  r   r-   rK  rL  s     r   rK  HTestGreenlet.test_recursive_startup.<locals>.convoluted.__getattribute__D  s6    5=TZZ1_!"DJKKO"33D??r   c                 >     U R                   R                  U5        M  r'   r   r   )rB   r   s     r   rK   ;TestGreenlet.test_recursive_startup.<locals>.convoluted.runI  s    KK&&u- r   )rr  N)r   r   r   r   rq  rK  rK   r   r   r   r   
convolutedro  @  s    @
.r   rz  r   ru  T)r-   r?   r   rb  )rB   rz  r.   s      r   test_recursive_startup#TestGreenlet.test_recursive_startup>  s9    	. 	. L"r*
 %)!r   c                 T  ^^^ [         R                  " 5       mTR                  5         [         R                  " 5       mTR                  5          " UU4S jS[        5      nS nUUU4S jn[        R
                  " 5       n[        U5      /mU" 5       TS   l        TS   R                  5         [         R                  " US9nUR                  5         TR                  5         TR                  5         U R                  [        R
                  " 5       U5        UR                  S5        g )Nc                   $   > \ rS rSrU U4S jrSrg);TestGreenlet.test_threaded_updatecurrent.<locals>.finalizedi[  c                 F   > TR                  5         TR                  5         g r'   releaseacquire)rB   lock1lock2s    r   __del__CTestGreenlet.test_threaded_updatecurrent.<locals>.finalized.__del__\  s     r   r   Nr   r   r   r   r  r   r  r  s   r   	finalizedr  [  s       r   r  c                  ^    [         R                  " 5       R                  R                  5         g r'   r   r   r   r   deallocator=TestGreenlet.test_threaded_updatecurrent.<locals>.deallocatorc  rY  r   c                     > TR                  5         [        R                  " 5         T S	 TR                  5         TR                  5         [        R                  " 5         TR                  5         g r   r  r   r   r  )r.   r  r  s   r   fthread9TestGreenlet.test_threaded_updatecurrent.<locals>.fthreade  sF    MMO!!MMOMMO!MMOr   r   r}   r|   )r   Lockr  objectr   r   r-   bombr   r   r   r  r?   r   )	rB   r  r  r  r:  r   r.   r  r  s	         @@@r   test_threaded_updatecurrent(TestGreenlet.test_threaded_updatecurrentT  s      	  	  	 	2	 ""$%&K!		!G,		 	,,.5	r
r   c                    ^^^ / mUUU4S jmS m[        T5      /mTS   R                  5         [        TTS   5      mTR                  5       nU R                  T5        U R                  US5        g )Nc                    > [         R                  " 5       R                  R                  5       n TS	 [         R                  " 5       R                  Tl         [         R                  " 5       R                  R                  U 5        TR	                  [         R                  " 5       5        g ! TR	                  [         R                  " 5       5        f = fr   )r   r   r   r   r   )r   	initiatorr#   r<  s    r   r<  >TestGreenlet.test_dealloc_switch_args_not_lost.<locals>.worker  s    '')00779Eq	'224;;I3##%,,33E:H//12H//12s   .B* *&Cc                      gr  r   r   r   r   r  ATestGreenlet.test_dealloc_switch_args_not_lost.<locals>.initiator      r   r   r   )r-   r   r   r?   )rB   r   r  r#   r<  s     @@@r   !test_dealloc_switch_args_not_lost.TestGreenlet.test_dealloc_switch_args_not_lost  sk    	3	 f%&q		6!95	  "#r   c                    ^^^ S m " S S[         5      nU" 5       m[        SS9mUUU4S jn[        U5      nU R                  UR	                  5       T5        g )Nc                     U " U0 UD6  g r'   r   )r,  rq   ks      r   _apply0TestGreenlet.test_tuple_subclass.<locals>._apply  s    !MqMr   c                       \ rS rSrS rSrg)1TestGreenlet.test_tuple_subclass.<locals>.mytuplei  c                 r    [         R                  " 5       R                  5         [        R	                  U 5      $ r'   )r   r   r   tuple__len__rF   s    r   r  9TestGreenlet.test_tuple_subclass.<locals>.mytuple.__len__  s&    ##%,,.}}T**r   r   N)r   r   r   r   r  r   r   r   r   mytupler    s    +r   r  r   )rq   c                  h   > T " [         R                  " 5       R                  R                  TT5        g r'   r   )r  r   kwargss   r   switchapply5TestGreenlet.test_tuple_subclass.<locals>.switchapply  s$    8&&(//66fEr   )r  dictr-   r?   r   )rB   r  r  r.   r  r   r  s       @@@r   test_tuple_subclass TestGreenlet.test_tuple_subclass  sL    		+e 	+ y	F$V,r   c                     [        S[        4S[        S 5      05      n " S SU5      n " S SU5      nU" 5         U R                  [        U5        g )NAbstractSubclassrK   c                     g r'   r   rF   s    r   r   7TestGreenlet.test_abstract_subclasses.<locals>.<lambda>  s    r   c                       \ rS rSrSrg):TestGreenlet.test_abstract_subclasses.<locals>.BadSubclassi  r   Nr   r   r   r   BadSubclassr        r   r  c                       \ rS rSrS rSrg);TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclassi  c                     g r'   r   rF   s    r   rK   ?TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclass.run  s    r   r   N)r   r   r   r   rK   r   r   r   r   GoodSubclassr    s    r   r  )r   r-   r   rL   r%  )rB   r  r  r  s       r   test_abstract_subclasses%TestGreenlet.test_abstract_subclasses  sT    "NN#4568
	* 		+ 	 	)[1r   c                    ^ ^ [         R                  " 5       (       d  g [         R                  " 5       S   mTS:  a  g UU 4S jn[        S5       H  nU" 5       (       d  M    g    g )Nr   2   c                  $  >^	^
^^ [         R                  " 5       m
T
R                  5         [         R                  " 5       mTR                  5         S/mU
U4S jn [         R                  " U S9nUR	                  5          " U
UU4S jS[
        5      m	 " U	4S jS[
        5      n/ n[        TS-  5      n[        R                  " 5       nU" 5       nU HI  nS nTS	   (       a  UR                  S
5          g[        5       nTS	   (       a    OFUR                  U5        MK     [        R                  " 5         TS	   (       a  UR                  S
5        gTR                  UR                  U5        U H  nTR                  UR                  U5        M!     g)NFc                  p   > T R                  5         [        R                  " 5         TR                  5         g r'   r  r  s   r   another_threadWTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.another_thread  s!    ##%r   r}   c                   &   > \ rS rSrU UU4S jrSrg)TTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callbacki  c                 P   > TR                  5         TR                  5         STS'   g )NTr   r  )rB   r  r  recycleds    r   r  \TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callback.__del__  s    MMOMMO"&HQKr   r   Nr  )r  r  r  s   r   gc_callbackr    s    ' 'r   r  c                   "   > \ rS rSrU 4S jrSrg)PTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbagei  c                 *   > X l         T" 5       U l        g r'   )cyclecallback)rB   r  s    r   rq  YTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbage.__init__  s    !%J$/MDMr   )r  r  N)r   r   r   r   rq  r   )r  s   r   garbager    s    2 2r   r  r<   r   r|   T)r   r  r  r   r   r  rA   r   r   r   r-   r   r   r   r?   r   )r  r   r  lr   currentr.   r   lastr  r  r  r  NrB   s            @@@@r   attempt?TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt  s/   NN$EMMONN$EMMOwH    7AGGI' 'f '
2& 2 Aac
A))+G	AA;FF2J "}A;  

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

!!*,/0s   # &AAr|   )r   r   r   r-   r    rt   r  rA   r   r   assertGreaterEqualr?   )rB   r  initial_refsr  r   r   r   s   `    @@r   5test_issue_245_reference_counting_subclass_no_threadsBTestGreenlet.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                 "  ^^^^^ SSK Jn  SSK Jn  SSKJm   " S S[
        5      m/ mU" 5       mU4S jmUUUUU4S jn[        R                  " T5      n/ nUS	-   n[        (       a  S
n[        U5       H2  nU" 5       nU" X84S9n	UR                  U5        U	R                  5         M4     U H  n
U
R                  S5        M     TS S 2	 TR                  5         U R                  5         U R                  [        R                  " T5      U5        g )Nr   )r   )r   r  c                       \ rS rSrSrg)STestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.MyGreenleti8  r   Nr   r   r   r   
MyGreenletr  8  r  r   r  c                  D   > T " 5       R                   R                  5         g r'   rx  r  s   r   r  VTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.greenlet_main>  s    L&&(r   c                    > T" T5      nTR                  U5        UR                  5         AU R                  5         TR                  S5        T" 5         g )Nr|   )r   r   r   r   )greenlet_running_eventminer  r   r  r  ref_cleareds     r   thread_mainTTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.thread_mainA  sH    m,DLLKKM"&&( R  Lr   -   r  r   r|   )r   r   r   r   r   r-   r    rt   r   rA   r   r   r   r   r_  r?   )rB   r   r   r  r  thread_ready_eventsr   r   eventr  r  r  r   r  r  r  s              @@@@@r   2test_issue_245_reference_counting_subclass_threads?TestGreenlet.test_issue_245_reference_counting_subclass_threads*  s     	%#'	 	 g	)	 	8 z2 #b(&& L|$AGE;X>F&&u-LLN	 % .JOOB . !H 	&&(4lCr   c                     S n[        U5      nS n[        X25      nU R                  [        5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nc                      g)N   r   r   r   r   no_args\TestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.no_argsx  r  r   c                      gr  r   r   r   r   leafYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.leaf}  r  r   )r-   rL   r%  r   )rB   r   parent_never_startedr  childs        r   >test_falling_off_end_switches_to_unstarted_parent_raises_errorKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_errorw  sJ    	  +73	 D7 y)LLN *))s   A
Ac                     S n[        U5      nS n[        X25      nUR                  5       nU R                  US5        g )Nc                 
    U S4$ N   r   r   s    r   one_argUTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.one_arg  s    r7Nr   c                      gr  r   r   r   r   r  RTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.leaf  r  r   )r   r  r   )rB   r  r  r  r  r;  s         r   7test_falling_off_end_switches_to_unstarted_parent_worksDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works  s@    	  +73	 D7*r   c                   ^  " S S[         5      nU" 5       n/ m[        U4S jU5      nU R                  [        5         UR                  5         S S S 5        U R	                  TS/5        U R                  [        5         UR                  5         S S S 5        U R	                  TS/5        g ! , (       d  f       Nc= f! , (       d  f       N3= f)Nc                       \ rS rSrS rSrg)XTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parenti  c                     US:X  a  [         eg rJ   )r   rL  s     r   rK  iTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parent.__getattribute__  s    5=#O !r   r   NrO  r   r   r   Parentr    s    $r   r  c                  &   > T R                  S5      $ r  r   r"   s   r   r   ZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.<lambda>      DKKOr   r   )r-   rL   r   r   r?   )rB   r  r  r  r#   s       @r   ;test_switch_to_dead_greenlet_with_unstarted_perverse_parentHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent  s    	$[ 	$  &x35IJ y)LLN * 	t$y)LLN *t$ *)
 *)s   B- B>-
B;>
Cc                   ^ / m[        U4S j5      n[        U4S j5      nUR                  5         U R                  TS/5        Xl        UR                  5       nU R	                  U5        U R                  TSS/5        g )Nc                  &   > T R                  S5      $ r  r   r"   s   r   r   DTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>  s    4;;r?r   c                  &   > T R                  S5      $ r  r   r"   s   r   r   r     r  r   r   r  )r-   r   r?   r   r_   )rB   r  r  r;  r#   s       @r   %test_switch_to_dead_greenlet_reparent2TestGreenlet.test_switch_to_dead_greenlet_reparent  sl    *+BC34t$+&!Bx(r   c                 j  ^^ [         R                  " 5       mU4S jnU4S jm[        U5      nUR                  5         [        S 5      nUR                  5         U R	                  UR
                  5        U R                  UR
                  R                  R                  S5        U R	                  UR
                  R                  5        U R                  UR
                  R                  R                  R                  S5        U R                  UR
                  R                  R                  5        g )Nc                     > T " 5         g r'   r   inners   r   outerHTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.outer  s    Gr   c                  P   > T R                  [        R                  " S5      5        g r   )r   r    r   r:  s   r   r'  HTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.inner  s    KKa()r   c                      g r'   r   r   r   r   r   KTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.<lambda>      r   r'  r(  )r   r   r-   r   rY   r   r?   f_codeco_namer   r_   )rB   r(  r9  	unrelatedr'  r:  s       @@r   ,test_can_access_f_back_of_suspended_greenlet9TestGreenlet.test_can_access_f_back_of_suspended_greenlet  s     ""$		* % 

  -	 	S\\*,,44g>S\\001,,33;;WE#,,--445r   c                   ^^^ SSK Jm  SSKJm  UUU4S jm[	        T5      nUR                  S5        UR                  n[        S5       H.  nU R                  UR                  S   U5        UR                  nM0     U R                  UR                  S   S5        U R                  UR                  5        U R                  UR                  S5      S	5        g )
Nr   )partialr   )_test_extension_cppc                    > U S:  a  U TR                  T" TU S-
  5      5      -  $ [        R                  " 5       R                  R	                  5       $ )Nr   r   )	test_callr   r   r   r   )vr7  r6  recurses    r   r;  @TestGreenlet.test_get_stack_with_nested_c_calls.<locals>.recurse  sJ    1u.88!a%9PQQQ&&(//6688r   r>   r:  r|   i  )	functoolsr6   r7  r-   r   r   rA   r?   ra  r   r_   )rB   grr   r   r7  r6  r;  s       @@@r   "test_get_stack_with_nested_c_calls/TestGreenlet.test_get_stack_with_nested_c_calls  s    %)	9
 !
		!qAU^^C0!4LLE  	,a0%,,'2-r   c                 :  ^^ [         R                  " 5       mU4S jnU4S jm[        U5      nUR                  5       n[        S 5      nUR                  5         U R	                  UR
                  R                  S5        U R                  UR                  5        g )Nc                  >   > T " [         R                  " S5      5        g r   )r    r   r&  s   r   r(  6TestGreenlet.test_frames_always_exposed.<locals>.outer  s    #--"#r   c                 (   > TR                  U 5        g r'   )r   )r   r:  s    r   r'  6TestGreenlet.test_frames_always_exposed.<locals>.inner  s    KKr   c                      g r'   r   r   r   r   r   9TestGreenlet.test_frames_always_exposed.<locals>.<lambda>  r/  r   r(  )	r   r   r-   r   r?   r0  r1  r_   r   )rB   r(  r?  r   r2  r'  r:  s        @@r   test_frames_always_exposed'TestGreenlet.test_frames_always_exposed  sx     ""$	$	 		  -	--w7%,,'r   )rb  r  N)F)8r   r   r   r   rC   rG   rR   rV   r\   r`   rj   ru   r   r   r   r   r   r   r   unittestskipIfr	   r   r   r   r   r   r   r  r  r&  r.  r3  r>  rD  rT  r   rd  rh  rk  r{  r  r  r  r  r  r  r  r  r  r  r"  r3  r@  rI  r   r   r   r   r2   r2   5   sw   .117
!
'(D,1 = =~,8+OI0 __&&G55n+ 	 -& 5"	+C
6	; 7) 7)r : :> ) )*-^$4-82 5n(FT __&&EDDDDL+%*)6:.&(r   r2   c                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)TestGreenletSetParentErrorsi   c                   ^^^ 0 m[         R                  " 5       m[         R                  " 5       mUUU4S jnS n[         R                  " US9nUR                  5         TR	                  S5        [        U5      nUR                  5         U R                  [        5       nTS   Ul	        S S S 5        TR                  5         UR                  S5        U R                  [        WR                  5      S5        g ! , (       d  f       NU= f)Nc                  f   > [        S 5      TS'   T R                  5         TR                  S5        g )Nc                      g r'   r   r   r   r   r   QTestGreenletSetParentErrors.test_threaded_reparent.<locals>.run.<locals>.<lambda>  r  r   r.   r|   r  r  s   r   rK   ?TestGreenletSetParentErrors.test_threaded_reparent.<locals>.run  r
  r   c                  ^    [         R                  " 5       R                  R                  5         g r'   r   r   r   r   blankATestGreenletSetParentErrors.test_threaded_reparent.<locals>.blank  rY  r   r}   r|   r.   z&parent cannot be on a different thread)r   r   r   r   r   r-   r   rL   r  r   r   r   r?   rO   rP   )	rB   rK   rU  r  r.   r(   r  r  r  s	         @@@r   test_threaded_reparent2TestGreenletSetParentErrors.test_threaded_reparent  s    !)__&
	 
	2 !!-2	
z*cCyAH +BS]]+-UV +*s    C::
Dc                   ^ / mU4S jn[         R                  " US9nUR                  5         UR                  S5        U R	                  U R
                  S-   S9   " U4S jS[        5      nU" S 5      nU R                  [        R                  5       nUR                  5         S S S 5        U R                  [        WR                  5      S	5        TS S 2	 g ! , (       d  f       N9= f)
Nc                  `   > [        S 5      n TR                  U 5        U R                  5         g )Nc                      g r'   r   r   r   r   r   YTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker.<locals>.<lambda>      Dr   )r-   r   r   )r.   anothers    r   r<  GTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker  s"    L)ANN1HHJr   r}   r|   r   )initial_main_greenletsc                   "   > \ rS rSrU 4S jrSrg)KTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convolutedi7  c                 P   > US:X  a
  TS   U l         [        R                  " X5      $ NrK   r   r   r-   rK  rB   rM  r^  s     r   rK  \TestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convoluted.__getattribute__8  &    5=")!*DK"33D??r   r+   NrO  r^  s   r   rz  rb  7      @ @r   rz  c                      g r'   r   r   r   r   r   ITestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.<lambda><  rS  r   r^  )r   r   r   r   r_  main_greenlets_before_testr-   rL   r   r   r   r?   rO   rP   )rB   r<  r   rz  r.   r(   r^  s         @r   test_unexpected_reparenting7TestGreenletSetParentErrors.test_unexpected_reparenting  s    	 F+			r
& 	&&d>]>]`a>a&b	@ 	@
 |$x~~.#HHJ /S]]+]	_AJ	 /.s   C
C'c                 &  ^^^ / m[         R                  " 5       m[         R                  " 5       mUUU4S jn " U4S jS[        5      n[         R                  " US9nUR	                  5         TR                  S5         U" S 5      nU R                  [        R                  5       nUR                  5         S S S 5        U R                  S[        WR                  5      5        U R                  S[        UR                  5      5        U R                  S	[        UR                  5      5        TR                  5         UR                  S5        TS S 2	 g ! , (       d  f       N= f! TR                  5         UR                  S5        TS S 2	 f = f)
Nc                     > [        S 5      n TR                  U 5        U R                  5         TR                  5         TR	                  S5        g )Nc                      g r'   r   r   r   r   r   hTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.worker.<locals>.<lambda>J  r]  r   r|   )r-   r   r   r   r   )r.   r^  keep_main_aliveswitched_to_greenlets    r   r<  VTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.workerI  s<    L)ANN1HHJ $$&  $r   c                   "   > \ rS rSrU 4S jrSrg)ZTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convolutediO  c                 P   > US:X  a
  TS   U l         [        R                  " X5      $ rd  re  rf  s     r   rK  kTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convoluted.__getattribute__P  rh  r   r+   NrO  ri  s   r   rz  rx  O  rj  r   rz  r}   r|   c                      g r'   r   r   r   r   r   XTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.<lambda>Z      4r   z#Cannot switch to a different threadExpectedCurrent)r   r   r-   r   r   r   rL   r   r   r   rN   rO   rP   r   r   )	rB   r<  rz  r   r.   r(   r^  rt  ru  s	         @@@r   *test_unexpected_reparenting_thread_runningFTestGreenletSetParentErrors.test_unexpected_reparenting_thread_runningC  s    (0#//+	%	@ 	@ F+		!!"%	<(A""8>>2c
 3MM?S]]ASTMM*c#--&89MM)S%78!FF2J
 32 !FF2J
s%    (E( (E9A7E( 
E%!E( ((Fc                 &   [        S 5      nU R                  UR                  [        R                  " 5       5        U R                  [        5       nU?S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nc                      g r'   r   r   r   r   r   GTestGreenletSetParentErrors.test_cannot_delete_parent.<locals>.<lambda>h      Tr   can't delete attribute)
r-   rZ   r   r   r   rL   rM   r?   rO   rP   )rB   r<  r(   s      r   test_cannot_delete_parent5TestGreenletSetParentErrors.test_cannot_delete_parentg  sd    \*fmmX%8%8%:;~.# /S]]+-EF /.s   B
Bc                     U R                  [        5       n[        R                  " 5       ?S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nr  rL   rM   r   r   r   r?   rO   rP   rB   r(   s     r   !test_cannot_delete_parent_of_main=TestGreenletSetParentErrors.test_cannot_delete_parent_of_maino  sI    ~.###%, /S]]+-EF /.s   A
A(c                 `    U R                  [        R                  " 5       R                  5        g r'   )r_   r   r   r   rF   s    r   !test_main_greenlet_parent_is_none=TestGreenletSetParentErrors.test_main_greenlet_parent_is_noneu  s    (--/667r   c                    ^  S nU 4S jn[        U5      nT R                  U5        U" U5        UR                  5         T R                  U5        U" U5        UR                  5         g )Nc                  ^    [         R                  " 5       R                  R                  5         g r'   r   r   r   r   bgCTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.bgz  s    !((//1r   c                    > S STS4 Hb  nTR                  [        5       nXl        S S S 5        TR                  [	        WR
                  5      S[        U5      R                  -   5        Md     g ! , (       d  f       NN= f)Nr   42z4GreenletChecker: Expected any type of greenlet, not )rL   r%  r   r?   rO   rP   typer   )gletpr(   rB   s      r   checkFTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.check~  sg    1dD(&&y1S"#K 2   &JTRSWM]M]]_	 )11s   A//
A=	)r-   r   r   r   )rB   r  r  r.   s   `   r   test_set_parent_wrong_types7TestGreenletSetParentErrors.test_set_parent_wrong_typesy  sW    	2	_ Oa 	

a 	

r   c                     [        S 5      nU R                  [        5       nXl        S S S 5        U R	                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nc                      g r'   r   r   r   r   r   @TestGreenletSetParentErrors.test_trivial_cycle.<locals>.<lambda>  r}  r   cyclic parent chain)r-   rL   r  r   r?   rO   rP   )rB   r  r(   s      r   test_trivial_cycle.TestGreenletSetParentErrors.test_trivial_cycle  sI    <(z*cK +S]]+-BC +*s   A
A%c                    U R                  [        5       n[        R                  " 5       [        R                  " 5       l        S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nz(cannot set the parent of a main greenletr  r  s     r   test_trivial_cycle_main3TestGreenletSetParentErrors.test_trivial_cycle_main  sT    ~.#+3+>+>+@H!( /S]]+-WX /.s   .A22
B c                    [        S 5      n[        S 5      n[        S 5      nX!l        X2l        U R                  [        5       nXl        S S S 5        U R	                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nc                      g r'   r   r   r   r   r   ?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>  rC  r   c                      g r'   r   r   r   r   r   r    rC  r   c                      g r'   r   r   r   r   r   r    rC  r   r  )r-   r   rL   r  r?   rO   rP   )rB   r/   r   g3r(   s        r   test_deeper_cycle-TestGreenletSetParentErrors.test_deeper_cycle  sg    &&&		z*cI +S]]+-BC +*s   A;;
B	r   N)r   r   r   r   rW  rn  r  r  r  r  r  r  r  r  r   r   r   r   rN  rN     s<    W2'R"HGG88DY	Dr   rN  c                   ^    \ rS rSr\" \S5      (       d  SS jrS rS rS r	S r
S	 rS
 rSrg)TestRepri  assertEndsWithNc                 J    U R                  UR                  U5      XU45        g r'   )r   endswith)rB   rc  suffixmsgs       r   r  TestRepr.assertEndsWith  s    OOAJJv.C0@Ar   c                 d    [        [        R                  " 5       5      nU R                  US5        g )N current active started main>)reprr   r   r  rB   rs     r   test_main_while_running TestRepr.test_main_while_running  s&    $$&'A>?r   c                    ^ [         R                  " 5       mU4S jn[        U5      nUR                  5       nU R	                  US5        g )Nc                     > [        T 5      $ r'   )r  r+  s   r   rK   -TestRepr.test_main_in_background.<locals>.run  s    :r    suspended active started main>)r   r   r-   r   r  )rB   rK   r.   r  r:  s       @r   test_main_in_background TestRepr.test_main_in_background  s>    ""$	 HHJA@Ar   c                 N    [        [        5       5      nU R                  US5        g )Nz	 pending>)r  r-   r  r  s     r   test_initialTestRepr.test_initial  s    A{+r   c                 4  ^ [         R                  " 5       m " U4S jS[        R                  5      nU" 5       nUR	                  5         UR                  S5        U R                  UR                  S5        U R                  UR                  S5        [        S5       H  n[        R                  " S5        M     [        S5       HO  nU R                  UR                  R                  5        [        UR                  5      nU R                  US5        MQ     g )	Nc                   .   > \ rS rSrS=rrSrU 4S jrSrg)/TestRepr.test_main_from_other_thread.<locals>.Ti  Nc                    > [        T5      U l        [        R                  " 5       U l        [        U R                  5      U l        g r'   )r  original_mainr   r   	main_gletr  )rB   r:  s    r   rK   3TestRepr.test_main_from_other_thread.<locals>.T.run  s0    %)$Z"!)!4!4!6#'#7 r   )r  r  r  )	r   r   r   r   r  r  r  rK   r   r+  s   r   Tr    s    *..MKI8 8r   r  r|   r  r  r6   gMbP?z (thread exited) dead>)r   r   r   r   r   r   r  r  r  rA   r   r   r   r  rh   r  )rB   r  r   r   r  r:  s        @r   test_main_from_other_thread$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                    [        S 5      nUR                  5         U R                  [        U5      S5        U R	                  S[        U5      5        U R	                  S[        U5      5        U R	                  S[        U5      5        g )Nc                      g r'   r   r   r   r   r   $TestRepr.test_dead.<locals>.<lambda>  s    r   z dead>	suspendedstartedactive)r-   r   r  r  assertNotInr[   s     r   	test_deadTestRepr.test_dead  se    %	
DGX.d1g.DG,47+r   c                     [        S 5      n[        S 5      n[        R                  " 5       nXU4 H3  nU R                  U< [        5        U R                  U< [        5        M5     g )Nc                      g r'   r   r   r   r   r   >TestRepr.test_formatting_produces_native_str.<locals>.<lambda>  r  r   c                      g r'   r   r   r   r   r   r    r  r   )r-   r   r   r   rO   )rB   g_deadg_not_startedg_curr.   s        r   #test_formatting_produces_native_str,TestRepr.test_formatting_produces_native_str  s_     \*#L1##%-A!! !! .r   r   r'   )r   r   r   r   r*  r   r  r  r  r  r  r  r  r   r   r   r   r  r    s7    8-..	B@B,!=F,r   r  c                   &    \ rS rSrS rS rS rSrg)TestMainGreenleti  c                     S[        [        R                  " 5       5      ;   d   e[        [        R                  " 5       5      nS[        U5      ;  d   eU$ )Nr:  )r  r   r   r  )rB   r   s     r   _check_current_is_main'TestMainGreenlet._check_current_is_main  sH    h1134444$$&'T!W$$$r   c                 b    U R                  5       n[        SU40 5      nU R                  U5        g )Nsubclass)r  r  rY   )rB   	main_typer  s      r   )test_main_greenlet_type_can_be_subclassed:TestMainGreenlet.test_main_greenlet_type_can_be_subclassed  s.    //1	
YL"5X&r   c                 v    U R                  5         U R                  [        R                  " 5       [        5        g r'   )r  r   r   r   r-   rF   s    r   test_main_greenlet_is_greenlet/TestMainGreenlet.test_main_greenlet_is_greenlet  s'    ##%h113[Ar   r   N)r   r   r   r   r  r  r  r   r   r   r   r  r    s    '
Br   r  c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)TestBrokenGreenletsi  c                     S n[         R                  R                  U5      nSUl        U R	                  [
        S5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nc                      [        S5      e)NzNever get here)AssertionErrorr   r   r   r,  <TestBrokenGreenlets.test_failed_to_initialstub.<locals>.func  s     !122r   Tz;Failed to switch stacks into a greenlet for the first time.)r   	_greenletUnswitchableGreenletforce_switch_errorassertRaisesRegexSystemErrorr   )rB   r,  r.   s      r   test_failed_to_initialstub.TestBrokenGreenlets.test_failed_to_initialstub  sW    	3 33D9###K$acHHJc c cs    A
A(c                   ^ / mU4S jn[         R                  R                  U5      nUR                  5         U R	                  TS/5        UR                  5         U R	                  TSS/5        SUl        U R                  [        S5         UR                  5         S S S 5        SUl        UR                  5         U R	                  T/ SQ5        g ! , (       d  f       N:= f)Nc                     > T R                  S5        [        R                  " 5       R                  R	                  5         T R                  S5        [        R                  " 5       R                  R	                  5         T R                  S5        g )Nr   r<   r6   r7   )runss   r   r,  DTestBrokenGreenlets.test_failed_to_switch_into_running.<locals>.func,  sZ    KKN!((//1KKN!((//1KKNr   r   r<   Tz0Failed to switch stacks into a running greenlet.F)r   r<   r6   )r   r  r  r   r?   r  r  r  )rB   r,  r.   r  s      @r   "test_failed_to_switch_into_running6TestBrokenGreenlets.test_failed_to_switch_into_running*  s    	 33D9	
s#	
1v&###K$VXHHJX  %	
y)X Xs   C
C c                     U R                  S5      nU R                  SUR                  5        U R                  UR                  U R	                  5       5        g )Nzfail_slp_switch.pyzfail_slp_switch is running)assertScriptRaisesrN   output
returncode,get_expected_returncodes_for_aborted_processrB   exs     r   &test_failed_to_slp_switch_into_running:TestBrokenGreenlets.test_failed_to_slp_switch_into_runningF  sA    $$%9:2BII>bmmT%V%V%XYr   c                     U R                  S5      nU R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  SU5        g )Nzfail_switch_two_greenlets.pyz	In g1_runTRACEzLEAVE TRACEzFalling off end of mainzFalling off end of g1_runzFalling off end of g2
run_scriptrN   rB   r  s     r   #test_reentrant_switch_two_greenlets7TestBrokenGreenlets.test_reentrant_switch_two_greenletsL  sh    !?@k6*gv&mV,/816:-v6r   c                     U R                  SSS9nU R                  SUR                  5        U R                  SUR                  5        g )Nzfail_switch_three_greenlets.py)r   )	exitcodesr%  zpositional arguments)r  rN   r  r  s     r   %test_reentrant_switch_three_greenlets9TestBrokenGreenlets.test_reentrant_switch_three_greenletsV  s@     $$%EQU$Vk299-,bii8r   c                 J    U R                  S5      nU R                  SU5        g )Nzfail_switch_three_greenlets2.pya  RESULTS: [('trace', 'switch'), ('trace', 'switch'), ('g2 arg', 'g2 from tracefunc'), ('trace', 'switch'), ('main g1', 'from g2_run'), ('trace', 'switch'), ('g1 arg', 'g1 from main'), ('trace', 'switch'), ('main g2', 'from g1_run'), ('trace', 'switch'), ('g1 from parent', 'g1 from main 2'), ('trace', 'switch'), ('main g1.2', 'g1 done'), ('trace', 'switch'), ('g2 from parent', ()), ('trace', 'switch'), ('main g2.2', 'g2 done')]r  r  s     r   &test_reentrant_switch_three_greenlets2:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2_  s)     !BC= 		
r   c                 J    U R                  S5      nU R                  SU5        g )Nz#fail_initialstub_already_started.pya!  RESULTS: ['Begin C', 'Switch to b from B.__getattribute__ in C', ('Begin B', ()), '_B_run switching to main', ('main from c', 'From B'), 'B.__getattribute__ back from main in C', ('Begin A', (None,)), ('A dead?', True, 'B dead?', True, 'C dead?', False), 'C done', ('main from c.2', None)]r  r  s     r   4test_reentrant_switch_GreenletAlreadyStartedInPythonHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPythonq  s'    !FG1
 	
r   c                 J    U R                  S5      nU R                  SU5        g )Nzfail_clearing_run_switches.pyzRESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]r  r  s     r   *test_reentrant_switch_run_callable_has_del>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_del}  s'    !@A 	
r   r   N)r   r   r   r   r  r  r
  r  r  r  r  r  r   r   r   r   r  r    s+    
*8Z79
$


r   r  c                   T    \ rS rSr\R
                  " \" \S5      S5      S 5       rSr	g)
TestModulei  _is_gil_enabledz,Needs 3.13 and above for sys._is_gil_enabledc                     [         (       a%  U R                  [        R                  " 5       5        g U R	                  [        R                  " 5       5        g r'   )r   r   r    r"  r   rF   s    r   test_no_gil_on_free_threaded'TestModule.test_no_gil_on_free_threaded  s6     '&S0023OOC//12r   r   N)
r   r   r   r   rK  
skipUnlessr*  r    r$  r   r   r   r   r!  r!    s.    &78GI3I3r   r!  __main__)r   r    r   r   rK  abcr   r   r   r-   r>  r   r   r	   r
   r   	leakcheckr   r   rJ  r   r$   r0   r2   rN  r  r  r  r!  r   r:  r   r   r   <module>r*     s    	 
       ,  "   ) & (		 	H(8 H(VjD( jDZSx SlBx B.k
( k
Z3 3 zMMO r   