Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_frame.cpython-311.pyc
�

�KeC-��0�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
Gd�dej��ZGd�dej��ZGd	�d
ej��ZGd�dej��Zed
krej��dSdS)�N)�support)�threading_helper)�assert_python_okc�j�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Ze
jd���Zd
S)�	ClearTestz"
    Tests for frame.clear().
    �c��ddzdS�N�r�)�self�x�kwargss   �9/usr/local/apps/python3/lib/python3.11/test/test_frame.py�innerzClearTest.inners��	�!�����c�V�	|jdi|��n#t$r}|}Yd}~nd}~wwxYw|S)Nr)r�ZeroDivisionError)r
r�e�excs    r�outerzClearTest.outersU��	��D�J� � �� � � � �� �	�	�	��C�C�C�C�C�C�����	�����
s�
�
&�!�&c�R�|�$|j���|j}|�"dSdS)z2
        Clear all frames in a traceback.
        N)�tb_frame�clear�tb_next)r
�tbs  r�clear_traceback_framesz ClearTest.clear_traceback_framess3���n��K��������B��n�n�n�n�nrc��Gd�d��}|��}tj|��}|�|���}~tj��|�d|����|�|j��tj��|�d|����dS)Nc��eZdZdS)�&ClearTest.test_clear_locals.<locals>.CN��__name__�
__module__�__qualname__rrr�Cr '��������Drr%��c)	�weakref�refrr�
gc_collect�assertIsNotr�
__traceback__�assertIs�r
r%r(�wrrs     r�test_clear_localszClearTest.test_clear_locals&s���	�	�	�	�	�	�	�	�
�A�C�C��
�[��^�^���j�j�1�j�o�o��
����������r�r�t�t�$�$�$��#�#�C�$5�6�6�6�������
�
�d�B�B�D�D�!�!�!�!�!rc�z�Gd�d��}|��}|�|���}~|jj}|���|�|jd��|�|jd��|�|jd��|�|jd��dS)Nc��eZdZdS)�7ClearTest.test_clear_does_not_clear_specials.<locals>.CNr!rrrr%r46r&rr%r')	rr-rrr,�f_code�f_locals�
f_builtins�	f_globals)r
r%r(r�fs     r�"test_clear_does_not_clear_specialsz,ClearTest.test_clear_does_not_clear_specials5s���	�	�	�	�	�	�	�	�
�A�C�C���j�j�1�j�o�o��
���&��	���	�	�	������4�(�(�(������T�*�*�*������t�,�,�,������d�+�+�+�+�+rc�����d���fd�}|��}t|�������|j��������dS)NFc3�P�K�	dV�����d�dS#d�wxYw)NT)r)�endlyr
s��r�gz)ClearTest.test_clear_generator.<locals>.gDs8�����
������
�
��������������s�!�%)�next�assertFalse�gi_framer�
assertTrue)r
r>�genr=s`  @r�test_clear_generatorzClearTest.test_clear_generatorBs������	�	�	�	�	�	��a�c�c���S�	�	�	�����������������������rc�~�	ddzn##t$r}|jj}Yd}~nd}~wwxYw|�t��5|���ddd��n#1swxYwY|�t��5|j���ddd��dS#1swxYwYdSr
�rr-r�assertRaises�RuntimeErrorr�f_back)r
rr9s   r�test_clear_executingzClearTest.test_clear_executingRsE��	)�
�a�C�C�C�� �	)�	)�	)���(�A�A�A�A�A�A�����	)����
�
�
�|�
,�
,�	�	�
�G�G�I�I�I�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
�
�|�
,�
,�	�	�
�H�N�N����	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s4��
(�#�(�A&�&A*�-A*�B2�2B6�9B6c�����d���fd�}|��}t|��}�����|��������dS)NFc3��K�	ddzn�#t$r�}|jj}��t��5|���ddd��n#1swxYwY��t��5|j���ddd��n#1swxYwY|V�Yd}~nd}~wwxYwd�dS#d�wxYw)NrrTrF)rr9r=r
s  ��rr>z3ClearTest.test_clear_executing_generator.<locals>.g`s\�����

