HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/greenlet/tests/__pycache__/test_greenlet.cpython-310.pyc
o

���g���@sddlZddlZddlZddlZddlZddlmZddlmZddlZddlmZ	ddl
mZddl
mZddl
m
Z
dd	lmZGd
d�de�Zdd
�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zedkr�e��dSdS)�N)�ABCMeta)�abstractmethod)�greenlet�)�TestCase)�RUNNING_ON_MANYLINUX)�PY313)�fails_leakcheckc@�eZdZdS)�	SomeErrorN��__name__�
__module__�__qualname__�rr�G/usr/local/lib/python3.10/dist-packages/greenlet/tests/test_greenlet.pyr�rcCs0z
t��j��Wt�|�t��d���Nr)r�
getcurrent�parent�switch�append�sys�exc_infor��seenrrr�fmain s�rcCs"dd�}t||d�}|�|�dS)NcSs|��Nr)�excrrr�crasher,�zsend_exception.<locals>.crasher�r��RawGreenletr)�grr�g1rrr�send_exception)sr&c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Ze�eo=ed�dd��Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z e!d]d7d8��Z"e!d9d:��Z#d;d<�Z$e!d=d>��Z%d?d@�Z&dAdB�Z'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+e�eo�edK�dLdM��Z,dNdO�Z-dPdQ�Z.dRdS�Z/dTdU�Z0dVdW�Z1dXdY�Z2dZd[�Z3d\S)^�TestGreenletcs^g��fdd�}t|�}��d�|����d�|����d�|��ttd���dS)Ncs&��d�t��j����d�dS)Nr��rrrrrr��lstrr�f7s
z'TestGreenlet._do_simple_test.<locals>.fr���)r#rr�assertEqual�list�range)�selfr,r$rr*r�_do_simple_test4s


zTestGreenlet._do_simple_testcC�|��dSr)r4�r3rrr�test_simpleCszTestGreenlet.test_simplecCsNt�}|�t��}|��Wd�n1swY|�dt|j��dS�N�run)r#�assertRaises�AttributeErrorr�assertIn�str�	exception�r3r$rrrr�(test_switch_no_run_raises_AttributeErrorFs

�z5TestGreenlet.test_switch_no_run_raises_AttributeErrorcCsPt�}|�t��
}|�t�Wd�n1swY|�dt|j��dSr8)r#r:r;�throwrr<r=r>r?rrr�'test_throw_no_run_raises_AttributeErrorMs
�z4TestGreenlet.test_throw_no_run_raises_AttributeErrorcCs*tdd�}|�|�|�|jt���dS)Nr!)r#�assertIsNotNone�assertIsrrr�r3r$rrr�test_parent_equals_NoneTs

z$TestGreenlet.test_parent_equals_NonecCs$tdd�}|�|�|�|j�dS)N)r9)r#rC�assertIsNoner9rErrr�test_run_equals_NoneY�

z!TestGreenlet.test_run_equals_Nonecs�g��fdd�}t|�}t|�}|��|�t��d�|��|�t��d�|��|�t��d�|�|jd�|��|�t��d�|�|jd�dS)Ncs*��d�t��j����ddg�dS)Nr)rrrrr�extendrr*rrr,as
z)TestGreenlet.test_two_children.<locals>.frr-r.T�)r#rr0�len�dead)r3r,r$�hrr*r�test_two_children^szTestGreenlet.test_two_childrencsfg��fdd����fdd�}t|�}|�t�|�d�|��|��gd��|�t�|�d�dS)Ncs��d�t��j��dS)N�br)rr*rrr,us
z3TestGreenlet.test_two_recursive_children.<locals>.fcs(��d�t��}|����d�dS)N�a�c)rr#r�r$�r,r+rrr$ys
z3TestGreenlet.test_two_recursive_children.<locals>.gr-)rQrPrR)r#r0r�getrefcountrrErrTr�test_two_recursive_childrenrsz(TestGreenlet.test_two_recursive_childrencsfg���fdd���fdd�td�D�}|D]}|��q|D]}|�d�q��t��t|��dS)Ncs�����d�dS�NT)r4rr)r3�successrrr,�sz$TestGreenlet.test_threads.<locals>.fcsg|]}tj�d��qS)��target)�	threading�Thread)�.0�i�r,rr�
<listcomp>�sz-TestGreenlet.test_threads.<locals>.<listcomp>�
)r2�start�joinr0rL)r3�ths�thr)r,r3rXr�test_threads�s
zTestGreenlet.test_threadscCs�g}tt�}tt�}|�|�|�|�||_|�|g�|�t|j�|�|tg�|��}|�|d�|�|tg�|�d�}|�|d�|�|tg�dS)Nr�)r#rrrr0r:r)r3rr%�g2�valuerrr�test_exception�s


