Your IP : 216.73.216.213


Current Path : /opt/alt/python311/lib64/python3.11/test/test_capi/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/test/test_capi/__pycache__/test_misc.cpython-311.pyc

�

�0�i0���`�ddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZmZ	ddlZn
#e$rdZYnwxYw	ddlZn
#e$rdZYnwxYwejd	��Z ddl!Z!e"ed
��Z#dZ$d�Z%d�Z&Gd
�d��Z'Gd�dej(��Z)Gd�dej(��Z*Gd�dej(��Z+Gd�dej(��Z,Gd�dej(��Z-Gd�dej(��Z.ej/��Gd�dej(����Z0Gd�de0��Z1ej2ej3��d��Gd �d!e0����Z4ej2e#d"��Gd#�d$e0����Z5ej6edud%��Gd&�d'ej(����Z7Gd(�d)ej(��Z8d*Z9Gd+�d,ej(��Z:e;d-krej<��dSdS).�)�OrderedDictN)�support)�MISSING_C_DOCSTRINGS)�
import_helper)�threading_helper)�warnings_helper)�assert_python_failure�assert_python_ok�	_testcapi�gettotalrefcountc�V�|�dd���dd��S)Nzutf-8�replace�
�)�decoder)�errs �?/opt/alt/python311/lib64/python3.11/test/test_capi/test_misc.py�
decode_stderrr.s&���:�:�g�y�)�)�1�1�$��;�;�;�c��|S)zsome doc���selfs r�testfunctionr2s���Krc�b�eZdZe�e��Ze�e��ZdS)�InstanceMethodN)�__name__�
__module__�__qualname__r�instancemethod�idrrrrrr7s4������	�	!�	!�"�	%�	%�B��+�+�L�9�9�L�L�Lrrc���eZdZd�Zej��d���Zd�Zd�Zd�Z	d�Z
eje
d��d���Zeje
d��d	���Zejed
��d���Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zejee d��d��d���Z!d�Z"ej#d��d���Z$ej#d��d���Z%d�Z&ejed
��d ���Z'd!�Z(d"�Z)d#�Z*d$�Z+d%�Z,d&�Z-d'�Z.d(�Z/d)�Z0d*�Z1d+�Z2d,�Z3d=d.�Z4ej��d/���Z5d0�Z6d1�Z7d2�Z8d3�Z9d4�Z:d5�Z;d6�Z<d7�Z=d8�Z>d9�Z?d:�Z@d;�ZAd<S)>�CAPITestc�B�t��}|�t|��|�����|�|���|u��|�|jjtj��|�tjjtj��dtj_|�tjd��|�tt|jdd��dS)N�test�	attribute)
r�assertEqualr!�
assertTruer�__doc__r&�assertRaises�AttributeError�setattr�r�insts  r�test_instancemethodzCAPITest.test_instancemethod=s�����������D���4�7�7�9�9�-�-�-�����)�)�+�+�t�3�4�4�4�����*�2�L�4H�I�I�I�����4�<�l�>R�S�S�S�06��#�-�����/��8�8�8����.�'�4�3D�k�SY�Z�Z�Z�Z�Zrc��tj��5tjtjddgtjtj���}ddd��n#1swxYwY|���\}}|�|d��|�	|�
���d��|��dS)N�-cz4import _testcapi;_testcapi.crash_no_current_thread())�stdout�stderrrs�Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL))r�SuppressCrashReport�
subprocess�Popen�sys�
executable�PIPE�communicater'r(�rstrip�
startswith)r�p�outrs    r� test_no_FatalError_infinite_loopz)CAPITest.test_no_FatalError_infinite_loopHs��
�
(�
*�
*�	9�	9�� �#�.�$�#H�"I�)3��(2��	9�9�9�A�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9����	9�	9�	9�	9��]�]�_�_�
��c�����c�"�"�"�����
�
���/�/�F�G�G��
	�	�	�	�	s�9A�A� Ac�P�|�ttj��dS�N)r*�
ValueErrorr�!make_memoryview_from_NULL_pointerrs r�!test_memoryview_from_NULL_pointerz*CAPITest.test_memoryview_from_NULL_pointer[s!�����*�i�&Q�R�R�R�R�Rrc�V�td��}td��}	|�#t$r�}tj��}t
�|��}tj��}t
�|��}tj��}|�||��|�||��|�||��|�||��|�||��|�||��Yd}~dSd}~wwxYw)N�5�TEST)rB�	TypeError�failr7�	exceptionr�
set_exceptionr')	r�raised_exception�new_exc�e�orig_sys_exception�orig_exception�new_sys_exception�
new_exception�reset_sys_exceptions	         r�test_exceptionzCAPITest.test_exception^s)��%�c�?�?���F�#�#��	.�"�"���
	?�
	?�
	?�!$�����&�4�4�W�=�=�N� #�
����%�3�3�N�C�C�M�"%�-�/�/�����^�Q�/�/�/����^�-=�>�>�>����/��@�@�@����0�.�A�A�A����]�G�4�4�4����.�
�>�>�>�>�>�>�>�>�>�����
	?���s�"�
D(�C1D#�#D(c��td��}td��}	|�#t$�r}|j}t	j��}t�|j|d��}t	j��}t
j|�}t	j��}	|�	|d|��|�
||j||f��|�
||��|�
|	|��|�
||j|df��|�
||��Yd}~dSd}~wwxYw)NrFrGF�)rBrHr(�
__traceback__r7�exc_infor�set_exc_info�	__class__r'�assertSequenceEqual)
rrLrMrN�tb�orig_sys_exc_info�
orig_exc_info�new_sys_exc_info�new_exc_info�reset_sys_exc_infos
          r�
test_exc_infozCAPITest.test_exc_infotsQ��%�c�?�?���F�#�#��	#�"�"���	E�	E�	E���B� #�����%�2�2�7�3D�g�t�T�T�M�"�|�~�~��$�1�=�A�L�!$��������]�1�-�q�1�1�1��$�$�]�5E�5O�Qa�ce�4f�g�g�g��$�$�%6�
�F�F�F��$�$�%7��G�G�G��$�$�\�G�4E�w�PT�3U�V�V�V��$�$�%5�|�D�D�D�D�D�D�D�D�D�����	E���s�"�E�D	D<�<Ec	�6�|�t��5}t�td��ddd��n#1swxYwY|�|jjd��|�t��5}t�ttddd����ddd��n#1swxYwY|jjd}|�|t��|�|jd��|�t��5}t�ttd����ddd��n#1swxYwY|�|jjd	��Gd
�dt��}Gd�d
t|���}|�t��5}t�||����ddd��dS#1swxYwYdS)N�*�rdrV��r�rVrfrg�)ric��eZdZd�ZdS)�&CAPITest.test_set_object.<locals>.Metac��ddzdS)NrVrr)�cls�subs  r�__subclasscheck__z8CAPITest.test_set_object.<locals>.Meta.__subclasscheck__�s���!����rN)rrrrorrr�Metark�s#������
�
�
�
�
rrpc��eZdZdS)�(CAPITest.test_set_object.<locals>.BrokenN�rrrrrr�Brokenrr���������Drrt)�	metaclass)r*rBr�exc_set_objectr'rJ�argsrH�assertIsInstance�PermissionError�OSError�type�	Exception�ZeroDivisionError)rrN�wrappedrprts     r�test_set_objectzCAPITest.test_set_object�s��
�
�
�z�
*�
*�	5�a��$�$�Z��4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5������)�5�1�1�1��
�
�z�
*�
*�	C�a��$�$�Z��1�Q�q�1A�1A�B�B�B�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C����	C�	C�	C�	C��+�"�1�%�����g�y�1�1�1������y�1�1�1��
�
��
/�
/�	C�1��$�$�W�o�b�.A�.A�B�B�B�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C����	C�	C�	C�	C������)�5�1�1�1�	�	�	�	�	�4�	�	�	�	�	�	�	�	�Y�$�	�	�	�	��
�
�0�
1�
1�	7�Q��$�$�V�V�V�X�X�6�6�6�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	7�	7sG�!A�A�A�
0C	�	C
�C
�6.E0�0E4�7E4�$H�H�Hz(_posixsubprocess required for this test.c��Gd�dt��}|�td��5tjd|��ddddd	d
ddd
dddddddddddd��ddd��n#1swxYwYGd�dt��}|�ttjd|��ddddd	d
ddd
dddddddddddd��dS)Nc��eZdZd�ZdS)�1CAPITest.test_seq_bytes_to_charp_array.<locals>.Zc��dS�NrVrrs r�__len__z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__�����qrN�rrrr�rrr�Zr���#������
�
�
�
�
rr��indexingrVT�rVrf�����	�
���
��F����c��eZdZd�Zd�ZdS)r�c��tjSrA)r7�maxsizers rr�z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__�s
���{�"rc��dS)N�xr)r�is  r�__getitem__z=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__�����trN)rrrr�r�rrrr�z1CAPITest.test_seq_bytes_to_charp_array.<locals>.Z�s2������
#�
#�
#�
�
�
�
�
r)�object�assertRaisesRegexrH�_posixsubprocess�	fork_execr*�MemoryError�rr�s  r�test_seq_bytes_to_charp_arrayz&CAPITest.test_seq_bytes_to_charp_array�s���	�	�	�	�	��	�	�	��
#�
#�I�z�
:�
:�	k�	k��&��A�A�C�C��V�A�a��!�A�b��B�r�"�T�$�r�RW�XZ�[]�^`�ac�di�
k�
k�
k�	k�	k�	k�	k�	k�	k�	k�	k�	k�	k�	k����	k�	k�	k�	k�	�	�	�	�	��	�	�	�
	