��!�����$�
�
�
��O�,���&�&�|�4�4����G�G�I�I�I��������������������&�&�|�4�4�%�%��H�N�N�$�$�$�%�%�%�%�%�%�%�%�%�%�%����%�%�%�%��������������

��������������sr��C�
C�&B;�A�B;�A 	� B;�#A 	�$B;�B'�B;�'B+	�+B;�.B+	�/B;�6C�;C�C�C)r?r@rrB)r
r>rCr9r=s`   @r�test_clear_executing_generatorz(ClearTest.test_clear_executing_generator]sx������	�	�	�	�	�	��a�c�c����I�I���������	���	�	�	���������rc�����fd���fd�}gd�}g�|d��|��|��g�|d��|��|��dS)Nc�~��tjd��}��|j|jjz
��dS)Nr)�sys�	_getframe�append�f_linenor5�co_firstlineno)r9�liness �r�record_linez7ClearTest.test_lineno_with_tracing.<locals>.record_lineus6����
�a� � �A��L�L���A�H�$;�;�<�<�<�<�<rc�z�����|rdtjd��_������dS)NTr)rPrQ�f_trace)�tracerVs �r�testz0ClearTest.test_lineno_with_tracing.<locals>.testysB����K�M�M�M��
0�+/��
�a� � �(��K�M�M�M��K�M�M�M�M�Mr)r�rFT)�assertEqual)r
rZ�expected_linesrUrVs   @@r�test_lineno_with_tracingz"ClearTest.test_lineno_with_tracingts�����	=�	=�	=�	=�	=�	�	�	�	�	�#��������U���������/�/�/�����T�
�
�
������/�/�/�/�/rc��tj��5Gd�d��}|��}tj|��}|�|���}~|�d|����|�|j��|�d|����ddd��dS#1swxYwYdS)Nc��eZdZdS)�)ClearTest.test_clear_refcycles.<locals>.CNr!rrrr%ra�s�������rr%r')	r�
disable_gcr)r*rr,rr-r.r/s     r�test_clear_refcycleszClearTest.test_clear_refcycles�s���
�
!�
!�		&�		&�
�
�
�
�
�
�
�
�����A���Q���B��*�*�q�*�/�/�C�����T�2�2�4�4�(�(�(��'�'��(9�:�:�:��M�M�$�����%�%�%�		&�		&�		&�		&�		&�		&�		&�		&�		&�		&�		&�		&����		&�		&�		&�		&�		&�		&s�BB:�:B>�B>N)r)r"r#r$�__doc__rrrr1r:rDrJrMr^r�cpython_onlyrcrrrrrs�������������������
"�
"�
"�,�,�,���� 	�	�	����.0�0�0�(
��&�&���&�&�&rrc�,�eZdZd�Zd�Zd�Zd�Zd�ZdS)�FrameAttrsTestc��d�}	|��nE#t$r8}|j}g}|r#|�|j��|j}|�#Yd}~nd}~wwxYw|S)Nc�*��d�d}�fd�}|��S)Nr�c� ���dz}ddzd}dS�N�rr�	r��z�trs  �rrz8FrameAttrsTest.make_frames.<locals>.outer.<locals>.inner�������E���!������rr��yrrs  @rrz)FrameAttrsTest.make_frames.<locals>.outer��3����A��A�
�
�
�
�
��5�7�7�Nr)rr-rRrr)r
rrr�framess     r�make_frameszFrameAttrsTest.make_frames�s���	�	�	�	 ��E�G�G�G�G�� �	 �	 �	 ���B��F��
 ��
�
�b�k�*�*�*��Z���
 ����������	 �����
s�
�
A�.A
�
Ac��|���\}}}|j}|�|�d��tj��|�|ddd���|j}|�|ddd���dS)Nrrrj)rrt�)rrp)rwr6�assertIsInstance�pop�types�FunctionTyper\)r
r9rr�outer_locals�inner_localss      r�test_localszFrameAttrsTest.test_locals�s����*�*�,�,���5�%��~�����l�.�.�w�7�7��9K�L�L�L�����Q�Q�'7�'7�8�8�8��~������Q�Q�'7�'7�8�8�8�8�8rc���|���\}}}|���|���|�|ji��|�|ji��dS�N)rwrr\r6�r
r9rrs    rr1z FrameAttrsTest.test_clear_locals�si���*�*�,�,���5�%�
���
�
�
�
���
�
�
�������,�,�,�������,�,�,�,�,rc��|���\}}}|j|j|���|���|�|ji��|�|ji��dSr�)rwr6rr\r�s    r�test_locals_clear_localsz'FrameAttrsTest.test_locals_clear_locals�sw���*�*�,�,���5�%�
���
���
���
�
�
�
���
�
�
�������,�,�,�������,�,�,�,�,rc��|���\}}}|�t��5|`ddd��dS#1swxYwYdSr�)rwrG�AttributeErrorrS)r
r9�_s   r�test_f_lineno_del_segfaultz)FrameAttrsTest.test_f_lineno_del_segfault�s����"�"�$�$���1�a�
�
�
�~�
.�
.�	�	��
�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�A�A�
AN)r"r#r$rwr�r1r�r�rrrrgrg�s_���������&9�9�9�-�-�-�-�-�-�����rrgc��eZdZdZd�ZdS)�ReprTestz 
    Tests for repr(frame).
    c�J�d�}|jj}	|��|�d��nE#t$r8}|j}g}|r#|�|j��|j}|�#Yd}~nd}~wwxYw|\}}}tj	tt����}	|�t|��d|	|dzfz��|�t|��d|	|dzfz��|�t|��d|	|dzfz��dS)	Nc�*��d�d}�fd�}|��S)Nrrjc� ���dz}ddzd}dSrlrros  �rrz0ReprTest.test_repr.<locals>.outer.<locals>.inner�rrrrrss  @rrz!ReprTest.test_repr.<locals>.outer�rurzshould have raisedz=^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code test_repr>$�z9^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code outer>$ryz9^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code inner>$r)