zTestGreenlet.test_exceptioncCs8g}tt�}|�|�|�tt|t�|�|tg�dSr)r#rrr:�KeyErrorr&r0)r3rr%rrr�test_send_exception�s

z TestGreenlet.test_send_exceptioncCspg}tt�}tt�}|�|�|�|�|�|g�~t��|�|tjg�~t��|�|tjtjg�dSr)r#rrr0�gc�collectr�GreenletExit)r3rr%rhrrr�test_dealloc�s

zTestGreenlet.test_dealloccCs|dd�}t|�}|��tj}ddlm}|�}t_z~W|t_n|t_w|��}|�d|�|�d|�|�d|�dS)NcSs,z
t��j��WdStjytd�wr)rrrrrorrrrrr9�s
�zHTestGreenlet.test_dealloc_catches_GreenletExit_throws_other.<locals>.runr)�StringIO�	Exception�ignoredr)r#rr�stderr�iorq�getvaluer<)r3r9r$�	oldstderrrqrt�vrrr�.test_dealloc_catches_GreenletExit_throws_other�sz;TestGreenlet.test_dealloc_catches_GreenletExit_throws_otherz=Sometimes flaky (getting one GreenletExit in the second list)c	sg�g�t���t���t���t���������fdd�}tj|d�}|����d�|��g�|�t��d��dd�=t��|��g���	���d�z|��t
jg�W��	�|�d��dd�=�dd�=dS��	�|�d��dd�=�dd�=w)NcsZtt�}|�����|�~t�������d�t������d�t�dS)Nr()r#rrrrmrn�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�somerefrrr,�s




z1TestGreenlet.test_dealloc_other_thread.<locals>.frYrarr()
r[�Eventr\rbr{r0rLrmrnrzrrorc)r3r,�trr|r�test_dealloc_other_thread�s6




�

z&TestGreenlet.test_dealloc_other_threadcsf�fdd�}t|�}|��}��||ju���|�|��}��|���|d���|jd�dS)Ncs,t�d�}��|jd�t��j�|�dS)Nr�meaning of life)r�	_getframer0�f_backrrrrr_r6rr�f1s
z#TestGreenlet.test_frame.<locals>.f1r�)r#r�
assertTrue�gr_frame�assertFalser0)r3r�r$�frame�from_grr6r�
test_frames

zTestGreenlet.test_framecCsLdd�}tj|dd�}tj|dd�}|��|��|�d�|�d�dS)Ncst�fdd��}|��dS)Ncs
t���Sr)�time�sleepr��xrr�<lambda>$�
z>TestGreenlet.test_thread_bug.<locals>.runner.<locals>.<lambda>r")r�r$rr�r�runner#sz,TestGreenlet.test_thread_bug.<locals>.runner)g�������?�rZ�args)g333333�?ra)r[r\rbrc)r3r��t1�t2rrr�test_thread_bug"s
zTestGreenlet.test_thread_bugcs.�fdd�}t|�jddd�}��|d�dS)Ncs��|d���|d�dS)Nr.r-�*)r0�rQrPr6rrr9.sz,TestGreenlet.test_switch_kwargs.<locals>.runr.r-r�r��r#rr0)r3r9r�rr6r�test_switch_kwargs-szTestGreenlet.test_switch_kwargscCsRdd�}t|�}|�ddi|�d��|�dddif|���|�d|���dS)NcSs2t��jj|d�t��jjddd�||dfS)Nr�r-r(�rrrrr�rrrr96sz6TestGreenlet.test_switch_kwargs_to_parent.<locals>.runr�r()r-)r(�	)r#r0r)r3r9r$rrr�test_switch_kwargs_to_parent5s
z)TestGreenlet.test_switch_kwargs_to_parentcs�i�t���t������fdd�}tj|d�}|����d�|�tj���d��Wd�n1s8wY��	�|�
d����dS)Nc�&tdd���d<�����d�dS)NcS�dSrrrrrrr�E�zITestGreenlet.test_switch_to_another_thread.<locals>.run.<locals>.<lambda>r$ra�r#rzr{r��
created_event�data�
done_eventrrr9D�z7TestGreenlet.test_switch_to_another_thread.<locals>.runrYrar$)r[r�r\rbr{r:r�errorrrzrc�clear)r3r9�threadrr�r�test_switch_to_another_thread?s
�
z*TestGreenlet.test_switch_to_another_threadcs*��fdd�}�fdd��t|���dS)Ncs:ztd��t��}t������|t���YdS)N�fun)�
ValueErrorrrr#rr0)r�rNr3rrr,Ssz&TestGreenlet.test_exc_state.<locals>.fcs��t��d�dS)N)NNN)r0rrrr6rrrN[�z&TestGreenlet.test_exc_state.<locals>.hr")r3r,rr�r�test_exc_stateRszTestGreenlet.test_exc_statecCs�dd�}dd�}dd�}t|�}|�|ji�|��|�|jd�|�|jddi�|j|_|�|jddi�|�t||�|�t||d�dS)	NcSsdt��_dS�Nr�)rr�testrrrrr,a�z*TestGreenlet.test_instance_dict.<locals>.fcSs|`dSr��__dict__rSrrr�deldictc�z0TestGreenlet.test_instance_dict.<locals>.deldictcSs
||_dSrr�)r$rirrr�setdicte�
z0TestGreenlet.test_instance_dict.<locals>.setdictr�r�)r#r0r�rr�r:�	TypeError)r3r,r�r�r$rrr�test_instance_dict`szTestGreenlet.test_instance_dictcs2g��fdd�}t|�}|��|��dg�dS)Ncs��tt��d��dSr8)r�hasattrrrr��has_runrr�funcss�z;TestGreenlet.test_running_greenlet_has_no_run.<locals>.funcFr��r3r�r$rr�r� test_running_greenlet_has_no_runqs
z-TestGreenlet.test_running_greenlet_has_no_runcCs0ddl}|�t|jt��|�t|jt��dSr)�copyr:r�r#�deepcopy)r3r�rrr�
test_deepcopy|szTestGreenlet.test_deepcopycs�tdd���t���g����fdd�}t|�d�}|��~|���|��d��|��dj���dd�=d�d�dS)NcSr�rrrrrrr��r�z;TestGreenlet.test_parent_restored_on_kill.<locals>.<lambda>csLz���WdStjy%��t��j���t������YdSwr)rrrorrrr��hub�main�resultrr�worker�s�z9TestGreenlet.test_parent_restored_on_kill.<locals>.workerr!rr)r#rrrr�rDr)r3r�r$rr�r�test_parent_restored_on_kill�s	