���+�'7�'A��A�A�C�C��V�A�a��!�A�b��B�r�"�T�$�r�RW�XZ�[]�^`�ac�di�	k�	k�	k�	k�	ks�3A.�.A2�5A2c��Gd�dt��}|�ttj|��dgdddddd	d
ddd
ddddddddddd��dS)Nc��eZdZd�ZdS)�-CAPITest.test_subprocess_fork_exec.<locals>.Zc��dSr�rrs rr�z5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__�r�rNr�rrrr�r��r�rr��1Tr�r�r�r�r�r�r�r�r�r�r�r�Fr�r�r�r�)r�r*rHr�r�r�s  r�test_subprocess_fork_execz"CAPITest.test_subprocess_fork_exec�s���	�	�	�	�	��	�	�	�
	
���)�%5�%?��!�#�#�t�f�T�&��1�Q�q��2�b��B�r�$�t�TV�W\�]_�`b�ce�fh�in�	p�	p�	p�	p�	prz6Signature information for builtins requires docstringsc��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tj	jd��|�tj	jd��|�tj
jd��|�tj
jd��|�tjjd��|�tjjd��dS)Nz This docstring has no signature.z[docstring_with_invalid_signature($module, /, boo)

This docstring has an invalid signature.zedocstring_with_invalid_signature2($module, /, boo)

--

This docstring also has an invalid signature.z%This docstring has a valid signature.z($module, /, sig)z>
This docstring has a valid signature and some extra newlines.z($module, /, parameter))r'r�no_docstringr)�__text_signature__�docstring_empty�docstring_no_signature� docstring_with_invalid_signature�!docstring_with_invalid_signature2�docstring_with_signature�#docstring_with_signature_but_no_doc�+docstring_with_signature_and_extra_newlinesrs r� test_docstring_signature_parsingz)CAPITest.test_docstring_signature_parsing�s��	
����/�7��>�>�>�����/�B�D�I�I�I�����2�:�D�A�A�A�����2�E�t�L�L�L�����9�A�.�	0�	0�	0�����9�L�d�S�S�S�����C�K�
7�	�	�	�
	
����C�V�X\�]�]�]�����D�L�
<�	�	�	�	
����D�W�Y]�^�^�^�����;�C�3�	5�	5�	5�����;�N�Pc�d�d�d�����F�N�PT�U�U�U�����F�Y��	!�	!�	!�	
����N�V�M�	O�	O�	O�����N�a�%�	'�	'�	'�	'�	'rc��tj}|��}|��}|�||zd||f��|�|dzd|df��|�d|zdd|f��|}||z}|�|d||f��|}|dz}|�|d|df��d}||z}|�|dd|f��dS)N�matmulrd�imatmul)r�
matmulTyper')r�M�m1�m2�os     r�&test_c_type_with_matrix_multiplicationz/CAPITest.test_c_type_with_matrix_multiplication�s
��� ��
�Q�S�S��
�Q�S�S������b��8�R��"4�5�5�5�����b��8�R��"4�5�5�5�����b��8�R��"4�5�5�5���	�R�������Y��B�/�0�0�0���	�R�������Y��B�/�0�0�0���	�R�������X�r�2�.�/�/�/�/�/rc���t���}|�|�d��d��|�|�dd��d��dS)NrV)rVNrf)rfrf)r�ipowTyper'�__ipow__)rr�s  r�test_c_type_with_ipowzCAPITest.test_c_type_with_ipow�s_��
��� � ��������A���	�2�2�2�������A�q�)�)�6�2�2�2�2�2rc��trOtjd��}td|��\}}}t	|��}|�|d��dS|�t��5}t�	��ddd��n#1swxYwY|�t|j��d��dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r1a#Fatal Python error: _Py_CheckFunctionResult: a function returned NULL without setting an exception\nPython runtime state: initialized\nSystemError: <built-in function return_null_without_error> returned NULL without setting an exception\n\nCurrent thread.*:\n  File .*", line 6 in <module>\nzFreturn_null_without_error.* returned NULL without setting an exception)�Py_DEBUG�textwrap�dedentr	r�assertRegexr*�SystemErrorr�return_null_without_error�strrJ�r�code�rcr>r�cms      r�test_return_null_without_errorz'CAPITest.test_return_null_without_errors#���	K��?�$���D�1��t�<�<�L�B��S���$�$�C����S�4�
5�
5�
5�
5�
5��"�"�;�/�/�
6�2��3�3�5�5�5�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6����S���.�.�J�
K�
K�
K�
K�
K��1B�B�Bc��trOtjd��}td|��\}}}t	|��}|�|d��dS|�t��5}t�	��ddd��n#1swxYwY|�t|j��d��dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            r1aqFatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set\nPython runtime state: initialized\nValueError\n\nThe above exception was the direct cause of the following exception:\n\nSystemError: <built-in function return_result_with_error> returned a result with an exception set\n\nCurrent thread.*:\n  File .*, line 6 in <module>\nzBreturn_result_with_error.* returned a result with an exception set)r�r�r�r	rr�r*r�r�return_result_with_errorr�rJr�s      r�test_return_result_with_errorz&CAPITest.test_return_result_with_error#s!���	H��?�$���D�1��t�<�<�L�B��S���$�$�C����S�
7�
8�
8�
8�
8�
8� �"�"�;�/�/�
5�2��2�2�4�4�4�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5����
5�
5�
5�
5����S���.�.�G�
H�
H�
H�
H�
Hr�c���tjd��}td|��\}}}t|��}d|vr|�|d��dS|�d|��dS)Nz�
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.getitem_with_error({1: 2}, 1)
        r1z
SystemError: aFatal Python error: _Py_CheckSlotResult: Slot __getitem__ of type dict succeeded with an exception set\nPython runtime state: initialized\nValueError: bug\n\nCurrent thread .* \(most recent call first\):\n  File .*, line 6 in <module>\n\nExtension modules: _testcapi \(total: 1\)\nz'returned a result with an exception set)r�r�r	rr��assertIn�rr�r�r>rs     r�test_getitem_with_errorz CAPITest.test_getitem_with_errorEs����� �
�
��-�T�4�8�8���C���C� � ���#�%�%����S�	C�

D�

D�

D�

D�

D�
�M�M�C�S�I�I�I�I�Irc�8�t���dSrA)r�test_buildvalue_Nrs rr�zCAPITest.test_buildvalue_Ncs���#�#�%�%�%�%�%rc�j�d}td|��\}}}|���}t|d��D]w\}}|�d|��|�d���^}}	t|	��}	|�|	|dz��|�|	|dzdz
���xdS)Na*if 1:
            import _testcapi

            class C(): pass

            # The first loop tests both functions and that remove_mem_hooks()
            # can be called twice in a row. The second loop checks a call to
            # set_nomemory() after a call to remove_mem_hooks(). The third
            # loop checks the start and stop arguments of set_nomemory().
            for outer_cnt in range(1, 4):
                start = 10 * outer_cnt
                for j in range(100):
                    if j == 0:
                        if outer_cnt != 3:
                            _testcapi.set_nomemory(start)
                        else:
                            _testcapi.set_nomemory(start, start + 1)
                    try:
                        C()
                    except MemoryError as e:
                        if outer_cnt != 3:
                            _testcapi.remove_mem_hooks()
                        print('MemoryError', outer_cnt, j)
                        _testcapi.remove_mem_hooks()
                        break
        r1rVsMemoryError� r�rf)r