�__code__rT�failrr-rRrr�re�escape�repr�__file__�assertRegex)
r
r�offsetrrrv�f_this�f_outer�f_inner�	file_reprs
          r�	test_reprzReprTest.test_repr�sq��	�	�	���.��		,��E�G�G�G�
�I�I�*�+�+�+�+��!�	 �	 �	 ���B��F��
 ��
�
�b�k�*�*�*��Z���
 ����������	 ����$*� �����I�d�8�n�n�-�-�	�����f���Y�%�v��{�3�4�	5�	5�	5�	
����g���U�%�v��z�2�3�	4�	4�	4�	
����g���U�%�v��z�2�3�	4�	4�	4�	4�	4s�
1�
A3�.A.�.A3N)r"r#r$rdr�rrrr�r��s-�������� 4� 4� 4� 4� 4rr�c�~�eZdZd�Zejd���Zejej��d�����Z	dS)�TestIncompleteFrameAreInvisiblec�`�tjdt�d���}td|��dS)Nz�
            import gc

            gc.set_threshold(1,1,1)
            class GCHello:
                def __del__(self):
                    print("Destroyed from gc")

            def gen():
                yield

            fd = open(zy)
            l = [fd, GCHello()]
            l.append(l)
            del fd
            del l
            gen()
        z-c)�textwrap�dedentr�r)r
�codes  r�test_issue95818z/TestIncompleteFrameAreInvisible.test_issue95818�sD���� � � � � �
�
��$	��t�$�$�$�$�$rc�|��	�d�}��	fd��d�}tj��}tjdd�}tj��}t	j��}	tj��|��}t|��tj��tj	ddd��t	j
|��tj����d�	tj��t|��|�
|j�	��tj	|�|tjdd�<t	j
|��|rtj��dSdS#tj	|�|tjdd�<t	j
|��|rtj��wwxYw)Nc��dS)z^
            Don't actually do anything, just force a frame object to be created.
            Nr)�frame�event�args   rrYzGTestIncompleteFrameAreInvisible.test_sneaky_frame_object.<locals>.traces���rc�v��tj��j�tj����dS)z�
            Yo dawg, I heard you like frames, so I'm allocating a frame while
            you're allocating a frame, so you can have a frame while you have a
            frame!
            N)rPrQrI�gc�	callbacks�remove)�phase�info�callback�sneaky_frame_objects  ��rr�zJTestIncompleteFrameAreInvisible.test_sneaky_frame_object.<locals>.callbacks0���#&�-�/�/�"8���L����)�)�)�)�)rc3�K�	dV��r�rrrrr9zCTestIncompleteFrameAreInvisible.test_sneaky_frame_object.<locals>.fs����
�����
rrr)r��
get_thresholdr��	isenabledrP�gettrace�disabler?�collect�
set_threshold�settracerR�enabler.rA)
r
rYr9�
old_threshold�
old_callbacks�old_enabled�	old_tracer>r�r�s
        @@r�test_sneaky_frame_objectz8TestIncompleteFrameAreInvisible.test_sneaky_frame_objects�����	�	�	�
		*�		*�		*�		*�		*�		*�	�	�	��(�*�*�
���Q�Q�Q��
��l�n�n���L�N�N�	�"	��J�L�L�L�����A���G�G�G�
�J�L�L�L���Q��1�%�%�%�
�L������L����)�)�)�"&���I�K�K�K���G�G�G�
�M�M�!�*�&9�:�:�:���m�,�,�+�B�L����O��L��#�#�#��
��	������
�
��
��m�,�,�+�B�L����O��L��#�#�#��
��	�����
���s�CE0�0AF;c�R���G�fd�d���G�fd�dtj��}d�|��}|���|���|������0|��j|jj���j	���.dSdS)Nc���eZdZ�fd�ZdS)�TTestIncompleteFrameAreInvisible.test_sneaky_frame_object_teardown.<locals>.SneakyDelc�.��tj���dS)a@
                Stash a reference to the entire stack for walking later.

                It may look crazy, but you'd be surprised how common this is
                when using a test runner (like pytest). The typical recipe is:
                ResourceWarning + -Werror + a custom sys.unraisablehook.
                N)rPrQ)r
r�s �r�__del__z\TestIncompleteFrameAreInvisible.test_sneaky_frame_object_teardown.<locals>.SneakyDel.__del__Os���'*�m�o�o�#�#�#rN)r"r#r$r�)r�s�r�	SneakyDelr�Ns.�������	
6�	
6�	
6�	
6�	
6�	
6�	
6rr�c���eZdZdZ�fd�ZdS)�WTestIncompleteFrameAreInvisible.test_sneaky_frame_object_teardown.<locals>.SneakyThreadz�
            A separate thread isn't needed to make this code crash, but it does
            make crashes more consistent, since it means sneaky_frame_object is
            backed by freed memory after the thread completes!
            c������}dS)z.Run SneakyDel.__del__ as this frame is popped.Nr)r
r*r�s  �r�runz[TestIncompleteFrameAreInvisible.test_sneaky_frame_object_teardown.<locals>.SneakyThread.runas����i�k�k���rN)r"r#r$rdr�)r�s�r�SneakyThreadr�Zs8�������
�
�
"�
"�
"�
"�
"�
"�
"rr�)
�	threading�Thread�start�join�assertIsNotNoner,r5r�r�rI)r
r�rqr�r�s   @@r�!test_sneaky_frame_object_teardownzATestIncompleteFrameAreInvisible.test_sneaky_frame_object_teardownJs�����
	6�
	6�
	6�
	6�
	6�
	6�
	6�
	6�
	6�
	6�		"�		"�		"�		"�		"�		"�		"�9�+�		"�		"�		"�#���L�N�N��	���	�	�	�	������	
���0�1�1�1�!�-����#�*�L�,<�,E�
�
�
�#6�"<��	"�-�-�-�-�-rN)
r"r#r$r�rrer�r�requires_working_threadingr�rrrr�r��sy������%�%�%�,
��<�<���<�|
��0��0�2�2�%=�%=�3�2���%=�%=�%=rr��__main__)r�r�rPr�r�r|�unittestr)rZr�test.supportr�test.support.script_helperr�TestCaserrgr�r�r"�mainrrr�<module>r�st��	�	�	�	�	�	�	�	�
�
�
�
���������������������������)�)�)�)�)�)�7�7�7�7�7�7�E&�E&�E&�E&�E&��!�E&�E&�E&�P2�2�2�2�2�X�&�2�2�2�j%4�%4�%4�%4�%4�x� �%4�%4�%4�N~=�~=�~=�~=�~=�h�&7�~=�~=�~=�@�z����H�M�O�O�O�O�O��r