z)TestGreenlet.test_parent_restored_on_killcCsNt�}tdd�|d�}|�t��
|��Wd�dS1s wYdS)NcSr�rrrrrrr��r�z9TestGreenlet.test_parent_return_failure.<locals>.<lambda>r!)r#r:r;r)r3r%rhrrr�test_parent_return_failure�s

"�z'TestGreenlet.test_parent_return_failurecCs2Gdd�dt�}|dd��}|�t|jt��dS)Nc@�eZdZdd�ZdS)z>TestGreenlet.test_throw_exception_not_lost.<locals>.mygreenletcSszt�Yt�||�Sr)rrr#�__getattribute__�r3�namerrrr��s
zOTestGreenlet.test_throw_exception_not_lost.<locals>.mygreenlet.__getattribute__N�r
rrr�rrrr�
mygreenlet��r�cSr�rrrrrrr��r�z<TestGreenlet.test_throw_exception_not_lost.<locals>.<lambda>)r#r:rrA)r3r�r$rrr�test_throw_exception_not_lost�sz*TestGreenlet.test_throw_exception_not_lostFcsTg�dd�����fdd�}tj|d�}|��|�d�~�r$|��|�tj��}�d�t	�Wd�n1s<wY�sTt
|j�}|�|dkpQd	|v�n	|�
t
|j�d�t�djd
�r�|�t���dj��Wd�n1s|wY�s�t�djjd
�r��djj��n|��dj�~d��dd�=d|_dS)NcS�t��j��dSrr�rrrrr���zGTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.workercs6t��}|����|��r|��t��dSdSr)r#rrrrrS�r��wait_for_cleanupr�rr�creator�s
�zHTestGreenlet._do_test_throw_to_dead_thread_doesnt_crash.<locals>.creatorrYrar�Bcannot switch to a different thread (which happens to have exited)z
Cannot switchr�T)r[r\rbrc�wait_for_pending_cleanupsr:rr�rArr=r>r�r0r�r��RuntimeErrorr��f_localsrG�expect_greenlet_leak)r3r�r�r�r�srr�r�*_do_test_throw_to_dead_thread_doesnt_crash�sF
�
����

z7TestGreenlet._do_test_throw_to_dead_thread_doesnt_crashcCr5r�r�r6rrr�&test_throw_to_dead_thread_doesnt_crash�sz3TestGreenlet.test_throw_to_dead_thread_doesnt_crashcCs|�d�dSrWr�r6rrr�+test_throw_to_dead_thread_doesnt_crash_wait�r�z8TestGreenlet.test_throw_to_dead_thread_doesnt_crash_waitcCs2Gdd�dt�}|�}|�|�d�d�d|_dS)Nc@�$eZdZdd�Zdd�Zdd�ZdS)z7TestGreenlet.test_recursive_startup.<locals>.convolutedcSst�|�d|_dSr)r#�__init__�countr6rrrr��s