�
splitlines�	enumerater��split�int�assertLessEqual�assertGreaterEqual)
rr�r�r>r�linesr��line�_�counts
          r�test_set_nomemoryzCAPITest.test_set_nomemoryfs�����4(��d�3�3���C����� � �� ���*�*�	2�	2�G�A�t��M�M�.�#�.�.�.��
�
�4�(�(�I�Q����J�J�E�� � ���!��,�,�,��#�#�E�1�Q�3�q�5�1�1�1�1�	2�	2rc
��Gd�dt��}Gd�dt��}dddd�}it��|��|��|t|��||��||��fD]�}|�t�|��t|�������|�t�|��t|�������|�t�	|��t|�
��������dS)	Nc�2��eZdZ�fd�Z�fd�Z�fd�Z�xZS)�9CAPITest.test_mapping_keys_values_items.<locals>.Mapping1c�^��tt�������SrA)�list�super�keys�rrZs �rr�z>CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.keys�s����E�G�G�L�L�N�N�+�+�+rc�^��tt�������SrA)r�r��valuesr�s �rr�z@CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.values�s����E�G�G�N�N�,�,�-�-�-rc�^��tt�������SrA)r�r��itemsr�s �rr�z?CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.items�s����E�G�G�M�M�O�O�,�,�,r�rrrr�r�r��
__classcell__�rZs@r�Mapping1r��sj�������
,�
,�
,�
,�
,�
.�
.�
.�
.�
.�
-�
-�
-�
-�
-�
-�
-�
-�
-rr�c�2��eZdZ�fd�Z�fd�Z�fd�Z�xZS)�9CAPITest.test_mapping_keys_values_items.<locals>.Mapping2c�^��tt�������SrA)�tupler�r�r�s �rr�z>CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.keys�s����U�W�W�\�\�^�^�,�,�,rc�^��tt�������SrA)rr�r�r�s �rr�z@CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.values�s����U�W�W�^�^�-�-�.�.�.rc�^��tt�������SrA)rr�r�r�s �rr�z?CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.items�s����U�W�W�]�]�_�_�-�-�-rr�r�s@r�Mapping2r��sj�������
-�
-�
-�
-�
-�
/�
/�
/�
/�
/�
.�
.�
.�
.�
.�
.�
.�
.�
.rrrVrfrg)�foo�bar�spam)�dictr�assertListEqualr�get_mapping_keysr�r��get_mapping_valuesr��get_mapping_itemsr�)rr�r�dict_obj�mappings     r�test_mapping_keys_values_itemsz'CAPITest.test_mapping_keys_values_items�s|��	-�	-�	-�	-�	-�t�	-�	-�	-�	.�	.�	.�	.�	.�t�	.�	.�	.��Q��2�2���K�M�M�8�8�:�:�x�x�z�z� �+�h�"7�"7� ���*�*�H�H�X�,>�,>�@�	8�	8�G�
� � ��!;�!;�G�!D�!D�!%�g�l�l�n�n�!5�!5�
7�
7�
7�� � ��!=�!=�g�!F�!F�!%�g�n�n�&6�&6�!7�!7�
9�
9�
9�� � ��!<�!<�W�!E�!E�!%�g�m�m�o�o�!6�!6�
8�
8�
8�
8�	8�	8rc��|�ttjd��|�ttjd��|�ttjd��Gd�d��}|��}|�ttj|��|�ttj|��|�ttj|��dS)Nc� �eZdZd�Zd�Zd�ZdS)�CCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMappingc��dSrArrs rr�zHCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.keys�r�rc��dSrArrs rr�zJCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.values�r�rc��dSrArrs rr�zICAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.items�r�rN)rrrr�r�r�rrr�
BadMappingr�sA������
�
�
�
�
�
�
�
�
�
�
rr)r*r+rr	r
rrH)rr�bad_mappings   r�&test_mapping_keys_values_items_bad_argz/CAPITest.test_mapping_keys_values_items_bad_arg�s������.�)�*D�d�K�K�K����.�)�*F��M�M�M����.�)�*E�t�L�L�L�	�	�	�	�	�	�	�	�!�j�l�l�����)�Y�%?��M�M�M����)�Y�%A�;�O�O�O����)�Y�%@�+�N�N�N�N�Nrc��ddi}|�t�|d����|�t�|d����Gd�dt��}|ddi��}|�t�|d����|�t�|d����dS)N�arV�bc��eZdZdS)�.CAPITest.test_mapping_has_key.<locals>.SubDictNrsrrr�SubDictr�rurr)r(r�mapping_has_key�assertFalser)r�dctr�dct2s    r�test_mapping_has_keyzCAPITest.test_mapping_has_key�s����A�h�����	�1�1�#�s�;�;�<�<�<�����2�2�3��<�<�=�=�=�	�	�	�	�	�d�	�	�	��w��Q�x� � �����	�1�1�$��<�<�=�=�=�����2�2�4��=�=�>�>�>�>�>rc���gd�}|���}t�|ddddg��ddg|dd�<|�||��|�|gd���Gd�d��}|��}t�|d	d
d��|�|jtd	d
����|�|jd��d}|�t��5t�|ddd
��ddd��n#1swxYwY|�|d��d}|�t��5t�|ddd��ddd��n#1swxYwY|�|d��|�t��5t�dddd��ddd��n#1swxYwYdddd�}|�t��5t�|ddd��ddd��n#1swxYwY|�|dddd���dS)N�rVrfrg�r�rVrgr�r�)rVr�r�r%r�c��eZdZd�ZdS)�0CAPITest.test_sequence_set_slice.<locals>.Customc�"�||_||_dSrA)�index�value)rr)r*s   r�__setitem__z<CAPITest.test_sequence_set_slice.<locals>.Custom.__setitem__�s��"��
�"��
�
�
rN)rrrr+rrr�Customr'�s#������
#�
#�
#�
#�
#rr,rr��abc�rVrfrgr%)r�r��abcd�xyrr�crh)	�copyr�sequence_set_slicer'r)�slicer*r*rH�r�data�	data_copyr,r1�bad_seq1�bad_seq2r
s        r�test_sequence_set_slicez CAPITest.test_sequence_set_slice�s��������I�I�K�K�	��$�$�T�1�a�!�Q��8�8�8��Q��	�!�A�#������y�)�)�)��������/�/�/�	#�	#�	#�	#�	#�	#�	#�	#�

�F�H�H���$�$�Q��1�e�4�4�4������%��1�+�+�.�.�.������%�(�(�(� ��
�
�
�y�
)�
)�	A�	A��(�(��1�a��@�@�@�	A�	A�	A�	A�	A�	A�	A�	A�	A�	A�	A����	A�	A�	A�	A�����<�0�0�0���
�
�
�y�
)�
)�	?�	?��(�(��1�a��>�>�>�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?�����6�*�*�*��
�
�y�
)�
)�	;�	;��(�(��q�!�T�:�:�:�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;��c�c�*�*��
�
�
�y�
)�
)�	>�	>��(�(��!�Q��=�=�=�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>����	>�	>�	>�	>�����c�c�c�":�":�;�;�;�;�;sH�D-�-D1�4D1�*F�F�F�G9�9G=�G=�$I�I�Ic��gd�}|���}t�|dd��|dd�=|�||��|�|gd���Gd�d��}|��}t�|dd��|�|jtdd����d	}|�t��5t�|dd��ddd��n#1swxYwY|�|d	��d
}|�t��5t�|dd��ddd��n#1swxYwY|�|d
��|�t��5t�ddd��ddd��n#1swxYwYddd
d�}|�t��5t�|dd��ddd��n#1swxYwY|�|ddd
d���dS)Nr$rVrg)rVr%r�c��eZdZd�ZdS)�0CAPITest.test_sequence_del_slice.<locals>.Customc��||_dSrA)r))rr)s  r�__delitem__z<CAPITest.test_sequence_del_slice.<locals>.Custom.__delitem__�s
��"��
�
�
rN)rrrr?rrrr,r=�s#������
#�
#�
#�
#�
#rr,rr�r.r/rrr1rh)r2r�sequence_del_slicer'r)r4r*rHr5s        r�test_sequence_del_slicez CAPITest.test_sequence_del_slice�sM�������I�I�K�K�	��$�$�T�1�a�0�0�0��a��c�N�����y�)�)�)�����y�y�y�)�)�)�	#�	#�	#�	#�	#�	#�	#�	#�
�F�H�H���$�$�Q��1�-�-�-������%��1�+�+�.�.�.� ��
�
�
�y�
)�
)�	9�	9��(�(��1�a�8�8�8�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9����	9�	9�	9�	9�����<�0�0�0���
�
�
�y�
)�
)�	9�	9��(�(��1�a�8�8�8�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9����	9�	9�	9�	9�����6�*�*�*��
�
�y�
)�
)�	5�	5��(�(��q�!�4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5��c�c�*�*��
�
�
�y�
)�
)�	8�	8��(�(��!�Q�7�7�7�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�����c�c�c�":�":�;�;�;�;�;sH� D	�	D
�D
�E/�/E3�6E3�*G�G�G�>H'�'H+�.H+�negative_refcountz need _testcapi.negative_refcountc��tjd��}td|��\}}}|�|d��dS)Nz�
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        r1s`_testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)r�r�r	r�r�s     r�test_negative_refcountzCAPITest.test_negative_refcountsZ��
�� �
�
��-�T�4�8�8���C������;�	<�	<�	<�	<�	<rc�R�ddlm}d}td��D]}||f��}�dS)Nr��MyList��)rrG�range)rrG�Lr�s    r�test_trashcan_subclasszCAPITest.test_trashcan_subclass$sK��	%�$�$�$�$�$����t���	�	�A����t���A�A�	�	r�cpuc�:�|�t��dSrA)�do_test_trashcan_python_classr�rs r�test_trashcan_python_class1z$CAPITest.test_trashcan_python_class1,s���*�*�4�0�0�0�0�0rc�<�ddlm}|�|��dS)NrrF)rrGrN)rrGs  r�test_trashcan_python_class2z$CAPITest.test_trashcan_python_class20s.��$�$�$�$�$�$��*�*�6�2�2�2�2�2rc���Gd�d|��}dD]e}d}td��D]}||f��}||_�|r|f}|�|jd��~|�|jd���fdS)Nc�,��eZdZdZ�fd�Z�fd�Z�xZS)�6CAPITest.do_test_trashcan_python_class.<locals>.PyListrc�T���xjdz
c_t��j|�dSr�)�numr��__init__)rrxrZs  �rrWz?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__=s-����
�
��"�
�
� ���� �$�'�'�'�'rc�(���xjdzc_dSr�)rVr�s �r�__del__z>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__@s����
�
��"�
�
�
�
r)rrrrVrWrYr�r�s@r�PyListrT9sX��������C�
(�
(�
(�
(�
(�
#�
#�
#�
#�
#�
#�
#�
#�
#rrZ)rrVir)rI�attr�
assertGreaterrVr')r�baserZ�parityrJr�s      rrNz&CAPITest.do_test_trashcan_python_class5s���	#�	#�	#�	#�	#�T�	#�	#�	#��	,�	,�F��A��5�\�\�
�
���F�A�4�L�L�������
��D�����v�z�1�-�-�-�����V�Z��+�+�+�+�	,�	,rc��|�tjjd��|�tjjd��dS)N�somedocz(arg1, arg2))r'r�HeapDocCTyper)r�rs r�&test_heap_ctype_doc_and_text_signaturez/CAPITest.test_heap_ctype_doc_and_text_signatureQsB��	
����/�7��C�C�C�����/�B�N�S�S�S�S�Src�P�|�tjjd��dSrA)r'r�
NullTpDocTyper)rs r�test_null_type_doczCAPITest.test_null_type_docWs$������0�8�$�?�?�?�?�?rc�6�Gd�dtj��}|��}tj|��}|�|jd��|�|jd��~|�|dz
tj|����dS)Nc���eZdZ�fd�Z�xZS)�`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclassc�V��d|_t�����dS�Nr���value2r�rWr�s �rrWziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__\�&��� ������ � �"�"�"�"�"r�rrrrWr�r�s@r�HeapGcCTypeSubclassrh[�8�������
#�
#�
#�
#�
#�
#�
#�
#�
#rror�r�rV)r�HeapGcCTyper7�getrefcountr'r*rl)rro�subclass_instance�type_refcnts    r�:test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncezCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_onceZs���	#�	#�	#�	#�	#�)�"7�	#�	#�	#�
0�/�1�1���o�&9�:�:��	
���*�0�"�5�5�5����*�1�2�6�6�6�
�����q��#�/�:M�*N�*N�O�O�O�O�Orc����Gd�dtj���G��fd�d�������}tj���}tj���}|�|jd��|�|jd��~tr|�|�j��n|�|dz
�j��|�|dz�j��|�|dz
tj�����|�|tj�����dS)Nc���eZdZ�fd�Z�xZS)�dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Ac�V��d|_t�����dSrjrkr�s �rrWzmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__mrmrrnr�s@r�Arxlrprrzc�,���eZdZ�fd�Z��fd�Z�xZS)�dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bc�H��t�����dSrA)r�rWr�s �rrWzmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__rs������ � �"�"�"�"�"rc�z���|_tj����_tj����_dSrA)rZr7rr�
refcnt_in_del)rrz�Bs ��rrYzlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__us0���!"���"%�/�!�"4�"4���"%�/�!�"4�"4����r)rrrrWrYr�)rZrzr�s@��rr�r|qsW��������
#�
#�
#�
#�
#�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5rr�r�r�rV)	rrqr7rrr'r*rlr�r)rrsrt�new_type_refcntrzr�s    @@r�Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncezYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_onceks}����	#�	#�	#�	#�	#�	�%�	#�	#�	#�
	5�	5�	5�	5�	5�	5�	5�	5��	5�	5�	5��A�C�C���o�a�(�(���/�!�,�,��	
���*�0�"�5�5�5����*�1�2�6�6�6���	?�
���[�!�/�:�:�:�:����[�1�_�a�o�>�>�>�����1�,�a�o�>�>�>�	
����q��#�/�!�*<�*<�=�=�=�	
����#�/�!�*<�*<�=�=�=�=�=rc�^�t���}d|_|�|jd��|�|j|j��|�|jddi��t���}|�i|j��dS�Nrdr)r�HeapCTypeWithDictrr'�dictobj�__dict__r-s  r�test_heaptype_with_dictz CAPITest.test_heaptype_with_dict�s����*�*�,�,����������2�&�&�&������t�}�5�5�5�������r�{�3�3�3��*�*�,�,������T�]�+�+�+�+�+rc�^�t���}d|_|�|jd��|�|j|j��|�|jddi��t���}|�i|j��dSr�)r�HeapCTypeWithNegativeDictrr'r�r�r-s  r� test_heaptype_with_negative_dictz)CAPITest.test_heaptype_with_negative_dict�s����2�2�4�4����������2�&�&�&������t�}�5�5�5�������r�{�3�3�3��2�2�4�4������T�]�+�+�+�+�+rc���t���}tj|��}|�|��|��|�|j|��dSrA)r�HeapCTypeWithWeakref�weakref�refr'�weakreflist)rr.r�s   r�test_heaptype_with_weakrefz#CAPITest.test_heaptype_with_weakref�s]���-�-�/�/���k�$������������%�%�%�����)�3�/�/�/�/�/rc��t���}t|��}|�|d��dS)Ns1234)r�HeapCTypeWithBuffer�bytesr')rr.rs   r�test_heaptype_with_bufferz"CAPITest.test_heaptype_with_buffer�s:���,�,�.�.���$�K�K������G�$�$�$�$�$rc�L�t���}tjtj��}|�|jd��|�|jd��~|�|dz
tjtj����dS�Nr�r�rV)r�HeapCTypeSubclassr7rrr'r*rl)rrsrts   r�9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncezBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once�s���%�7�7�9�9���o�i�&A�B�B��	
���*�0�"�5�5�5����*�1�2�6�6�6�
�����q��#�/�)�:U�*V�*V�W�W�W�W�Wrc���t���}tjtj��}tjtj��}|�|jd��|�|jd��~tr&|�|tjj	��n(|�|dz
tjj	��|�|dztjj	��|�|dz
tjtj����|�|tjtj����dSr�)
r�HeapCTypeSubclassWithFinalizerr7rrr�r'r*rlr�r)rrsrtr�s    r�Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncezXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_once�s4��%�D�D�F�F���o�i�&N�O�O���/�)�*E�F�F��	
���*�0�"�5�5�5����*�1�2�6�6�6�
��	f�
���[�)�*R�*`�a�a�a�a����[�1�_�i�.V�.d�e�e�e�����1�,�i�.I�.W�X�X�X�	
����q��#�/�)�:b�*c�*c�d�d�d�	
����#�/�)�:U�*V�*V�W�W�W�W�Wrc���t���}|�|jd��d|_|�|jd��|`|�|jd��dS)Nr�r�r)r�HeapCTypeSetattrr'�pvaluer*)r�objs  r�test_heaptype_with_setattroz$CAPITest.test_heaptype_with_setattro�sm���(�(�*�*�������R�(�(�(���	������R�(�(�(��I������Q�'�'�'�'�'rc��Gd�dtjtj��}Gd�dtjtj��}tjtjtjtjfD]d}tjtjtjtjfD]}||urGd�d||��}�Gd�d||��}Gd	�d
||��}�edS)Nc��eZdZdS)�MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both1Nrsrrr�Both1r��rurr�c��eZdZdS)�MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both2Nrsrrr�Both2r��rurr�c��eZdZdS)�ICAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.SNrsrrr�Sr��s�������rr�c��eZdZdS)�JCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.B1Nrsrrr�B1r����������rr�c��eZdZdS)�JCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.B2Nrsrrr�B2r��r�rr�)rr�r��HeapCTypeWithDict2�HeapCTypeWithWeakref2)rr�r�rm�cls2r�r�r�s        r�5test_multiple_inheritance_ctypes_with_weakref_or_dictz>CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict�sU��	�	�	�	�	�I�2�I�4O�	�	�	�	�	�	�	�	�I�/��1O�	�	�	��/��1M��*�I�,K�M�
	�
	�C�"�4�i�6R��.�	�0O�Q�
�
���d�?�?������C������
�
�
�
�
�U�C�
�
�
�
�
�
�
�
�U�C�
�
�
�
�
	�
	rc��ddlm}|�|dd��d��|�|dd��d��|�|dd��d	��|�|dd
��d��|�|dd��d
��|�|dd��d��|�|dd��d��|�|dd
��d��|�t|dd��|�t|d	d��|�t
|dd��dS)Nr)�pynumber_tobase�{rf�	0b1111011r��0o173r��123��0x7bi����z
-0b1111011z-0o173z-123z-0x7bg�^@)rr�r'r*rHr�)rr�s  r�test_pynumber_tobasezCAPITest.test_pynumber_tobase�sx��-�-�-�-�-�-�������a�0�0�+�>�>�>�������a�0�0�'�:�:�:�������b�1�1�5�9�9�9�������b�1�1�6�:�:�:�������q�1�1�<�@�@�@�������q�1�1�8�<�<�<�������r�2�2�F�;�;�;�������r�2�2�G�<�<�<����)�_�e�R�@�@�@����)�_�e�R�@�@�@����+���Q�?�?�?�?�?rrc���tj��5tdd|��\}}}ddd��n#1swxYwYt|��}|�d|��tjd|t
j��}|s|�d|����t|�
d������d����}t|�
d����}	|D]}
|�|
|���|D]}
|�|
|���|�t!|��|	��dS)	Nz-sSIr1z.Fatal Python error: test_fatal_error: MESSAGE
z,^Extension modules:(.*) \(total: ([0-9]+)\)$z$Cannot find 'Extension modules:' in rVz, rf)rr4r	rr��re�search�	MULTILINErI�set�group�stripr�r��assertNotInr'�len)rr��expected�not_expectedr�r>r�match�modules�total�names           r�check_fatal_errorzCAPITest.check_fatal_errors���
�
(�
*�
*�	E�	E�0���t�D�D�L�B��S�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E��C� � ���
�
�G��	�	�	��	�I��r�|�-�-���	F��I�I�D�S�D�D�E�E�E��e�k�k�!�n�n�*�*�,�,�2�2�4�8�8�9�9���E�K�K��N�N�#�#���	)�	)�D��M�M�$��(�(�(�(� �	,�	,�D����T�7�+�+�+�+�����W���u�-�-�-�-�-s�6�:�:c��d}d}d}|�|||��d}d}tjd��}|�||��dS)N)r)r7z8import _testcapi, sys; _testcapi.fatal_error(b"MESSAGE")z�
            import _testcapi, sys
            sys.stdlib_module_names = frozenset({"_testcapi"})
            _testcapi.fatal_error(b"MESSAGE")
        )r�r�r�)rr�r�r�s    r�test_fatal_errorzCAPITest.test_fatal_errorsk��"����I�����t�X�|�<�<�<���%���� �
�
��
	
���t�X�.�.�.�.�.rc�d�t���}|�|d��dS�Nz<NULL>)r�pyobject_repr_from_nullr'�r�ss  r�test_pyobject_repr_from_nullz%CAPITest.test_pyobject_repr_from_null*s/���-�-�/�/������H�%�%�%�%�%rc�d�t���}|�|d��dSr�)r�pyobject_str_from_nullr'r�s  r�test_pyobject_str_from_nullz$CAPITest.test_pyobject_str_from_null.s/���,�,�.�.������H�%�%�%�%�%rc�d�t���}|�|d��dS)Ns<NULL>)r�pyobject_bytes_from_nullr'r�s  r�test_pyobject_bytes_from_nullz&CAPITest.test_pyobject_bytes_from_null2s/���.�.�0�0������I�&�&�&�&�&rc��tj}d}||��}t|dd��}|�|j|j��dS)Ns%# -*- coding: latin1 -*-
print('¤')
z<string>�exec)r�Py_CompileString�compiler'�	co_consts)r�_compiler��resultr�s     r�test_Py_CompileStringzCAPITest.test_Py_CompileString6sO���-��?����$�����4��V�4�4������)�8�+=�>�>�>�>�>rc��tjd��}g}ttd��r|�d��t
jdkr|�d��|D]X}|�|���5|�t|j	|����ddd��n#1swxYwY�YdS)N�ctypes�
get_native_id�PyThread_get_thread_native_id�nt�
Py_FrozenMain)r�)
r�
import_module�hasattr�_thread�append�osr��subTestr(�	pythonapi)rr��namesr�s    r�test_export_symbolszCAPITest.test_export_symbols>s���,�X�6�6�����7�O�,�,�	:��L�L�8�9�9�9��7�d�?�?��L�L��)�)�)��	A�	A�D����4��(�(�
A�
A������(8�$� ?� ?�@�@�@�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A����
A�
A�
A�
A��	A�	As�)B5�5B9	�<B9	c� �d�}Gd�d��}|�t�|��d��|�t�|j��d��|�t�|��j��d��|�t�t��d��|�t�|��d��dS)Nc��dSrArrrr�function_examplez:CAPITest.test_eval_get_func_name.<locals>.function_exampleV����rc��eZdZd�ZdS)�+CAPITest.test_eval_get_func_name.<locals>.Ac��dSrArrs r�method_examplez:CAPITest.test_eval_get_func_name.<locals>.A.method_exampleYr�rN�rrrr�rrrrzr�X�������)�)�)�)�)rrzr�r��sumr|)r'r�eval_get_func_namer�r��rr�rzs   r�test_eval_get_func_namez CAPITest.test_eval_get_func_nameUs��#�#�#�	*�	*�	*�	*�	*�	*�	*�	*�	
����5�5�6F�G�G�+�	-�	-�	-�����5�5�a�6F�G�G�)�	+�	+�	+�����5�5�a�a�c�c�6H�I�I�)�	+�	+�	+�����5�5�c�:�:�E�B�B�B�����5�5�a�8�8�&�A�A�A�A�Arc� �d�}Gd�d��}|�t�|��d��|�t�|j��d��|�t�|��j��d��|�t�t��d��|�t�|��d��dS)Nc��dSrArrrrr�z:CAPITest.test_eval_get_func_desc.<locals>.function_exampleer�rc��eZdZd�ZdS)�+CAPITest.test_eval_get_func_desc.<locals>.Ac��dSrArrs rr�z:CAPITest.test_eval_get_func_desc.<locals>.A.method_examplehr�rNr�rrrrzrgr�rrzz()z object)r'r�eval_get_func_descr�r�rs   r�test_eval_get_func_descz CAPITest.test_eval_get_func_descds��#�#�#�	*�	*�	*�	*�	*�	*�	*�	*�	
����5�5�6F�G�G��	�	�	�����5�5�a�6F�G�G��	�	�	�����5�5�a�a�c�c�6H�I�I��	�	�	�����5�5�c�:�:�D�A�A�A�����5�5�a�8�8�)�D�D�D�D�Drc�N�ddl}d�}t�|��}|�||j��|�||j��|�t��5t�d��ddd��dS#1swxYwYdS)Nrc��dSrArrrr�somez-CAPITest.test_function_get_code.<locals>.somev����Dr)	�typesr�function_get_codery�CodeTyper'�__code__r*r�)rrrr�s    r�test_function_get_codezCAPITest.test_function_get_codess�������	�	�	��*�*�4�0�0�����d�E�N�3�3�3�����t�}�-�-�-�
�
�
�{�
+�
+�	.�	.��'�'��-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	.�	.s�2B�B�!Bc�F�d�}t�|��}|�|t��|�||j��|�t��5t�d��ddd��dS#1swxYwYdS)Nc��dSrArrrrrz0CAPITest.test_function_get_globals.<locals>.some�r
r)r�function_get_globalsryrr'�__globals__r*r�)rr�globals_s   r�test_function_get_globalsz"CAPITest.test_function_get_globals�s���	�	�	��1�1�$�7�7�����h��-�-�-�����4�#3�4�4�4�
�
�
�{�
+�
+�	1�	1��*�*�4�0�0�0�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1�	1�	1��.B�B�Bc�F�d�}t�|��}|�|t��|�||j��|�t��5t�d��ddd��dS#1swxYwYdS)Nc��dSrArrrrrz/CAPITest.test_function_get_module.<locals>.some�r
r)r�function_get_moduleryr�r'rr*r�)rr�modules   r�test_function_get_modulez!CAPITest.test_function_get_module�s���	�	�	��.�.�t�4�4�����f�c�*�*�*�������1�1�1�
�
�
�{�
+�
+�	0�	0��)�)�$�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0rc���tj}|�|d��tj��tjtdd��5|�|d�����d��ddd��n#1swxYwY|�|d��t��|�|d��t��dS)Nsstdout�🐍rdsnonexisting��)
r�
sys_getobject�assertIsr7r2r�	swap_attrr'�encoder+)r�	getobjects  r�test_sys_getobjectzCAPITest.test_sys_getobject�s���+�	��
�
�i�i�	�*�*�C�J�7�7�7�
�
�s�L�"�
5�
5�	C�	C����Y�Y�|�':�':�'<�'<�=�=�r�B�B�B�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C����	C�	C�	C�	C�	
�
�
�i�i��/�/��@�@�@��
�
�i�i��(�(�.�9�9�9�9�9s�2B�B�Bc��tj}dg}dg}	|�|d|��d��|�tj|��|�|d|��d��|�tj|��|�|dt��d��|�ttd����|�|dt��d��tj
t��5t`ddd��n#1swxYwYn=#tj
t��5t`ddd��w#1swxYwYwxYw	|�|d���|��d��|�ttd��|��|�|d���t��d��|�ttd����tj
t��5ttd��ddd��n#1swxYwYnK#tj
t��5ttd��ddd��w#1swxYwYwxYw|�t ��5|d|��ddd��dS#1swxYwYdS)Nr*rlsnewattrr�newattrr r!)r�
sys_setobjectr'r#r7r)�NULLrr��
contextlib�suppressr+r%�getattr�delattrr*�UnicodeDecodeError)r�	setobjectr*rls    r�test_sys_setobjectzCAPITest.test_sys_setobject�s����+�	��	�����
	 ����Y�Y�z�5�9�9�1�=�=�=��M�M�#�+�u�-�-�-����Y�Y�z�6�:�:�A�>�>�>��M�M�#�+�v�.�.�.����Y�Y�z�4�8�8�!�<�<�<����W�S�)�4�4�5�5�5����Y�Y�z�4�8�8�!�<�<�<��$�^�4�4�
 �
 ��K�
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 ����$�^�4�4�
 �
 ��K�
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �
 ����	+����Y�Y�|�':�':�'<�'<�e�D�D�a�H�H�H��M�M�'�#�|�4�4�e�<�<�<����Y�Y�|�':�':�'<�'<�d�C�C�Q�G�G�G����W�S�,�7�7�8�8�8��$�^�4�4�
+�
+���\�*�*�*�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+����
+�
+�
+�
+����$�^�4�4�
+�
+���\�*�*�*�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+����
+�
+�
+�
+�
+�����
�
�1�
2�
2�	&�	&��I�g�u�%�%�%�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&�	&�	&s��C2D?�D3�3D7�:D7�?E9�E-�!E9�-E1�1E9�4E1�5E9�=B:I>�I2�2I6�9I6�>K�J:�.K�:J>�>K�J>�K�#
K=�=L�LN)r)Brrrr/r�requires_subprocessr?rDrTrbr��unittest�
skipUnlessr�r�r��skipIfrr�r�r�r�r�r�r�r�rrr"r:rAr�rrDrK�requires_resourcerOrQrNrbrerur�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr	rrrr'r2rrrr#r#;s�������	[�	[�	[�!�W� �"�"���#�"��$S�S�S�.�.�.�,#�#�#�.7�7�7�8�X��)�+U�V�V�k�k�W�V�k�"�X��)�+U�V�V�p�p�W�V�p��X�_�)�M�O�O�''�''�O�O�''�R0�0�0�"3�3�3�K�K�K�: H� H� H�DJ�J�J�<&�&�&�"2�"2�"2�H8�8�8�6O�O�O�"
?�
?�
?�'<�'<�'<�R%<�%<�%<�N�X�����,?�@�@�;�=�=�<�<�=�=�<� ����W��u�%�%�1�1�&�%�1��W��u�%�%�3�3�&�%�3�,�,�,�8�X�_�)�M�O�O�T�T�O�O�T�@�@�@�P�P�P�"&>�&>�&>�P,�,�,�,�,�,�0�0�0�%�%�%�

X�
X�
X�X�X�X�6(�(�(����&@�@�@�.�.�.�.�*!�W� �"�"�/�/�#�"�/�$&�&�&�&�&�&�'�'�'�?�?�?�A�A�A�.
B�
B�
B�
E�
E�
E�.�.�.�	1�	1�	1�	0�	0�	0�:�:�:�&�&�&�&�&rr#c�X�eZdZd�Zdd�Zej��d���Zd�Zd�Z	dS)�TestPendingCallsc����fd�}t|��D]G}tjtj��dz��	t�|��rn��HdS)Nc�2����d��dSrA)r�)�ls�r�callbackz6TestPendingCalls.pendingcalls_submit.<locals>.callback�s���
�H�H�T�N�N�N�N�Nrg{�G�z�?)rI�time�sleep�randomr�_pending_threadfunc)rr<�nr=r�s `   r�pendingcalls_submitz$TestPendingCalls.pendingcalls_submit�s~���	�	�	�	�	�
�q���	�	�A��J�v�}���t�+�,�,�,�
��0�0��:�:���
��	�	rNc� �d}t|��|krx	t	d��D]}||z}�|r|j���s�G|dz
}|�|dkd|t|��fz��t|��|k�xdS)NrFz(%i)rHrVi'z(timeout waiting for %i callbacks, got %i)r�r�verbose�printrI�event�is_setr()rr<rB�contextr�r�rs       r�pendingcalls_waitz"TestPendingCalls.pendingcalls_wait�s������!�f�f��k�k�
)��4�[�[�
�
���a�C����
�w�}�3�3�5�5�
���Q�J�E��O�O�E�E�M�:�A�s�1�v�v�;�F�
H�
H�
H��!�f�f��k�k�	$�	$rc�����d}g}Gd�dt��}|���g�_d�_|�jz�_d�_tj���_tj���_	��fd�t�j��D��}tj|��5��
�j|���ddd��dS#1swxYwYdS)N� c��eZdZdS)�8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooNrsrrrrrN�s�������rrrfrc�H��g|]}tj�j�f�����S))�targetrx)�	threading�Thread�pendingcalls_thread)�.0r�rIrs  ��r�
<listcomp>z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>�sE���5�5�5���#�4�+C�*1��5�5�5�5�5�5r)r�r<rB�nThreads�	nFinishedrQ�Lock�lock�EventrGrIr�
start_threadsrJ)rrB�threadsrrIs`   @r�test_pendingcalls_threadedz+TestPendingCalls.test_pendingcalls_threaded�s@����
���������&�����#�%�%����	���	���	�>������ �~�'�'���!��)�)��
�5�5�5�5�5�!�'�"2�3�3�5�5�5���
+�G�
4�
4�	:�	:��"�"�7�9�a��9�9�9�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:����	:�	:�	:�	:�	:�	:s�-C�C�Cc���	|�|j|j��|j5|xjdz
c_|j}	ddd��n#1swxYwY||jkr|j	�
��dSdS#|j5|xjdz
c_|j}	ddd��n#1swxYwY||jkr|j	�
��wwxYwr�)rCr<rBrYrWrrErFrVrGr�)rrIrWs   rrSz$TestPendingCalls.pendingcalls_thread�s���		$��$�$�W�Y��	�:�:�:���
;�
;��!�!�Q�&�!�!�#�-�	�;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;����
;�
;�
;�
;�
�G�,�,�,��
�!�!�#�#�#�#�#�-�,����
;�
;��!�!�Q�&�!�!�#�-�	�;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;����
;�
;�
;�
;�
�G�,�,�,��
�!�!�#�#�#�#�-���s@� B�A�A�A�C�	B.�"C�.B2�2C�5B2�6)Cc�f�g}d}|�||��|�||��dS)N�@)rCrJ)rr<rBs   r�test_pendingcalls_non_threadedz/TestPendingCalls.test_pendingcalls_non_threadeds@��

����� � ��A�&�&�&����q�!�$�$�$�$�$rrA)
rrrrCrJr�requires_working_threadingr]rSrarrrr9r9�s}������
�
�
�$�$�$�$�&1��0�2�2�:�:�3�2�:�(
$�
$�
$�%�%�%�%�%rr9c���eZdZejeed��d��d���Zejeed��d��d���Zd�Z	ej
edud��d���ZdS)	�SubinterpreterTest�pipezrequires os.pipe()c���ddl}tj��\}}d�|��}t	|d��5}tj|��}|�|d��|�tj
|��ttj
����|�tj
|��t|����ddd��dS#1swxYwYdS)Nrz�if 1:
            import sys, builtins, pickle
            with open({:d}, "wb") as f:
                pickle.dump(id(sys.modules), f)
                pickle.dump(id(builtins), f)
            �rb)�builtinsr�re�format�openr�run_in_subinterpr'�assertNotEqual�pickle�loadr!r7r�)rrh�r�wr��f�rets       r�test_subinterpsz"SubinterpreterTest.test_subinterpss�������w�y�y���1��
��q�	�	�	
��!�T�]�]�	>�a��*�4�0�0�C����S�!�$�$�$������A����3�;���@�@�@������A����8���=�=�=�		>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>����	>�	>�	>�	>�	>�	>s�BC,�,C0�3C0c�X�tj��\}}d�|��}t|d��5}t	j|��}|�|d��|�tj|��ddd���ddd��dS#1swxYwYdS)Naaif 1:
            import pickle
            with open({:d}, "wb") as f:

                @(lambda x:x)  # Py 3.9
                def noop(x): return x

                a = (b := f'1{{2}}3') + noop('x')  # Py 3.8 (:=) / 3.6 (f'')

                async def foo(arg): return await arg  # Py 3.5

                pickle.dump(dict(a=a, b=b), f)
            rgr�123xr�)rr)	r�rerirjrrkr'rmrn)rrorpr�rqrrs      r�(test_subinterps_recent_language_featuresz;SubinterpreterTest.test_subinterps_recent_language_features!s����w�y�y���1����q�	�	�	
��!�T�]�]�	H�a��*�4�0�0�C����S�!�$�$�$����V�[��^�^�6��-F�-F�G�G�G�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	Hs�AB�B#�&B#c��ddl}tjd��|�t	|jd����dS)z�
        Exceptions saved in global module state get shared between
        individual module instances. This test checks whether or not
        a change in one interpreter's module gets reflected into the
        other ones.
        rNz1import binascii; binascii.Error.foobar = 'foobar'�foobar)�binasciirrkrr��Error)rrys  r�test_mutate_exceptionz(SubinterpreterTest.test_mutate_exception7sE��	����� �!T�U�U�U��������:�:�;�;�;�;�;rN�$test requires _testmultiphase modulec���tj��\}}|�tj|��|�tj|��t	jd|�d���}t
|��tj|d��}tj	|��}|�
|d��tj|d��}|�
||��dS)z�
        bpo-44050: Extension module state should be shared between interpreters
        when it doesn't support sub-interpreters.
        a�
            import importlib.machinery
            import importlib.util
            import os

            fullname = '_test_module_state_shared'
            origin = importlib.util.find_spec('_testmultiphase').origin
            loader = importlib.machinery.ExtensionFileLoader(fullname, origin)
            spec = importlib.util.spec_from_loader(fullname, loader)
            module = importlib.util.module_from_spec(spec)
            attr_id = str(id(module.Error)).encode()

            os.write(z, attr_id)
            �drN)r�re�
addCleanup�closer�r�r��readrrkr')rrorp�script�main_attr_idrr�subinterp_attr_ids       r�"test_module_state_shared_in_globalz5SubinterpreterTest.test_module_state_shared_in_globalDs����w�y�y���1������!�$�$�$������!�$�$�$���
"��
"�
"�
"�
�
��	
�V�����w�q�#�����&�v�.�.������a� � � ��G�A�s�O�O������'8�9�9�9�9�9r)
rrrr4r5r�r�rsrvr{r6�_testmultiphaser�rrrrdrds��������X�����V�,�,�.B�C�C�
>�
>�D�C�
>��X�����V�,�,�.B�C�C�H�H�D�C�H�*<�<�<��X�_�_��,�.T�U�U�:�:�V�U�:�:�:rrdc��eZdZejej��d�����Zejej��d�����ZdS)�TestThreadStatec����fd�}|��tj|���}|���|���dS)Nc�����g��fd�}t�|��|x}}tjd������t
j����dd��dS)Nc�T����tj����dSrA)r�rQ�	get_ident)�identss�rr=zCTestThreadState.test_thread_state.<locals>.target.<locals>.callbackns$����
�
�i�1�3�3�4�4�4�4�4rrVrgz/Couldn't find main thread correctly in the list)r�_test_thread_stater>r?r'r�rQr�)r=rrr�rs   @�rrPz1TestThreadState.test_thread_state.<locals>.targetks������F�
5�
5�
5�
5�
5�
�(�(��2�2�2���A���J�q�M�M�M����V�\�\�)�*=�*?�*?�@�@�!�N�
P�
P�
P�
P�
Pr)rP)rQrR�start�join)rrP�ts`  r�test_thread_statez!TestThreadState.test_thread_stategs_���	P�	P�	P�	P�	P�	�������F�+�+�+��	���	�	�	�	�������rc��tjd��}tddd|��}|�d|j��dS)Nz�
            import _testcapi

            def callback():
                print('callback called')

            _testcapi._test_thread_state(callback)
            z-X�tracemallocr1scallback called)r�r�r
r�r>)rr�rrs   r� test_gilstate_ensure_no_deadlockz0TestThreadState.test_gilstate_ensure_no_deadlock}sL���� �����t�]�D�$�?�?���
�
�(�#�'�2�2�2�2�2rN)rrrr�reap_threadsrbr�r�rrrr�r�es~�������"�0��0�2�2���3�2�#�"��(�"�0��0�2�2�3�3�3�2�#�"�3�3�3rr�c��eZdZe���d�ee��D����eje	���d���Z
d�ZdS)�
Test_testcapic#�K�|]E}|�d���|�d���,|tt|��fV��FdS)�test_�_codeN)r<�endswithr.r�rTr�s  r�	<genexpr>zTest_testcapi.<genexpr>�st����P�P�����w�/�/�P�8<�
�
�g�8N�8N�P�T�7�9�d�3�3�4�P�P�P�P�P�Pr)�categoryc�8�t���dSrA)r�
test_widecharrs rr�zTest_testcapi.test_widechar�s�����!�!�!�!�!rc�Z�|�tjtj��dSrA)r'r�
Py_Versionr7�
hexversionrs r�test_version_api_dataz#Test_testcapi.test_version_api_data�s#������-�s�~�>�>�>�>�>rN)rrr�locals�update�dirrr�ignore_warnings�DeprecationWarningr�r�rrrr�r��s�������
�F�H�H�O�O�P�P� #��I���P�P�P�P�P�P�
%�_�$�.@�A�A�A�"�"�B�A�"�?�?�?�?�?rr�c�n�eZdZe���d�ee��D����dS)�Test_testinternalcapic#�nK�|]0}|�d���|tt|��fV��1dS)r�N)r<r.�_testinternalcapir�s  rr�zTest_testinternalcapi.<genexpr>�sW����1�1�����w�/�/�1�T�7�#4�d�;�;�<�1�1�1�1�1�1rN)rrrr�r�r�r�rrrr�r��sW������
�F�H�H�O�O�1�1� #��$5� 6� 6�1�1�1�1�1�1�1�1rr�c�X�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZdS)�PyMemDebugTests�debugz(?:0x)?[0-9a-fA-F]+c���tj��5td||jd���}ddd��n#1swxYwY|j}|�dd��S)Nr1�
junk:false��PYTHONMALLOC�MALLOC_CONF�asciir)rr4r	r�rr)rr�r>r3s    r�checkzPyMemDebugTests.check�s���
�
(�
*�
*�	�	�'��d�!�.�)����C�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�����}�}�W�i�0�0�0s
�9�=�=c���|�d��}d}|�|j���}tj|tj���}|�||��dS)Nz3import _testcapi; _testcapi.pymem_buffer_overflow()a6Debug memory block at address p={ptr}: API 'm'\n    16 bytes originally requested\n    The [0-9] pad bytes at p-[0-9] are FORBIDDENBYTE, as expected.\n    The [0-9] pad bytes at tail={ptr} are not all FORBIDDENBYTE \(0x[0-9a-f]{{2}}\):\n        at tail\+0: 0x78 \*\*\* OUCH\n        at tail\+1: 0xfd\n        at tail\+2: 0xfd\n        .*\n(    The block was made by call #[0-9]+ to debug malloc/realloc.\n)?    Data at p: cd cd cd .*\n\nEnable tracemalloc to get the memory block allocation traceback\n\nFatal Python error: _PyMem_DebugRawFree: bad trailing pad byte��ptr)�flags)r�ri�	PTR_REGEXr�r��DOTALLr��rr>�regexs   r�test_buffer_overflowz$PyMemDebugTests.test_buffer_overflow�se���j�j�N�O�O��
S��������0�0���
�5��	�2�2�2������e�$�$�$�$�$rc��|�d��}d}|�|j���}|�||��dS)Nz.import _testcapi; _testcapi.pymem_api_misuse()a�Debug memory block at address p={ptr}: API 'm'\n    16 bytes originally requested\n    The [0-9] pad bytes at p-[0-9] are FORBIDDENBYTE, as expected.\n    The [0-9] pad bytes at tail={ptr} are FORBIDDENBYTE, as expected.\n(    The block was made by call #[0-9]+ to debug malloc/realloc.\n)?    Data at p: cd cd cd .*\n\nEnable tracemalloc to get the memory block allocation traceback\n\nFatal Python error: _PyMem_DebugRawFree: bad ID: Allocated using API 'm', verified using API 'r'\nr�)r�rir�r�r�s   r�test_api_misusezPyMemDebugTests.test_api_misuse�sO���j�j�I�J�J��	w��������0�0������e�$�$�$�$�$rc�`�|�|��}d}|�||��dS)Nz^Fatal Python error: _PyMem_DebugMalloc: Python memory allocator called without holding the GIL)r�r�)rr�r>r�s    r�check_malloc_without_gilz(PyMemDebugTests.check_malloc_without_gil�s5���j�j�����M���
�
�h��$�$�$�$�$rc�4�d}|�|��dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()�r��rr�s  r�test_pymem_malloc_without_gilz-PyMemDebugTests.test_pymem_malloc_without_gil�s$��H���%�%�d�+�+�+�+�+rc�4�d}|�|��dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()r�r�s  r� test_pyobject_malloc_without_gilz0PyMemDebugTests.test_pyobject_malloc_without_gil�s$��K���%�%�d�+�+�+�+�+rc�f�tjd|�d���}td||jd���dS)Nz�
            import gc, os, sys, _testcapi
            # Disable the GC to avoid crash on GC collection
            gc.disable()
            try:
                _testcapi.z�()
                # Exit immediately to avoid a crash while deallocating
                # the invalid object
                os._exit(0)
            except _testcapi.error:
                os._exit(1)
        r1r�r�)r�r�r
r�)r�	func_namer�s   r�check_pyobject_is_freedz'PyMemDebugTests.check_pyobject_is_freed�s]���� �
%� � � �
�
��	��$��*�$�	
�	
�	
�	
�	
�	
rc�0�|�d��dS)N�check_pyobject_null_is_freed�r�rs r�test_pyobject_null_is_freedz+PyMemDebugTests.test_pyobject_null_is_freed�s���$�$�%C�D�D�D�D�Drc�0�|�d��dS)N�%check_pyobject_uninitialized_is_freedr�rs r�$test_pyobject_uninitialized_is_freedz4PyMemDebugTests.test_pyobject_uninitialized_is_freed�s���$�$�%L�M�M�M�M�Mrc�0�|�d��dS)N�'check_pyobject_forbidden_bytes_is_freedr�rs r�&test_pyobject_forbidden_bytes_is_freedz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freeds���$�$�%N�O�O�O�O�Orc�0�|�d��dS)N�check_pyobject_freed_is_freedr�rs r�test_pyobject_freed_is_freedz,PyMemDebugTests.test_pyobject_freed_is_freeds���$�$�%D�E�E�E�E�ErN)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r��s��������L�&�I�
1�
1�
1�%�%�%�(
%�
%�
%�%�%�%�,�,�,�,�,�,�
�
�
�&E�E�E�N�N�N�P�P�P�F�F�F�F�Frr�c��eZdZdZdS)�PyMemMallocDebugTests�malloc_debugN�rrrr�rrrr�r�s������!�L�L�Lrr�z
need pymallocc��eZdZdZdS)�PyMemPymallocDebugTests�pymalloc_debugNr�rrrr�r�s������#�L�L�Lrr�z
need Py_DEBUGc��eZdZdZdS)�PyMemDefaultTestsrNr�rrrr�r�s�������L�L�Lrr�r|c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�Test_ModuleStateAccessz%Test access to module start (PEP 573)c�H�d}tj�d��j}tj�||��}tj�||��}tj�|��}|�|��||_	dS)N�!_testmultiphase_meth_state_accessr�)
�	importlib�util�	find_spec�origin�	machinery�ExtensionFileLoader�spec_from_loader�module_from_spec�exec_moduler)r�fullnamer��loader�specrs      r�setUpzTest_ModuleStateAccess.setUps���6����)�)�*;�<�<�C���$�8�8��6�J�J���~�.�.�x��@�@����0�0��6�6�����6�"�"�"�����rc��Gd�d|jj��}|��}|�|���|j��dS)z#PyType_GetModule for defining_classc��eZdZdS)�QTest_ModuleStateAccess.test_subclass_get_module.<locals>.StateAccessType_SubclassNrsrrr�StateAccessType_Subclassr�*rurr�N�r�StateAccessTyper#�get_defining_module�rr��instances   r�test_subclass_get_modulez/Test_ModuleStateAccess.test_subclass_get_module(si��	�	�	�	�	�t�{�'B�	�	�	�,�+�-�-���
�
�h�2�2�4�4�d�k�B�B�B�B�Brc��Gd�d|jj��}|��}|�|���|j��dS)Nc���eZdZ�fd�Z�xZS)�\Test_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclassc�D��t�����SrA)r�r�r�s �rr�zpTest_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclass.get_defining_module2s����w�w�2�2�4�4�4r)rrrr�r�r�s@rr�r1s8�������
5�
5�
5�
5�
5�
5�
5�
5�
5rr�r�r�s   r�#test_subclass_get_module_with_superz:Test_ModuleStateAccess.test_subclass_get_module_with_super0si��	5�	5�	5�	5�	5�t�{�'B�	5�	5�	5�,�+�-�-���
�
�h�2�2�4�4�d�k�B�B�B�B�Brc�h�|j���}|j���}|j|jd�}|���D�]Z\}}|�|��5|�|���|�����|�|���d��|��|�|���|�����|�|���d��|d��|�|���|�����|�|���d��|dd���|�|���|�����|�|���d��|�t��5|d�	��d
d
d
��n#1swxYwY|�t��5|ddd��d
d
d
��n#1swxYwYd
d
d
��n#1swxYwY��\d
S)z�Checks methods defined with and without argument clinic

        This tests a no-arg method (get_count) and a method with
        both a positional and keyword argument.
        )�clinic�noclinicrrVrgr%���T)�twice)�thriceNrf)
