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

�Ke�4��p�ddlZddlZddlZddlZddlmZGd�dej��ZGd�d��ZGd�de��Z	Gd	�d
ej��Z
Gd�de
��ZGd
�de
��Zd�Z
d�Ze
e��Zdd�Zd�ZGd�dej��Zedkrej��dSdS)�N)�supportc�&�eZdZd�Zd�Zd�Zd�ZdS)�TestGetProfilec�.�tjd��dS�N��sys�
setprofile��selfs �B/usr/local/apps/python3/lib/python3.11/test/test_sys_setprofile.py�setUpzTestGetProfile.setUp	�����t������c�.�tjd��dSrrrs r
�tearDownzTestGetProfile.tearDownrrc�R�|�tj����dSr)�assertIsNoner	�
getprofilers r
�
test_emptyzTestGetProfile.test_emptys$�����#�.�*�*�+�+�+�+�+rc��d�}tj|��|�tj��|��dS)Nc��dSr���argss r
�fnz&TestGetProfile.test_setget.<locals>.fn����Dr)r	r
�assertIsr)rrs  r
�test_setgetzTestGetProfile.test_setgetsE��	�	�	�	��r�����
�
�c�n�&�&��+�+�+�+�+rN)�__name__�
__module__�__qualname__rrrrrrr
rrsP������������,�,�,�,�,�,�,�,rrc�(�eZdZd�Zd�Zdd�Zd�ZdS)�HookWatcherc�"�g|_g|_dSr)�frames�eventsrs r
�__init__zHookWatcher.__init__s���������rc�Z�|dks|dks|dkr|�||��dSdS)N�call�return�	exception��	add_event�r�frame�event�args    r
�callbackzHookWatcher.callbacksC���V�O�O��� � ���#�#��N�N�5�%�(�(�(�(�(�$�#rNc�:�|�tjd��}	|j�|��}n>#t$r1t|j��}|j�|��YnwxYw|j�||t|��f��dS)zAdd an event to the log.N�)	r	�	_getframer&�index�
ValueError�len�appendr'�ident)rr1r0�framenos    r
r.zHookWatcher.add_event$s����=��M�!�$�$�E�	&��k�'�'��.�.�G�G���	&�	&�	&��$�+�&�&�G��K���u�%�%�%�%�%�	&����	
����G�U�E�%�L�L�9�:�:�:�:�:s�3�8A.�-A.c���t|jj��tt��g�d|_�fd�|jD��S)zRemove calls to add_event().Nc�(��g|]}|d�v�|��S)�r)�.0�item�
disalloweds  �r
�
<listcomp>z*HookWatcher.get_events.<locals>.<listcomp>6s'���J�J�J���Q��z�0I�0I��0I�0I�0Ir)r;r.�__func__r&r')rrBs @r
�
get_eventszHookWatcher.get_events1sC����D�N�3�4�4�e�E�l�l�C�
����J�J�J�J���J�J�J�Jrr)r r!r"r(r3r.rErrr
r$r$sZ���������)�)�)�;�;�;�;�K�K�K�K�Krr$c�D�eZdZd�Zd�Zd�Zd�Zd�Zd�Zeeeeeed�Z	dS)	�ProfileSimulatorc�V�||_g|_t�|��dSr)�testcase�stackr$r()rrIs  r
r(zProfileSimulator.__init__:s*�� ��
���
����T�"�"�"�"�"rc�4�|j|||��dSr)�dispatchr/s    r
r3zProfileSimulator.callback?s!����
�e��T�5�)�)�)�)�)rc�f�|�d|��|j�|��dS)Nr*)r.rJr:�rr0s  r
�
trace_callzProfileSimulator.trace_callCs2�����v�u�%�%�%��
���%� � � � � rc�d�|�d|��|j���dS)Nr+)r.rJ�poprNs  r
�trace_returnzProfileSimulator.trace_returnGs.�����x��'�'�'��
�������rc�:�|j�d��dS)Nz2the profiler should never receive exception events)rI�failrNs  r
�trace_exceptionz ProfileSimulator.trace_exceptionKs.���
���@�	B�	B�	B�	B�	Brc��dSrrrNs  r
�
trace_passzProfileSimulator.trace_passOs���r)r*r,r+�c_call�c_return�c_exceptionN)
r r!r"r(r3rOrRrUrWrLrrr
rGrG9s�������#�#�#�
*�*�*�!�!�!����B�B�B�
�
�
��$����!�

�
�H�H�HrrGc��eZdZd�ZdS)�TestCaseBasec���t||�����}||krA|�dtj|���dtj|������dSdS)NzExpected events:
z
Received events:
)�capture_events�new_watcherrT�pprint�pformat)r�callable�expectedr's    r
�check_eventszTestCaseBase.check_events]s����$�*:�*:�*<�*<�=�=���X����I�I�I����1�1�1�1�6�>�&�3I�3I�3I�K�
L�
L�
L�
L�
L��rN)r r!r"rdrrr
r\r\\s(������L�L�L�L�Lrr\c�b�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�ZdS)�ProfileHookTestCasec��t��Sr)r$rs r
r_zProfileHookTestCase.new_watcheres���}�}�rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��dSrr��ps r
�fz*ProfileHookTestCase.test_simple.<locals>.firrr5r*r+�r;rd�rrl�f_idents   r
�test_simplezProfileHookTestCase.test_simpleh�X��	�	�	���(�(�����!�q�&�'�2� �(�G�4� �	!�	!�	!�	!�	!rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��ddzdS�Nr5rrrjs r
rlz-ProfileHookTestCase.test_exception.<locals>.fq���
�a�C�C�C�Crr5r*r+rmrns   r
�test_exceptionz"ProfileHookTestCase.test_exceptionp�X��	�	�	���(�(�����!�q�&�'�2� �(�G�4� �	!�	!�	!�	!�	!rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc� �ddzdS#YdSxYwrtrrjs r
rlz4ProfileHookTestCase.test_caught_exception.<locals>.fy����1�������D�D�D������
r5r*r+rmrns   r
�test_caught_exceptionz)ProfileHookTestCase.test_caught_exceptionx�Z��	�	�	���(�(�����!�q�&�'�2� �(�G�4� �	!�	!�	!�	!�	!rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc� �ddzdS#YdSxYwrtrrjs r
rlz;ProfileHookTestCase.test_caught_nested_exception.<locals>.f�rzr{r5r*r+rmrns   r
�test_caught_nested_exceptionz0ProfileHookTestCase.test_caught_nested_exception�r}rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��ddzdSrtrrjs r
rlz4ProfileHookTestCase.test_nested_exception.<locals>.f�rurr5r*r+rmrns   r
�test_nested_exceptionz)ProfileHookTestCase.test_nested_exception�sZ��	�	�	���(�(�����!�q�&�'�2� !�(�G�4�	 �	!�	!�	!�	!�	!rc���d���fd�}t���}t|��}|�|dd|fdd|fdd|fdd|fdd|fdd|fg��dS)Nc��ddzdSrtrrjs r
rlz>ProfileHookTestCase.test_exception_in_except_clause.<locals>.f�rurc�X��	�|��dS#�|��YdS#YYdSxYwxYwrr�rkrls �r
�gz>ProfileHookTestCase.test_exception_in_except_clause.<locals>.g�sD���
���!�������
��Q�q�T�T�T�T�T�T������������s��)� �&�)�)r5r*r?r+�rm�rr�ro�g_identrls    @r
�test_exception_in_except_clausez3ProfileHookTestCase.test_exception_in_except_clause�s����	�	�	�	�	�	�	�	���(�(����(�(�����!�q�&�'�2� �&�'�2� �(�G�4� �&�'�2� �(�G�4� �(�G�4� �	!�	!�	!�	!�	!rc
���d���fd�}t���}t|��}|�|dd|fdd|fdd|fdd|fdd|fg��dS)Nc��ddzdSrtrrjs r
rlz9ProfileHookTestCase.test_exception_propagation.<locals>.f�rurc�|���|��|�d��dS#|�d��wxYw)N�falling throughr-r�s �r
r�z9ProfileHookTestCase.test_exception_propagation.<locals>.g�sB�����1�����[�[�!2�3�3�3�3�3��Q�[�[�!2�3�3�3�3���s�$�;r5r*r?r+r�rmr�s    @r
�test_exception_propagationz.ProfileHookTestCase.test_exception_propagation�s����	�	�	�	4�	4�	4�	4�	4���(�(����(�(�����!�q�&�'�2� �&�'�2� �(�G�4� �"3�W�=� �(�G�4�	 �	!�	!�	!�	!�	!rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc�*�ddzdS#ddzYdSxYwrtrrjs r
rlz/ProfileHookTestCase.test_raise_twice.<locals>.f�s$���1�������A�a�C�C�C�C�C���s��r5r*r+rmrns   r
�test_raise_twicez$ProfileHookTestCase.test_raise_twice�sZ��	�	�	���(�(�����!�q�&�'�2� �(�G�4� �	!�	!�	!�	!�	!rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��ddzdS#�xYwrtrrjs r
rlz1ProfileHookTestCase.test_raise_reraise.<locals>.f�s���1�������E���s��r5r*r+rmrns   r
�test_raise_reraisez&ProfileHookTestCase.test_raise_reraise�sZ��	�	�	���(�(�����!�q�&�'�2� �(�G�4� �	!�	!�	!�	!�	!rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��t���r)�	Exceptionrjs r
rlz)ProfileHookTestCase.test_raise.<locals>.f�s���+�+�rr5r*r+rmrns   r
�
test_raisezProfileHookTestCase.test_raise�sX��	�	�	���(�(�����!�q�&�'�2� �(�G�4� �	!�	!�	!�	!�	!rc�N���	�
�d���fd���fd��	�	fd��
�
fd�}t���}t���}t�	��}t�
��}t|��}|�|dd|fdd|fd	d|fd
d|fdd|fdd|fd
d|fd	d|fdd|fdd|fg
��dS)
Nc��ddzdSrtrrrr
rlz5ProfileHookTestCase.test_distant_exception.<locals>.f�rurc������dSrr�rls�r
r�z5ProfileHookTestCase.test_distant_exception.<locals>.g�����
�A�C�C�C�C�Crc������dSrr�r�s�r
�hz5ProfileHookTestCase.test_distant_exception.<locals>.h�r�rc������dSrr�r�s�r
�iz5ProfileHookTestCase.test_distant_exception.<locals>.i�r�rc������dSrr�rkr�s �r
�jz5ProfileHookTestCase.test_distant_exception.<locals>.j�r�rr5r*r?r���r+rm�rr�ror��h_ident�i_ident�j_identrlr�r�r�s       @@@@r
�test_distant_exceptionz*ProfileHookTestCase.test_distant_exception��<������	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	���(�(����(�(����(�(����(�(����(�(�����!�q�&�'�2� �&�'�2� �&�'�2� �&�'�2� �&�'�2� �(�G�4� �(�G�4� �(�G�4� �(�G�4� �(�G�4�
 �
	!�
	!�
	!�
	!�
	!rc
���d���fd�}t���}t|��}|�|dd|fdd|fdd|fdd|fdd|fdd|fdd|fdd|fg��dS)Nc3�6K�td��D]}|V��dS�Nr?��range�r�s r
rlz-ProfileHookTestCase.test_generator.<locals>.f��0�����1�X�X�
�
�������
�
rc�"�����D]}�dSrr�rkr�rls  �r
r�z-ProfileHookTestCase.test_generator.<locals>.g��%����Q�S�S�
�
���
�
rr5r*r?r+rmr�s    @r
�test_generatorz"ProfileHookTestCase.test_generator�s����	�	�	�	�	�	�	�	���(�(����(�(�����!�q�&�'�2� �&�'�2� �(�G�4� �&�'�2� �(�G�4� !�&�'�2� �(�G�4� �(�G�4� �	!�	!�	!�	!�	!rc
���d���fd�}t���}t|��}|�|dd|fdd|fdd|fdd|fdd|fdd|fdd|fdd|fg��dS)Nc3�6K�td��D]}|V��dSr�r�r�s r
rlz2ProfileHookTestCase.test_stop_iteration.<locals>.fr�rc�"�����D]}�dSrrr�s  �r
r�z2ProfileHookTestCase.test_stop_iteration.<locals>.gr�rr5r*r?r+rmr�s    @r
�test_stop_iterationz'ProfileHookTestCase.test_stop_iterations����	�	�	�	�	�	�	�	���(�(����(�(�����!�q�&�'�2� �&�'�2� �(�G�4� �&�'�2� �(�G�4� �&�'�2� �(�G�4� �(�G�4�
 �
	!�
	!�
	!�
	!�
	!rN)r r!r"r_rprvr|r�r�r�r�r�r�r�r�r�r�rrr
rfrfds����������!�!�!�!�!�!�!�!�!�!�!�!�	!�	!�	!�!�!�!�&
!�
!�
!�!�!�!�!�!�!�!�!�!�!�!�!�8!�!�!�,!�!�!�!�!rrfc�J�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�ProfileSimulatorTestCasec� �t|��Sr)rGrs r
r_z$ProfileSimulatorTestCase.new_watchers����%�%�%rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��dSrrrjs r
rlz/ProfileSimulatorTestCase.test_simple.<locals>.frrr5r*r+rmrns   r
rpz$ProfileSimulatorTestCase.test_simplerqrc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc��ddzdSrtrrjs r
rlz8ProfileSimulatorTestCase.test_basic_exception.<locals>.f&rurr5r*r+rmrns   r
�test_basic_exceptionz-ProfileSimulatorTestCase.test_basic_exception%rwrc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc� �ddzdS#YdSxYwrtrrjs r
rlz9ProfileSimulatorTestCase.test_caught_exception.<locals>.f.rzr{r5r*r+rmrns   r
r|z.ProfileSimulatorTestCase.test_caught_exception-r}rc�N���	�
�d���fd���fd��	�	fd��
�
fd�}t���}t���}t�	��}t�
��}t|��}|�|dd|fdd|fd	d|fd
d|fdd|fdd|fd
d|fd	d|fdd|fdd|fg
��dS)
Nc��ddzdSrtrrrr
rlz:ProfileSimulatorTestCase.test_distant_exception.<locals>.f7rurc������dSrrr�s�r
r�z:ProfileSimulatorTestCase.test_distant_exception.<locals>.g9r�rc������dSrrr�s�r
r�z:ProfileSimulatorTestCase.test_distant_exception.<locals>.h;r�rc������dSrrr�s�r
r�z:ProfileSimulatorTestCase.test_distant_exception.<locals>.i=r�rc������dSrrr�s �r
r�z:ProfileSimulatorTestCase.test_distant_exception.<locals>.j?r�rr5r*r?r�r�r�r+rmr�s       @@@@r
r�z/ProfileSimulatorTestCase.test_distant_exception6r�rc�p��i��fd�}t|��}|�|dd|fdd|fg��dS)Nc�.��tjidfi���dS�N�*��dict�get�rk�kwargss �r
rlz7ProfileSimulatorTestCase.test_unbound_method.<locals>.fUs#����H�R��&�&�v�&�&�&�&�&rr5r*r+rm�rrlror�s   @r
�test_unbound_methodz,ProfileSimulatorTestCase.test_unbound_methodSsh�����	'�	'�	'�	'�	'���(�(�����!�q�&�'�2� �(�G�4�6�	7�	7�	7�	7�	7rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc�8�t���dSrr�rjs r
rlz?ProfileSimulatorTestCase.test_unbound_method_no_args.<locals>.f]s���H�H�J�J�J�J�Jrr5r*r+rmrns   r
�test_unbound_method_no_argsz4ProfileSimulatorTestCase.test_unbound_method_no_args\sX��	�	�	���(�(�����!�q�&�'�2� �(�G�4�6�	7�	7�	7�	7�	7rc�f�d�}t|��}|�|dd|fdd|fg��dS)Nc�F�t�td��dSr��r�r��printrjs r
rlzDProfileSimulatorTestCase.test_unbound_method_invalid_args.<locals>.fes���H�H�U�B�����rr5r*r+rmrns   r
� test_unbound_method_invalid_argsz9ProfileSimulatorTestCase.test_unbound_method_invalid_argsdsX��	 �	 �	 ���(�(�����!�q�&�'�2� �(�G�4�6�	7�	7�	7�	7�	7rc�p��i��fd�}t|��}|�|dd|fdd|fg��dS)Nc�*��tjdi���dS)Nrr�r�s �r
rlzGProfileSimulatorTestCase.test_unbound_method_no_keyword_args.<locals>.fns����H���v�����rr5r*r+rmr�s   @r
�#test_unbound_method_no_keyword_argsz<ProfileSimulatorTestCase.test_unbound_method_no_keyword_argslsh�����	�	�	�	�	���(�(�����!�q�&�'�2� �(�G�4�6�	7�	7�	7�	7�	7rc�p��i��fd�}t|��}|�|dd|fdd|fg��dS)Nc�8��tjtdfi���dSr�r�r�s �r
rlzLProfileSimulatorTestCase.test_unbound_method_invalid_keyword_args.<locals>.fws#����H�U�B�)�)�&�)�)�)�)�)rr5r*r+rmr�s   @r
�(test_unbound_method_invalid_keyword_argszAProfileSimulatorTestCase.test_unbound_method_invalid_keyword_argsush�����	*�	*�	*�	*�	*���(�(�����!�q�&�'�2� �(�G�4�6�	7�	7�	7�	7�	7rN)
r r!r"r_rpr�r|r�r�r�r�r�r�rrr
r�r�s�������&�&�&�!�!�!�!�!�!�!�!�!�!�!�!�:7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7�7rr�c�\�t|d��r|j}n|j}|j|jfS)N�f_code)�hasattrr��__code__�co_firstlineno�co_name)�function�codes  r
r;r;~s5���x��"�"�!������ ������,�,rc�,�||��dS#YdSxYwrr)rlrks  r
�protectr��s ��	
��1��������D�D�D���s��c��|�t��}tj��}tj��	t	j|j��t||��t	jd��|rtj��n#|rtj��wwxYw|�	��dd�S)Nr5���)
r$�gc�	isenabled�disabler	r
r3r��enablerE)rbrk�old_gcs   r
r^r^�s����y��M�M���\�^�^�F��J�L�L�L����q�z�"�"�"���!������t�����	��I�K�K�K����	��I�K�K�K�K�	�����<�<�>�>�!�B�$��s�=B�B#c�H�ddl}|jt|����dS)Nr)r`r^)rbr`s  r
�show_eventsr��s+���M�M�M��F�M�.��*�*�+�+�+�+�+rc� �eZdZd�Zd�Zd�ZdS)�
TestEdgeCasesc��|�tjtj����tjd��dSr)�
addCleanupr	r
rrs r
rzTestEdgeCases.setUp�s6���������(8�(8�9�9�9���t�����rc����d�}d��G�fd�d��}tj|����tj��5}tj|��|�|jj|j��|�|jj	t��ddd��n#1swxYwY|�tj��|��dS)Nc��dSrrrs r
�fooz*TestEdgeCases.test_reentrancy.<locals>.foo�����Crc��dSrrrs r
�barz*TestEdgeCases.test_reentrancy.<locals>.bar�rrc� ��eZdZd�Z�fd�ZdS)�(TestEdgeCases.test_reentrancy.<locals>.Ac��dSrr)rrs  r
�__call__z1TestEdgeCases.test_reentrancy.<locals>.A.__call__�s���rc�0��tj���dSrr)rrs �r
�__del__z0TestEdgeCases.test_reentrancy.<locals>.A.__del__�s�����s�#�#�#�#�#rN)r r!r"r
r)rs�r
�Ar�s=�������
�
�
�
$�
$�
$�
$�
$�
$�
$rr
)r	r
r�catch_unraisable_exception�assertEqual�
unraisable�objectr�assertIsInstance�	exc_value�RuntimeErrorr)rrr
�cmrs    @r
�test_reentrancyzTestEdgeCases.test_reentrancy�sJ���	�	�	�	�	�	�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	��q�q�s�s����
�
/�
1�
1�	I�R��N�3�������R�]�1�1�9�=�=�=��!�!�"�-�"9�<�H�H�H�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�
	
�����)�)�3�/�/�/�/�/s�AB1�1B5�8B5c��d�}tj|��~tjtj����dS)Nc��dSrrrs r
rz+TestEdgeCases.test_same_object.<locals>.foo�rr)r	r
r)rrs  r
�test_same_objectzTestEdgeCases.test_same_object�sD��	�	�	�	��s�������s�~�'�'�(�(�(�(�(rN)r r!r"rrrrrr
r�r��sA���������0�0�0�.)�)�)�)�)rr��__main__r)r�r`r	�unittest�testr�TestCaserr$rGr\rfr�r;r��
protect_identr^r�r�r �mainrrr
�<module>r s��	�	�	�	�
�
�
�
�
�
�
�
�����������,�,�,�,�,�X�&�,�,�,�"K�K�K�K�K�K�K�K�@ 
� 
� 
� 
� 
�{� 
� 
� 
�FL�L�L�L�L�8�$�L�L�L�r!�r!�r!�r!�r!�,�r!�r!�r!�jb7�b7�b7�b7�b7�|�b7�b7�b7�J-�-�-������g���
� � � � �",�,�,�
#)�#)�#)�#)�#)�H�%�#)�#)�#)�L�z����H�M�O�O�O�O�O��r