z@TestGreenlet.test_recursive_startup.<locals>.convoluted.__init__cSs.|dkr|jdkrd|_|�d�t�||�S)Nr9rr�+)r�rr#r�r�rrrr��s
zHTestGreenlet.test_recursive_startup.<locals>.convoluted.__getattribute__cSs	|j�|�qr�rr�r3rirrrr9�s�z;TestGreenlet.test_recursive_startup.<locals>.convoluted.runN)r
rrr�r�r9rrrr�
convoluted�sr�r�r�T)r#r0rr�)r3r�r$rrr�test_recursive_startup�s
z#TestGreenlet.test_recursive_startupcs�t������t������G��fdd�dt�}dd�}���fdd�}t��}t|�g�|��d_�d��tj	|d�}|�
�������|�t��|�|�
d	�dS)
NcseZdZ��fdd�ZdS)z;TestGreenlet.test_threaded_updatecurrent.<locals>.finalizedcs������dSr��release�acquirer6��lock1�lock2rr�__del__szCTestGreenlet.test_threaded_updatecurrent.<locals>.finalized.__del__N�r
rrr�rr�rr�	finalizedsr�cSr�rr�rrrr�deallocatorr�z=TestGreenlet.test_threaded_updatecurrent.<locals>.deallocatorcs:���t���d=������t�����dSr�r�rrr�r�r$r�r�rr�fthreadsz9TestGreenlet.test_threaded_updatecurrent.<locals>.fthreadrrYra)r[�Lockr��objectrrr#�bombrr\rbr�r0rc)r3r�r�r�r�r�rr�r�test_threaded_updatecurrents"

z(TestGreenlet.test_threaded_updatecurrentcsbg����fdd��dd��t��g��d��t��d�����}|���|�|d�dS)Nc
sVt��j��}�d=t��j�_zt��j�|�W��t���dS��t���wr)rrrrr)ri��	initiatorrr�rrr�8s"z>TestGreenlet.test_dealloc_switch_args_not_lost.<locals>.workercS�dSr�rrrrrrEr zATestGreenlet.test_dealloc_switch_args_not_lost.<locals>.initiatorrr�)r#rr�r0r�rr�r�!test_dealloc_switch_args_not_lost6s

z.TestGreenlet.test_dealloc_switch_args_not_lostcsTdd��Gdd�dt�}|��tdd�����fdd�}t|�}|�|����dS)	NcSs||i|��dSrr)r�rQ�krrr�_apply^r�z0TestGreenlet.test_tuple_subclass.<locals>._applyc@r�)z1TestGreenlet.test_tuple_subclass.<locals>.mytuplecSst����t�|�Sr)rrr�tuple�__len__r6rrrrbs
z9TestGreenlet.test_tuple_subclass.<locals>.mytuple.__len__N)r
rrrrrrr�mytuplear�rr�)rQcs�t��jj���dSrr�r�rr��kwargsrr�switchapplygsz5TestGreenlet.test_tuple_subclass.<locals>.switchapply)r�dictr#r0r)r3rr
r$rrr�test_tuple_subclassPs
z TestGreenlet.test_tuple_subclasscCsPtdtfdtdd��i�}Gdd�d|�}Gdd�d|�}|�|�t|�dS)	N�AbstractSubclassr9cSr�rrr6rrrr�pr�z7TestGreenlet.test_abstract_subclasses.<locals>.<lambda>c@r
)z:TestGreenlet.test_abstract_subclasses.<locals>.BadSubclassNrrrrr�BadSubclassrrrc@r�)z;TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclasscSr�rrr6rrrr9vr z?TestGreenlet.test_abstract_subclasses.<locals>.GoodSubclass.runN)r
rrr9rrrr�GoodSubclassur�r)rr#rr:r�)r3r
rrrrr�test_abstract_subclassesls�z%TestGreenlet.test_abstract_subclassescsPt��sdSt��d��dkrdS��fdd�}td�D]}|�r%dSqdS)Nr�2c	st������t������dg���fdd�}tj|d�}|��G���fdd�dt��G�fdd�dt�}g}t�d	�}t��}|�}|D]}d}�d
r[|�	d�dSt
�}�d
rdn|�|�qKt�
��d
rw|�	d�dS��|j|�|D]	}��|j|�q�dS)
NFcs���t�����dSrr�rr�rr�another_thread��zWTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.another_threadrYcseZdZ���fdd�ZdS)zTTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callbackcs������d�d<dS)NTrr�r6�r�r��recycledrrr��rz\TestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.gc_callback.__del__Nr�rrrr�gc_callback�src�eZdZ�fdd�ZdS)zPTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbagecs||_��|_dSr)�cycle�callbackr6�rrrr��szYTestGreenlet.test_implicit_parent_with_threads.<locals>.attempt.<locals>.garbage.__init__N)r
rrr�rrrr�garbage��rr-rraT)r[r�r�r\rbr�r2rrrcr#rrmrnr0r)	rr�r�lr��currentr$�_�last��Nr3)rr�r�rr�attempt�s>

z?TestGreenlet.test_implicit_parent_with_threads.<locals>.attemptr/)rm�	isenabled�
get_thresholdr2)r3r#rrr!r�!test_implicit_parent_with_threads|s-��z.TestGreenlet.test_implicit_parent_with_threadscs|ddlm�ddlm�Gdd�dt�}t�|�}g�_���fdd�}td�D]}||���q(�`��	t�|�|�dS)	Nr�r)roc@r
)zTTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.GreenletNrrrrr�Greenlet�rr(cs6z	��j��WdS�y�j����YdSwr)rr�gletsrr�rorr3rr�
greenlet_main�s
�zYTestGreenlet.test_issue_245_reference_counting_subclass_no_threads.<locals>.greenlet_mainra)
rrror#rrUr)r2rr0)r3r(�initial_refsr+rrr*r�5test_issue_245_reference_counting_subclass_no_threads�s
zBTestGreenlet.test_issue_245_reference_counting_subclass_no_threadsz;The manylinux images appear to hang on this test on 3.13rc2c
s�ddlm}ddlm}ddlm�Gdd�dt��g�|���fdd�������fd	d
�}t���}g}t|d�D]}|�}|||fd�}|�	|�|�
�q<|D]}	|	�d
�qT�dd�=���|�
�|�t���|�dS)Nr)r\)r�r'c@r
)zSTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.MyGreenletNrrrrr�
MyGreenlet�rr.cs��j��dSrr�rr'rrr+�szVTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.greenlet_maincs8���}��|�|��~|����d���dS)Nra)rrrzr{)�greenlet_running_event�mine�r.rr)r+�ref_clearedrr�thread_main�s