rr��increment_count_clinic�increment_count_noclinicr�r�r'�	get_countr*rH)rrr�methodsr��increment_counts      r�test_state_accessz(Test_ModuleStateAccess.test_state_access8s��
�K�'�'�)�)���K�'�'�)�)���.��2�
�
��
&-�]�]�_�_�	-�	-�!�D�/����d�#�#�
-�
-�� � ���������
�
�>�>�>�� � �������2�2�2���!�!�!�� � ���������
�
�>�>�>�� � �������2�2�2����"�"�"�� � ���������
�
�>�>�>�� � �������2�2�2����$�/�/�/�/�� � ���������
�
�>�>�>�� � �������2�2�2��&�&�y�1�1�.�.�#�O�1�-�-�-�-�.�.�.�.�.�.�.�.�.�.�.����.�.�.�.��&�&�y�1�1�-�-�#�O�A�q�!�,�,�,�-�-�-�-�-�-�-�-�-�-�-����-�-�-�-�'
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-��	-�	-s[�1GJ%�6
I�J%�I�J%�I�J%�4J�J%�J�J%�J�J%�%J)	�,J)	c���|j���}|�t��5|���ddd��dS#1swxYwYdSrA)rr�r*rH�getmodulebydef_bad_def)rr�s  r�test_get_module_bad_defz.Test_ModuleStateAccess.test_get_module_bad_def^s����;�.�.�0�0��
�
�
�y�
)�
)�	.�	.��+�+�-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	.�	.s�A�A�Ac��Gd�dt|jj��}|�|�����|j��dS)Nc��eZdZdS)�FTest_ModuleStateAccess.test_get_module_static_in_mro.<locals>.SubclassNrsrrr�Subclassrjrurr)�
BaseExceptionrr�r#r�)rrs  r�test_get_module_static_in_mroz4Test_ModuleStateAccess.test_get_module_static_in_mrofsa��	�	�	�	�	�}�d�k�&A�	�	�	��
�
�h�h�j�j�4�4�6�6���D�D�D�D�DrN)
rrrr)r�r�rrrrrrrr�r�s�������/�/����C�C�C�C�C�C�$-�$-�$-�L.�.�.�E�E�E�E�Err�c�,�eZdZd�Zd�Zd�Zd�Zd�ZdS)�
Test_FrameAPIc�(�tj��SrA�r7�	_getframers r�getframezTest_FrameAPI.getframeqs���}���rc#�4K�tj��V�dSrArrs r�getgenframezTest_FrameAPI.getgenframets�����m�o�o�����rc���|���}|�|jt�|����|�|jt�|����|�|jt�	|����|�|j
t�|����dSrA)rr'�f_localsr�frame_getlocalsr#�	f_globals�frame_getglobals�
f_builtins�frame_getbuiltins�f_lasti�frame_getlasti)r�frames  r�test_frame_gettersz Test_FrameAPI.test_frame_gettersws����
�
����������)B�)B�5�)I�)I�J�J�J��
�
�e�o�y�'A�'A�%�'H�'H�I�I�I��
�
�e�&�	�(C�(C�E�(J�(J�K�K�K������	�(@�(@��(G�(G�H�H�H�H�Hrc��|���}t|��}|�|t�|����dSrA)r!�nextr#r�frame_getgenerator)r�genr+s   r�test_frame_get_generatorz&Test_FrameAPI.test_frame_get_generator~sF����� � ���S�	�	���
�
�c�9�7�7��>�>�?�?�?�?�?rc��d�}t�|jt��t	����}|�|j��dS)zzTest that accessing `f_back` does not cause a segmentation fault on
        a frame created with `PyFrame_New` (GH-99110).c��dSrArrrr�dummyz1Test_FrameAPI.test_frame_fback_api.<locals>.dummy�r
rN)r�	frame_newr�globalsr��assertIsNone�f_back)rr4r+s   r�test_frame_fback_apiz"Test_FrameAPI.test_frame_fback_api�sP��	�	�	��#�#�E�N�G�I�I�v�x�x�H�H�����%�,�'�'�'�'�'rN)rrrrr!r,r1r9rrrrrose������������I�I�I�@�@�@�
(�(�(�(�(rrr~c� �eZdZd�Zd�Zd�ZdS)�Test_Pep523APIc���g}t}|tz}	t|��D]&}||krtj|��|���'	tj��n#tj��wxYw|tz}|�t
|��t
|����t||d���D]\}}	|�||	���dS)NT)�strict)�"SUFFICIENT_TO_DEOPT_AND_SPECIALIZErIr��set_eval_frame_record�set_eval_frame_defaultr'r��zip)
r�funcr��actual_callsr�r�r��expected_callsr��actuals
          r�do_testzTest_Pep523API.do_test�s�����2���:�:��	7��5�\�\�
�
����:�:�%�;�L�I�I�I�������
�

�4�6�6�6�6���4�6�6�6�6�����!C�C������^�,�,�c�,�.?�.?�@�@�@� #�N�L�� N� N� N�	/�	/��H�f����X�v�.�.�.�.�	/�	/s�6A � A5c�`��Gd�d����fd�}ddg}|�||��dS)Nc��eZdZd�ZdS)�4Test_Pep523API.test_inlined_binary_subscr.<locals>.Cc��dSrAr)r�others  rr�z@Test_Pep523API.test_inlined_binary_subscr.<locals>.C.__getitem__�r�rN)rrrr�rrr�CrI�s#������
�
�
�
�
rrLc�(�����ddS�Nrdr)rLs�rrBz7Test_Pep523API.test_inlined_binary_subscr.<locals>.func�s���
�A�C�C��G�G�G�GrrBr��rF)rrBr�rLs   @r�test_inlined_binary_subscrz)Test_Pep523API.test_inlined_binary_subscr�sh���	�	�	�	�	�	�	�	�	�	�	�	�	���'�����T�5�!�!�!�!�!rc�N��dd���fd�}gd�}|�||��dS)Nrdc��dSrAr)�xs r�innerz/Test_Pep523API.test_inlined_call.<locals>.inner�r
rc�2������d��dSrNr)rTs�rrBz.Test_Pep523API.test_inlined_call.<locals>.func�s����E�G�G�G��E�"�I�I�I�I�Ir)rBrTrTrerO)rrBr�rTs   @r�test_inlined_callz Test_Pep523API.test_inlined_call�sW���	�	�	�	�	�	�	�	�	�+�*�*�����T�5�!�!�!�!�!rN)rrrrFrPrVrrrr;r;�sA������/�/�/� "�"�"�"�"�"�"�"rr;�__main__)=�collectionsrr�r,�importlib.machineryr��importlib.utilr�rmr@r�r5r7r�rQr>r4r�r%r�test.supportrrrr�test.support.script_helperr	r
r��ImportErrorr�r�rr�r�r�r+rrr�TestCaser#r9rdr�r�r�r3r�r�r5�
with_pymallocr�r�r6r�rr>r;r�mainrrr�<module>ras@��$�#�#�#�#�#�����������������	�	�	�	�
�
�
�
�
�
�
�
�	�	�	�	�����
�
�
�
���������������������������-�-�-�-�-�-�&�&�&�&�&�&�)�)�)�)�)�)�(�(�(�(�(�(�N�N�N�N�N�N�N�N��������������������������������O�O�O�����
(�M�'��4�4�	������7�3�*�+�+����<�<�<����
:�:�:�:�:�:�:�:�@&�@&�@&�@&�@&�x� �@&�@&�@&�HM%�M%�M%�M%�M%�x�(�M%�M%�M%�`S:�S:�S:�S:�S:��*�S:�S:�S:�l%3�%3�%3�%3�%3�h�'�%3�%3�%3�P?�?�?�?�?�H�%�?�?�?�1�1�1�1�1�H�-�1�1�1������cF�cF�cF�cF�cF�h�'�cF�cF���cF�L"�"�"�"�"�O�"�"�"����*�W�*�,�,�o�>�>�$�$�$�$�$�o�$�$�?�>�$����X��/�/���������0�/��
����D�(�*P�Q�Q�TE�TE�TE�TE�TE�X�.�TE�TE�R�Q�TE�n(�(�(�(�(�H�%�(�(�(�>&)�"�""�""�""�""�""�X�&�""�""�""�J�z����H�M�O�O�O�O�O��s$�*A/�/A9�8A9�=B�B�B