zTTestGreenlet.test_issue_245_reference_counting_subclass_threads.<locals>.thread_main�-r�ra)r[r\r�rrr#rrUr2rrbr{rzr�r0)
r3r\r�r3r,�thread_ready_eventsr�eventr�r�rr1r�2test_issue_245_reference_counting_subclass_threads�s.	
�


z?TestGreenlet.test_issue_245_reference_counting_subclass_threadscCsZdd�}t|�}dd�}t||�}|�t��
|��Wd�dS1s&wYdS)NcSr)N�
rrrrr�no_argsr z\TestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.no_argscSrr�rrrrr�leaf"r zYTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_error.<locals>.leaf)r#r:r�r)r3r9�parent_never_startedr:�childrrr�>test_falling_off_end_switches_to_unstarted_parent_raises_errors

"�zKTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_raises_errorcCs:dd�}t|�}dd�}t||�}|��}|�|d�dS)NcSs|dfS�N�rr�rrr�one_arg,r�zUTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.one_argcSrr�rrrrrr:1r zRTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_works.<locals>.leaf)r�r?r�)r3r@r;r:r<r�rrr�7test_falling_off_end_switches_to_unstarted_parent_works+s
zDTestGreenlet.test_falling_off_end_switches_to_unstarted_parent_workscs�Gdd�dt�}|�}g�t�fdd�|�}|�t��|��Wd�n1s*wY|��dg�|�t��|��Wd�n1sJwY|��dg�dS)Nc@r�)zXTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.ParentcSs|dkrt�dSr8)rr�rrrr�;s�ziTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.Parent.__getattribute__Nr�rrrr�Parent:r�rBc�
��d�Sr��rrrrrr�Br�zZTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parent.<locals>.<lambda>r�)r#r:rrr0)r3rBr;r<rrr�;test_switch_to_dead_greenlet_with_unstarted_perverse_parent9s
�
�zHTestGreenlet.test_switch_to_dead_greenlet_with_unstarted_perverse_parentcsfg�t�fdd��}t�fdd��}|��|��dg�||_|��}|�|�|��ddg�dS)NcrCr>rDrrrrr�Pr�zDTestGreenlet.test_switch_to_dead_greenlet_reparent.<locals>.<lambda>crCr�rDrrrrr�Qr�r�r?)r#rr0rrG)r3r;r<r�rrr�%test_switch_to_dead_greenlet_reparentNs
z2TestGreenlet.test_switch_to_dead_greenlet_reparentcs�t����fdd�}�fdd��t|�}|��tdd��}|��|�|j�|�|jjjd�|�|jj	�|�|jj	jjd�|�
|jj	j	�dS)	Ncs
��dSrrr��innerrr�outerbr�zHTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.outercs��t�d��dSr)rrr�r�r�rrrHer�zHTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.innercSr�rrrrrrr�nr�zKTestGreenlet.test_can_access_f_back_of_suspended_greenlet.<locals>.<lambda>rHrI)rrr#rrCr�r0�f_code�co_namer�rG)r3rIr��	unrelatedr�rHr�r�,test_can_access_f_back_of_suspended_greenlet\sz9TestGreenlet.test_can_access_f_back_of_suspended_greenletcs�ddlm�ddlm����fdd��t��}|�d�|j}td�D]}|�|j	d|�|j
}q$|�|j	dd�|�|j
�|�|�d	�d
�dS)Nr)�partialr)�_test_extension_cppcs.|dkr|����|d��St��j��S)Nrr)�	test_callrrrr)rx�rQrP�recurserrrT}sz@TestGreenlet.test_get_stack_with_nested_c_calls.<locals>.recurser/rxrai�)�	functoolsrP�rQr#rr�r2r0r�r�rG)r3�grr�r^rrSr�"test_get_stack_with_nested_c_callsys
z/TestGreenlet.test_get_stack_with_nested_c_callscsdt����fdd�}�fdd��t|�}|��}tdd��}|��|�|jjd�|�|j�dS)Ncs�t�d��dSr)rr�rrGrrrI�r�z6TestGreenlet.test_frames_always_exposed.<locals>.outercs��|�dSr)r)r�rJrrrH�r�z6TestGreenlet.test_frames_always_exposed.<locals>.innercSr�rrrrrrr��r�z9TestGreenlet.test_frames_always_exposed.<locals>.<lambda>rI)	rrr#rr0rKrLrGr�)r3rIrWr�rMrrNr�test_frames_always_exposed�sz'TestGreenlet.test_frames_always_exposedN)F)4r
rrr4r7r@rBrFrHrOrVrfrjrlrpry�unittest�skipIfrrr�r�r�r�r�r�r�r�r�r�r�r�r�r	r�r�r�r�r�rrrr&r-r7r=rArErFrOrXrYrrrrr'2sp
�
,
	9

/7�
Cr'c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestGreenletSetParentErrorscs�i�t���t������fdd�}dd�}tj|d�}|����d�t|�}|��|�t��
}�d|_	Wd�n1sBwY��
�|�d�|�t
|j�d�dS)	Ncr�)NcSr�rrrrrrr��r�zQTestGreenletSetParentErrors.test_threaded_reparent.<locals>.run.<locals>.<lambda>r$rar�rr�rrr9�r�z?TestGreenletSetParentErrors.test_threaded_reparent.<locals>.runcSr�rr�rrrr�blank�r�zATestGreenletSetParentErrors.test_threaded_reparent.<locals>.blankrYrar$z&parent cannot be on a different thread)r[r�r\rbr{r#rr:r�rrzrcr0r=r>)r3r9r]r�r$rrr�r�test_threaded_reparent�s 
�
z2TestGreenletSetParentErrors.test_threaded_reparentcs�g��fdd�}tj|d�}|��|�d�|j|jdd�G�fdd�dt�}|d	d
��}|�tj	��}|�
�Wd�n1sEwY|�t|j
�d��dd�=dS)Ncs"tdd��}��|�|��dS)NcSr�rrrrrrr��r�zYTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.worker.<locals>.<lambda>)r#rrrS��anotherrrr��s
zGTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.workerrYrar)�initial_main_greenletscr)zKTestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convolutedc�|dkr	�d|_t�||�S�Nr9r�rr#r�r�r_rrr���
z\TestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.convoluted.__getattribute__Nr�rr_rrr��rr�cSr�rrrrrrr��r�zITestGreenletSetParentErrors.test_unexpected_reparenting.<locals>.<lambda>r�)r[r\rbrcr��main_greenlets_before_testr#r:rr�rr0r=r>)r3r�r�r�r$rrr_r�test_unexpected_reparenting�s

��z7TestGreenletSetParentErrors.test_unexpected_reparentingc	sg�t���t������fdd�}G�fdd�dt�}tj|d�}|����d�zL|dd��}|�tj��}|�	�Wd�n1sGwY|�
d	t|j��|�
d
t|j��|�
dt|j��W��
�|�d��dd�=dS��
�|�d��dd�=w)Ncs4tdd��}��|�|�������d�dS)NcSr�rrrrrrr��r�zhTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.worker.<locals>.<lambda>ra)r#rrrzr{rS�r`�keep_main_alive�switched_to_greenletrrr��s

zVTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.workercr)zZTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convolutedcrbrcrdr�r_rrr��rezkTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.convoluted.__getattribute__Nr�rr_rrr��rr�rYracSr�rrrrrrr��r�zXTestGreenletSetParentErrors.test_unexpected_reparenting_thread_running.<locals>.<lambda>z#Cannot switch to a different thread�Expected�Current)r[r�r#r\rbr{r:rr�rr<r=r>rzrc)r3r�r�r�r$rrrhr�*test_unexpected_reparenting_thread_running�s,

�
�
zFTestGreenletSetParentErrors.test_unexpected_reparenting_thread_runningcCsbtdd��}|�|jt���|�t��
}|`Wd�n1s!wY|�t|j	�d�dS)NcSr�rrrrrrr�
r�zGTestGreenletSetParentErrors.test_cannot_delete_parent.<locals>.<lambda>�can't delete attribute)
r#rDrrrr:r;r0r=r>)r3r�rrrr�test_cannot_delete_parents�z5TestGreenletSetParentErrors.test_cannot_delete_parentcCsH|�t��}t��`Wd�n1swY|�t|j�d�dS)Nrn�r:r;rrrr0r=r>�r3rrrr�!test_cannot_delete_parent_of_mains
�z=TestGreenletSetParentErrors.test_cannot_delete_parent_of_maincCs|�t��j�dSr)rGrrrr6rrr�!test_main_greenlet_parent_is_nonesz=TestGreenletSetParentErrors.test_main_greenlet_parent_is_nonecsTdd�}�fdd�}t|�}��|�||�|����|�||�|��dS)NcSr�rr�rrrr�bgszCTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.bgc	sbdd�dfD](}��t��}||_Wd�n1swY��t|j�dt|�j�qdS)Nr�42z4GreenletChecker: Expected any type of greenlet, not )r:r�rr0r=r>�typer
)�glet�prr6rr�check#s���zFTestGreenletSetParentErrors.test_set_parent_wrong_types.<locals>.check)r#r�rr�)r3rtryr$rr6r�test_set_parent_wrong_typess


z7TestGreenletSetParentErrors.test_set_parent_wrong_typescCsRtdd��}|�t��}||_Wd�n1swY|�t|j�d�dS)NcSr�rrrrrrr�;r�z@TestGreenletSetParentErrors.test_trivial_cycle.<locals>.<lambda>�cyclic parent chain)r#r:r�rr0r=r>)r3rwrrrr�test_trivial_cycle:s
�z.TestGreenletSetParentErrors.test_trivial_cyclecCsN|�t��}t��t��_Wd�n1swY|�t|j�d�dS)Nz(cannot set the parent of a main greenletrprqrrr�test_trivial_cycle_main@s�z3TestGreenletSetParentErrors.test_trivial_cycle_maincCsvtdd��}tdd��}tdd��}||_||_|�t��}||_Wd�n1s+wY|�t|j�d�dS)NcSr�rrrrrrr�Gr�z?TestGreenletSetParentErrors.test_deeper_cycle.<locals>.<lambda>cSr�rrrrrrr�Hr�cSr�rrrrrrr�Ir�r{)r#rr:r�r0r=r>)r3r%rh�g3rrrr�test_deeper_cycleFs�z-TestGreenletSetParentErrors.test_deeper_cycleN)
r
rrr^rgrmrorrrsrzr|r}rrrrrr\�s)$r\c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestReprcCs|�|�|�||f�dSr)r��endswith)r3�got�suffixrrr�assertEndsWithTszTestRepr.assertEndsWithcCstt���}|�|d�dS)N� current active started main>)�reprrrr��r3�rrrr�test_main_while_runningWsz TestRepr.test_main_while_runningcs4t����fdd�}t|�}|��}|�|d�dS)Ncst��Sr)r�rrJrrr9]r�z-TestRepr.test_main_in_background.<locals>.run� suspended active started main>)rrr#rr�)r3r9r$r�rrJr�test_main_in_background[s
z TestRepr.test_main_in_backgroundcCstt��}|�|d�dS)Nz	 pending>)r�r#r�r�rrr�test_initialds
zTestRepr.test_initialcs�t���G�fdd�dtj�}|�}|��|�d�|�|jd�|�|jd�t	d�D]}t
�d�q-t	d�D]}|�|j
j�t|j
�}|�|d�q9dS)	Ncs$eZdZdZZdZ�fdd�ZdS)z/TestRepr.test_main_from_other_thread.<locals>.TNcs$t��|_t��|_t|j�|_dSr)r��
original_mainrr�	main_gletr3r6rJrrr9nrIz3TestRepr.test_main_from_other_thread.<locals>.T.run)r
rrr�r3r�r9rrJrr�Tksr�rar�r�r(g����MbP?z (thread exited) dead>)rrr[r\rbrcr�r�r3r2r�r�r�r�rMr�)r3r�r�rr�rrJr�test_main_from_other_threadhs

�z$TestRepr.test_main_from_other_threadcCsXtdd��}|��|�t|�d�|�dt|��|�dt|��|�dt|��dS)NcSr�rrrrrrr��r�z$TestRepr.test_dead.<locals>.<lambda>z dead>�	suspended�started�active)r#rr�r��assertNotInrErrr�	test_dead�szTestRepr.test_deadcCsXtdd��}tdd��}t��}|||fD]}|�d|ft�|�d|ft�qdS)NcSr�rrrrrrr��r�z>TestRepr.test_formatting_produces_native_str.<locals>.<lambda>cSr�rrrrrrr��r�z%sz%r)r#rr�assertIsInstancer=)r3�g_dead�
g_not_started�g_curr$rrr�#test_formatting_produces_native_str�s���z,TestRepr.test_formatting_produces_native_strN)
r
rrr�r�r�r�r�r�r�rrrrr�Rs	#r�c@r�)�TestMainGreenletcCs4dtt���vs
J�tt���}dt|�vsJ�|S)Nr�)r�rrrv)r3r�rrr�_check_current_is_main�sz'TestMainGreenlet._check_current_is_maincCs$|��}td|fi�}|�|�dS)N�subclass)r�rvrC)r3�	main_typer�rrr�)test_main_greenlet_type_can_be_subclassed�sz:TestMainGreenlet.test_main_greenlet_type_can_be_subclassedcCs|��|�t��t�dSr)r�r�rrr#r6rrr�test_main_greenlet_is_greenlet�sz/TestMainGreenlet.test_main_greenlet_is_greenletN)r
rrr�r�r�rrrrr��sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�TestBrokenGreenletscCsTdd�}tj�|�}d|_|�td��
|��Wd�dS1s#wYdS)NcSstd��)NzNever get here)�AssertionErrorrrrrr��r�z<TestBrokenGreenlets.test_failed_to_initialstub.<locals>.funcTz;Failed to switch stacks into a greenlet for the first time.)r�	_greenlet�UnswitchableGreenlet�force_switch_error�assertRaisesRegex�SystemErrorrr�rrr�test_failed_to_initialstub�s�
"�z.TestBrokenGreenlets.test_failed_to_initialstubcs�g��fdd�}tj�|�}|��|��dg�|��|��ddg�d|_|�td��|��Wd�n1s=wYd|_|��|��gd��dS)	Ncs>��d�t��j����d�t��j����d�dS)Nrr-r(r)r��runsrrr��s


zDTestBrokenGreenlets.test_failed_to_switch_into_running.<locals>.funcrr-Tz0Failed to switch stacks into a running greenlet.F)rr-r()rr�r�rr0r�r�r�r�rr�r�"test_failed_to_switch_into_running�s �
�z6TestBrokenGreenlets.test_failed_to_switch_into_runningcCs.|�d�}|�d|j�|�|j|���dS)Nzfail_slp_switch.pyzfail_slp_switch is running)�assertScriptRaisesr<�output�
returncode�,get_expected_returncodes_for_aborted_process�r3�exrrr�&test_failed_to_slp_switch_into_running�s
z:TestBrokenGreenlets.test_failed_to_slp_switch_into_runningcCsV|�d�}|�d|�|�d|�|�d|�|�d|�|�d|�|�d|�dS)Nzfail_switch_two_greenlets.pyz	In g1_run�TRACEzLEAVE TRACEzFalling off end of mainzFalling off end of g1_runzFalling off end of g2��
run_scriptr<�r3r�rrr�#test_reentrant_switch_two_greenlets�s
z7TestBrokenGreenlets.test_reentrant_switch_two_greenletscCs.|jddd�}|�d|j�|�d|j�dS)Nzfail_switch_three_greenlets.py)r)�	exitcodesr�zpositional arguments)r�r<r�r�rrr�%test_reentrant_switch_three_greenlets�sz9TestBrokenGreenlets.test_reentrant_switch_three_greenletscC�|�d�}|�d|�dS)Nzfail_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�rrr�&test_reentrant_switch_three_greenlets2s

�z:TestBrokenGreenlets.test_reentrant_switch_three_greenlets2cCr�)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�rrr�4test_reentrant_switch_GreenletAlreadyStartedInPythons

�zHTestBrokenGreenlets.test_reentrant_switch_GreenletAlreadyStartedInPythoncCr�)Nzfail_clearing_run_switches.pyz�RESULTS [('G.__getattribute__', 'run'), ('RunCallable', '__del__'), ('main: g.switch()', 'from RunCallable'), ('run_func', 'enter')]r�r�rrr�*test_reentrant_switch_run_callable_has_del!s

�z>TestBrokenGreenlets.test_reentrant_switch_run_callable_has_delN)r
rrr�r�r�r�r�r�r�r�rrrrr��s
	r��__main__)rmrr�r[rZ�abcrrrr#rVrrr�	leakcheckr	rrrrr&r'r\r�r�r�r
r�rrrr�<module>s>
		y.Um