Your IP : 216.73.216.85


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_capi.cpython-39.opt-2.pyc

a

XC?h���@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlZddlmZddlmZddlmZmZzddlZWney�dZYn0e�d�ZddlZeed�Zdd	�ZGd
d�d�ZGdd
�d
ej �Z!Gdd�dej �Z"Gdd�dej �Z#Gdd�dej �Z$Gdd�dej �Z%Gdd�dej �Z&Gdd�dej �Z'Gdd�de'�Z(e�)e�*�d�Gdd�de'��Z+e�)ed�Gd d!�d!e'��Z,Gd"d#�d#ej �Z-e.d$k�r�e�/�dS)%�)�OrderedDictN)�support)�MISSING_C_DOCSTRINGS)�assert_python_failure�assert_python_ok�	_testcapiZgettotalrefcountcCs|S�N���selfr	r	�3/opt/alt/python39/lib64/python3.9/test/test_capi.py�testfunction#sr
c@s eZdZe�e�Ze�e�ZdS)�InstanceMethodN)�__name__�
__module__�__qualname__rZinstancemethod�idr
r	r	r	rr(s
rc@sfeZdZdd�Zdd�Zdd�Zdd�Ze�e	d	�d
d��Z
e�e	d	�dd
��Ze�e
d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Ze�eed!�d"�d#d$��Zd%d&�Ze�d'�d(d)��Ze�d'�d*d+��Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"d4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d<d=�Z'd>d?�Z(d@dA�Z)dBdC�Z*dDdE�Z+dFdG�Z,dHdI�Z-dJS)K�CAPITestcCs~t�}|�t|�|���|�|��|u�|�|jjtj�|�tjjtj�dtj_|�tjd�|�tt	|jdd�dS)N�test�	attribute)
r�assertEqualr�
assertTruer
�__doc__r�assertRaises�AttributeError�setattr�r�instr	r	r�test_instancemethod.szCAPITest.test_instancemethodcCsvt���,tjtjddgtjtjd�}Wd�n1s:0Y|��\}}|�|d�|�	|�
��d�|�dS)N�-cz4import _testcapi;_testcapi.crash_no_current_thread())�stdout�stderr�s�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�PIPEZcommunicaterr�rstrip�
startswith)r�p�out�errr	r	r� test_no_FatalError_infinite_loop9s

��$��z)CAPITest.test_no_FatalError_infinite_loopcCs|�ttj�dSr)r�
ValueErrorrZ!make_memoryview_from_NULL_pointerr
r	r	r�!test_memoryview_from_NULL_pointerKsz*CAPITest.test_memoryview_from_NULL_pointerc

Cs�td�}td�}z|�Wn�ty�}z�|j}t��}t�|j|d�}t��}tj|�}t��}	|�|d|�|�	||j||f�|�	||�|�	|	|�|�	||j|df�|�	||�WYd}~nd}~00|�
d�dS)N�5ZTEST�F)r/�	TypeError�
__traceback__r&�exc_inforZset_exc_info�	__class__rZassertSequenceEqualr)
rZraised_exception�new_exc�e�tbZorig_sys_exc_infoZ
orig_exc_infoZnew_sys_exc_infoZnew_exc_infoZreset_sys_exc_infor	r	r�
test_exc_infoNs$
"zCAPITest.test_exc_infoz(_posixsubprocess required for this test.cCs�Gdd�dt�}|�ttjd|�dddddd	d
ddd
ddddddddd�Gdd�dt�}|�ttjd|�dddddd	d
ddd
ddddddddd�dS)Nc@seZdZdd�ZdS)�1CAPITest.test_seq_bytes_to_charp_array.<locals>.ZcSsdS�Nr2r	r
r	r	r�__len__is�9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__N�rrrr=r	r	r	r�Zhsr@r2��r2������	�
���
��������c@seZdZdd�Zdd�ZdS)r;cSstjSr)r&�maxsizer
r	r	rr=osr>cSsdS)N�xr	)r�ir	r	r�__getitem__qsz=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__N)rrrr=rXr	r	r	rr@ns)�objectrr3�_posixsubprocess�	fork_exec�MemoryError�rr@r	r	r�test_seq_bytes_to_charp_arrayes
,�
,�z&CAPITest.test_seq_bytes_to_charp_arraycCsPGdd�dt�}|�ttj|�dgdddddd	d
ddd
ddddddddd�dS)Nc@seZdZdd�ZdS)z-CAPITest.test_subprocess_fork_exec.<locals>.ZcSsdSr<r	r
r	r	rr=ysz5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__Nr?r	r	r	rr@xsr@�1rArBrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrT)rYrr3rZr[r]r	r	r�test_subprocess_fork_execvs
.�z"CAPITest.test_subprocess_fork_execz6Signature information for builtins requires docstringscCs|�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))rrZno_docstringr�__text_signature__Zdocstring_emptyZdocstring_no_signatureZ docstring_with_invalid_signatureZ!docstring_with_invalid_signature2Zdocstring_with_signatureZ#docstring_with_signature_but_no_docZ+docstring_with_signature_and_extra_newlinesr
r	r	r� test_docstring_signature_parsing�s<
�
�
�
�
�
�
�z)CAPITest.test_docstring_signature_parsingcCs�tj}|�}|�}|�||d||f�|�|dd|df�|�d|dd|f�|}||}|�|d||f�|}|d}|�|d|df�d}||}|�|dd|f�dS)N�matmul�*�imatmul)rZ
matmulTyper)r�MZm1Zm2�or	r	r�&test_c_type_with_matrix_multiplication�sz/CAPITest.test_c_type_with_matrix_multiplicationcCs2t��}|�|�d�d�|�|�dd�d�dS)Nr2)r2NrC)rCrC)rZipowTyper�__ipow__)rrgr	r	r�test_c_type_with_ipow�szCAPITest.test_c_type_with_ipowcCs|tr4t�d�}td|�\}}}|�|�dd�d�nD|�t��}t�	�Wd�n1s\0Y|�t
|j�d�dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r�
r"sFatal Python error: _Py_CheckFunctionResult: a function returned NULL without setting an error\nPython runtime state: initialized\nSystemError: <built-in function return_null_without_error> returned NULL without setting an error\n\nCurrent thread.*:\n  File .*", line 6 in <module>zBreturn_null_without_error.* returned NULL without setting an error)�Py_DEBUG�textwrap�dedentr�assertRegex�replacer�SystemErrorrZreturn_null_without_error�str�	exception�r�code�rcr,r-�cmr	r	r�test_return_null_without_error�s
�&�z'CAPITest.test_return_null_without_errorcCs|tr4t�d�}td|�\}}}|�|�dd�d�nD|�t��}t�	�Wd�n1s\0Y|�t
|j�d�dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            rrkr"sgFatal Python error: _Py_CheckFunctionResult: a function returned a result with an error 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 error set\n\nCurrent thread.*:\n  File .*, line 6 in <module>z>return_result_with_error.* returned a result with an error set)rlrmrnrrorprrqrZreturn_result_with_errorrrrsrtr	r	r�test_return_result_with_error�s
�&�z&CAPITest.test_return_result_with_errorcCst��dSr)r�test_buildvalue_Nr
r	r	rrzszCAPITest.test_buildvalue_NcCs<d}td|�\}}}|�d|�|�d|�|�d|�dS)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
        rsMemoryError 1 10sMemoryError 2 20sMemoryError 3 30)r�assertIn�rrurvr,r-r	r	r�test_set_nomemorys
zCAPITest.test_set_nomemoryc	Cs�Gdd�dt�}Gdd�dt�}dddd�}it�|�|�|t|�||�||�fD]R}|�t�|�t|����|�t�|�t|����|�t�	|�t|�
���qRdS)	Ncs4eZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)z9CAPITest.test_mapping_keys_values_items.<locals>.Mapping1cstt����Sr)�list�super�keysr
�r6r	rr�(sz>CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.keyscstt����Sr)r~r�valuesr
r�r	rr�*sz@CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.valuescstt����Sr)r~r�itemsr
r�r	rr�,sz?CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.items�rrrr�r�r��
__classcell__r	r	r�r�Mapping1'sr�cs4eZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)z9CAPITest.test_mapping_keys_values_items.<locals>.Mapping2cstt����Sr)�tuplerr�r
r�r	rr�/sz>CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.keyscstt����Sr)r�rr�r
r�r	rr�1sz@CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.valuescstt����Sr)r�rr�r
r�r	rr�3sz?CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.itemsr�r	r	r�r�Mapping2.sr�r2rCrA)�fooZbarZspam)�dictrZassertListEqualr�get_mapping_keysr~r��get_mapping_valuesr��get_mapping_itemsr�)rr�r�Zdict_obj�mappingr	r	r�test_mapping_keys_values_items&s �
�
�
�z'CAPITest.test_mapping_keys_values_itemscCsx|�ttjd�|�ttjd�|�ttjd�Gdd�d�}|�}|�ttj|�|�ttj|�|�ttj|�dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)zCCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMappingcSsdSrr	r
r	r	rr�GszHCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.keyscSsdSrr	r
r	r	rr�IszJCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.valuescSsdSrr	r
r	r	rr�KszICAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.itemsN)rrrr�r�r�r	r	r	r�
BadMappingFsr�)rrrr�r�r�r3)rr�Zbad_mappingr	r	r�&test_mapping_keys_values_items_bad_argAsz/CAPITest.test_mapping_keys_values_items_bad_argZnegative_refcountz need _testcapi.negative_refcountcCs*t�d�}td|�\}}}|�|d�dS)Nz�
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        rs`_testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)rmrnrror|r	r	r�test_negative_refcountRs

�zCAPITest.test_negative_refcountcCs,ddlm}d}td�D]}||f�}qdS)Nr��MyList��)rr��range)rr��LrWr	r	r�test_trashcan_subclassdszCAPITest.test_trashcan_subclassZcpucCs|�t�dSr)�do_test_trashcan_python_classr~r
r	r	r�test_trashcan_python_class1lsz$CAPITest.test_trashcan_python_class1cCsddlm}|�|�dS)Nrr�)rr�r�)rr�r	r	r�test_trashcan_python_class2psz$CAPITest.test_trashcan_python_class2cCshGdd�d|�}dD]N}d}td�D]}||f�}||_q$|rD|f}|�|jd�~|�|jd�qdS)Ncs,eZdZdZ�fdd�Z�fdd�Z�ZS)z6CAPITest.do_test_trashcan_python_class.<locals>.PyListrcs�jd7_t�j|�dSr<)�numr�__init__)r�argsr�r	rr�}sz?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__cs�jd8_dSr<)r�r
r�r	r�__del__�sz>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__)rrrr�r�r�r�r	r	r�r�PyListysr�)rr2ir)r��attrZ
assertGreaterr�r)r�baser�Zparityr�rWr	r	rr�us

z&CAPITest.do_test_trashcan_python_classcCsZGdd�dtj�}|�}t�|�}|�|jd�|�|jd�~|�|dt�|��dS)NcseZdZ�fdd�Z�ZS)z`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclasscsd|_t���dS�NrS��value2rr�r
r�r	rr��sziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__�rrrr�r�r	r	r�r�HeapGcCTypeSubclass�sr�rIrSr2)r�HeapGcCTyper&�getrefcountr�valuer�)rr��subclass_instance�type_refcntr	r	r�:test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once�s
zCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncecs�Gdd�dtj��G��fdd�d�����}t���}t���}|�|jd�|�|jd�~|�|d�j�|�|d�j�|�|dt����|�|t����dS)NcseZdZ�fdd�Z�ZS)zdCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Acsd|_t���dSr�r�r
r�r	rr��szmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__r�r	r	r�r�A�sr�cs*eZdZ�fdd�Z��fdd�Z�ZS)zdCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bcst���dSr)rr�r
r�r	rr��szmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__cs"�|_t����_t����_dSr)r6r&r��
refcnt_in_delr
�r��Br	rr��szlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__)rrrr�r�r�r	r�r�rr��sr�rIrSr2)rr�r&r�rr�r�r��rr�r�Znew_type_refcntr	r�r�Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once�s	

zYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncecCsXt��}d|_|�|jd�|�|j|j�|�|jddi�t��}|�i|j�dS�Nrdr�)rZHeapCTypeWithDictr�r�dictobj�__dict__rr	r	r�test_heaptype_with_dict�sz CAPITest.test_heaptype_with_dictcCsXt��}d|_|�|jd�|�|j|j�|�|jddi�t��}|�i|j�dSr�)rZHeapCTypeWithNegativeDictr�rr�r�rr	r	r� test_heaptype_with_negative_dict�sz)CAPITest.test_heaptype_with_negative_dictcCs2t��}t�|�}|�|�|�|�|j|�dSr)rZHeapCTypeWithWeakref�weakref�refrZweakreflist)rrr�r	r	r�test_heaptype_with_weakref�s
z#CAPITest.test_heaptype_with_weakrefcCs t��}t|�}|�|d�dS)Ns1234)rZHeapCTypeWithBuffer�bytesr)rr�br	r	r�test_heaptype_with_buffer�sz"CAPITest.test_heaptype_with_buffercCsNt��}t�tj�}|�|jd�|�|jd�~|�|dt�tj��dS�NrIrSr2)r�HeapCTypeSubclassr&r�rr�r�)rr�r�r	r	r�9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once�szBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncecCs�t��}t�tj�}t�tj�}|�|jd�|�|jd�~|�|dtjj�|�|dtjj�|�|dt�tj��|�|t�tj��dSr�)	rZHeapCTypeSubclassWithFinalizerr&r�r�rr�r�r�r�r	r	r�Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_once�szXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncecCs@t��}|�|jd�d|_|�|jd�|`|�|jd�dS)NrIrKr)rZHeapCTypeSetattrrZpvaluer�)r�objr	r	r�test_heaptype_with_setattrosz$CAPITest.test_heaptype_with_setattrocCs�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�{rCZ	0b1111011rGZ0o173rI�123rOZ0x7bi����z
-0b1111011z-0o173z-123z-0x7bg�^@)rr�rrr3rq)rr�r	r	r�test_pynumber_tobaseszCAPITest.test_pynumber_tobasecCst��}|�|d�dS�Nz<NULL>)rZpyobject_repr_from_nullr�r�sr	r	r�test_pyobject_repr_from_nullsz%CAPITest.test_pyobject_repr_from_nullcCst��}|�|d�dSr�)rZpyobject_str_from_nullrr�r	r	r�test_pyobject_str_from_null sz$CAPITest.test_pyobject_str_from_nullcCst��}|�|d�dS)Ns<NULL>)rZpyobject_bytes_from_nullrr�r	r	r�test_pyobject_bytes_from_null$sz&CAPITest.test_pyobject_bytes_from_nullcCs2tj}d}||�}t|dd�}|�|j|j�dS)Ns%# -*- coding: latin1 -*-
print('¤')
z<string>�exec)rZPy_CompileString�compiler�	co_consts)r�_compileru�result�expectedr	r	r�test_Py_CompileString(s
zCAPITest.test_Py_CompileStringN).rrrrr.r0r:�unittest�
skipUnlessrZr^r`ZskipIfrrbrhrjrxryrzr}r�r��hasattrrr�r�rZrequires_resourcer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	r	r	rr,sX



	�
)" �


#

rc@s6eZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)
�TestPendingCallscs>�fdd�}t|�D]$}t�t��d�t�|�r*qq*qdS)Ncs��d�dSr)�appendr	��lr	r�callback4sz6TestPendingCalls.pendingcalls_submit.<locals>.callbackg{�G�z�?)r��time�sleep�randomrZ_pending_threadfunc)rr��nr�rWr	r�r�pendingcalls_submit3s

z$TestPendingCalls.pendingcalls_submitNcCs�d}t|�|krxdr,tjr,tdt|�f�td�D]}||}q4|rR|j��sRq|d7}|�|dkd|t|�f�qdr�tjr�tdt|�f�dS)NrFz(%i)r�r2i'z(timeout waiting for %i callbacks, got %i)�lenr�verbose�printr��eventZis_setr)rr�r��context�countrW�ar	r	r�pendingcalls_waitBs


�
z"TestPendingCalls.pendingcalls_waitcs�d}g}Gdd�dt�}|��g�_d�_|�j�_d�_t���_t���_	��fdd�t
�j�D�}t�|�� ��
�j|��Wd�n1s�0YdS)N� c@seZdZdS)z8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooN�rrrr	r	r	rr�Zr"r�rCrcsg|]}tj�j�fd��qS))�targetr�)�	threading�Thread�pendingcalls_thread)�.0rW�r�rr	r�
<listcomp>cs��z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>)rYr�r��nThreads�	nFinishedr�ZLock�lockZEventr�r�rZ
start_threadsr�)rr�Zthreadsr�r	r�r�test_pendingcalls_threadedUs

�z+TestPendingCalls.test_pendingcalls_threadedcCs�zv|�|j|j�W|j�8|jd7_|j}drDtjrDtd|�Wd�n1sX0Y||jkr�|j	�
�nd|j�8|jd7_|j}dr�tjr�td|�Wd�n1s�0Y||jkr�|j	�
�0dS)Nr2Fzfinished threads: )r�r�r�r�r�rr�r�r�r��set)rr�r�r	r	rr�is 
(
�
(
z$TestPendingCalls.pendingcalls_threadcCs$g}d}|�||�|�||�dS)N�@)r�r�)rr�r�r	r	r�test_pendingcalls_non_threadedusz/TestPendingCalls.test_pendingcalls_non_threaded)N)rrrr�r�r�r�r�r	r	r	rr�1s

r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�SubinterpreterTestcCs�ddl}t��\}}d�|�}t|d��T}t�|�}|�|d�|�t	�
|�ttj
��|�t	�
|�t|��Wd�n1s�0YdS)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)�builtins�os�pipe�format�openr�run_in_subinterprZassertNotEqual�pickle�loadrr&�modules)rr��r�wru�f�retr	r	r�test_subinterps�s�
z"SubinterpreterTest.test_subinterpscCsrt��\}}d�|�}t|d��>}t�|�}|�|d�|�t�|�ddd��Wd�n1sd0YdS)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)
            r�rZ123xr�)r�r�)	r�r�rrrrrrr)rrrrurr	r	r	r�(test_subinterps_recent_language_features�s�
z;SubinterpreterTest.test_subinterps_recent_language_featurescCs(ddl}t�d�|�t|jd��dS)Nrz1import binascii; binascii.Error.foobar = 'foobar'Zfoobar)�binasciirrZassertFalser��Error)rrr	r	r�test_mutate_exception�s
z(SubinterpreterTest.test_mutate_exceptioncCs�t��\}}|�tj|�|�tj|�t�d|�d��}t|�t�|d�}t�	|�}|�
|d�t�|d�}|�
||�dS)Na�
            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)
            �dr)r�r�Z
addCleanup�closermrnr��readrrr)rrrZscriptZmain_attr_idr	Zsubinterp_attr_idr	r	r�"test_module_state_shared_in_global�s�

z5SubinterpreterTest.test_module_state_shared_in_globalN)rrrr
rrrr	r	r	rr��s
r�c@seZdZejdd��ZdS)�TestThreadStatecs2�fdd�}|�tj|d�}|��|��dS)NcsHg��fdd�}t�|�|}}t�d�����t���dd�dS)Ncs��t���dSr)r�r��	get_identr	�Zidentsr	rr��szCTestThreadState.test_thread_state.<locals>.target.<locals>.callbackr2rAz/Couldn't find main thread correctly in the list)rZ_test_thread_stater�r�rr�r�r)r�r�r�r
rrr��s

�z1TestThreadState.test_thread_state.<locals>.target)r�)r�r��start�join)rr��tr	r
r�test_thread_state�s

z!TestThreadState.test_thread_stateN)rrrrZreap_threadsrr	r	r	rr�src@s&eZdZe��dd�ee�D��dS)�
Test_testcapiccs0|](}|�d�r|�d�s|tt|�fVqdS)�test_�_codeN)r*�endswith�getattrr�r��namer	r	r�	<genexpr>�s�zTest_testcapi.<genexpr>N)rrr�locals�update�dirrr	r	r	rr�s�rc@s&eZdZe��dd�ee�D��dS)�Test_testinternalcapiccs&|]}|�d�r|tt|�fVqdS)rN)r*r�_testinternalcapirr	r	rr!�s
�zTest_testinternalcapi.<genexpr>N)rrrr"r#r$r&r	r	r	rr%�s�r%c@sleZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�PyMemDebugTests�debugz(?:0x)?[0-9a-fA-F]+cCsLt���"td||jdd�}Wd�n1s00Y|j}|�dd�S)Nr�
junk:false��PYTHONMALLOCZMALLOC_CONF�asciirp)rr#rr+r-�decode)rrur,r!r	r	r�check�s
�$zPyMemDebugTests.checkcCs<|�d�}d}|j|jd�}tj|tjd�}|�||�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�Zptr)�flags)r.r�	PTR_REGEX�rer��DOTALLro�rr,Zregexr	r	r�test_buffer_overflows

z$PyMemDebugTests.test_buffer_overflowcCs,|�d�}d}|j|jd�}|�||�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.rr1ror4r	r	r�test_api_misuses

zPyMemDebugTests.test_api_misusecCs|�|�}d}|�||�dS)Nz^Fatal Python error: _PyMem_DebugMalloc: Python memory allocator called without holding the GIL)r.r{)rrur,r�r	r	r�check_malloc_without_gil+s
z(PyMemDebugTests.check_malloc_without_gilcCsd}|�|�dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()�r7�rrur	r	r�test_pymem_malloc_without_gil1sz-PyMemDebugTests.test_pymem_malloc_without_gilcCsd}|�|�dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()r8r9r	r	r� test_pyobject_malloc_without_gil7sz0PyMemDebugTests.test_pyobject_malloc_without_gilcCs(t�d|�d��}td||jdd�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)
        rr)r*)rmrnrr+)rZ	func_namerur	r	r�check_pyobject_is_freed=s�
�z'PyMemDebugTests.check_pyobject_is_freedcCs|�d�dS)NZcheck_pyobject_null_is_freed�r<r
r	r	r�test_pyobject_null_is_freedPsz+PyMemDebugTests.test_pyobject_null_is_freedcCs|�d�dS)NZ%check_pyobject_uninitialized_is_freedr=r
r	r	r�$test_pyobject_uninitialized_is_freedSsz4PyMemDebugTests.test_pyobject_uninitialized_is_freedcCs|�d�dS)NZ'check_pyobject_forbidden_bytes_is_freedr=r
r	r	r�&test_pyobject_forbidden_bytes_is_freedVsz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freedcCs|�d�dS)NZcheck_pyobject_freed_is_freedr=r
r	r	r�test_pyobject_freed_is_freedYsz,PyMemDebugTests.test_pyobject_freed_is_freedN)rrrr+r1r.r5r6r7r:r;r<r>r?r@rAr	r	r	rr'�sr'c@seZdZdZdS)�PyMemMallocDebugTestsZmalloc_debugN�rrrr+r	r	r	rrB]srBz
need pymallocc@seZdZdZdS)�PyMemPymallocDebugTestsZpymalloc_debugNrCr	r	r	rrDasrDz
need Py_DEBUGc@seZdZdZdS)�PyMemDefaultTests�NrCr	r	r	rrEfsrEc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�Test_ModuleStateAccesscCsNd}tj�d�j}tj�||�}tj�||�}tj�|�}|�|�||_	dS)NZ!_testmultiphase_meth_state_accessZ_testmultiphase)
�	importlib�util�	find_spec�origin�	machinery�ExtensionFileLoader�spec_from_loader�module_from_spec�exec_module�module)r�fullnamerK�loader�specrQr	r	r�setUpss
zTest_ModuleStateAccess.setUpcCs0Gdd�d|jj�}|�}|�|��|j�dS)Nc@seZdZdS)zQTest_ModuleStateAccess.test_subclass_get_module.<locals>.StateAccessType_SubclassNr�r	r	r	r�StateAccessType_Subclass~srV�rQ�StateAccessTypeZassertIs�get_defining_module�rrV�instancer	r	r�test_subclass_get_module|sz/Test_ModuleStateAccess.test_subclass_get_modulecCs0Gdd�d|jj�}|�}|�|��|j�dS)NcseZdZ�fdd�Z�ZS)z\Test_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclasscs
t���Sr)rrYr
r�r	rrY�szpTest_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclass.get_defining_module)rrrrYr�r	r	r�rrV�srVrWrZr	r	r�#test_subclass_get_module_with_super�sz:Test_ModuleStateAccess.test_subclass_get_module_with_superc
Cs�|j��}|j��}|j|jd�}|��D�]N\}}|�|���(|�|��|���|�|��d�|�|�|��|���|�|��d�|d�|�|��|���|�|��d�|ddd�|�|��|���|�|��d�|�t	��|dd	�Wd�n1�s0Y|�t	��|dd
d�Wd�n1�sP0YWd�q*1�sp0Yq*dS)N)ZclinicZnoclinicrr2rA����T)Ztwice)ZthricerC)
rQrXZincrement_count_clinicZincrement_count_noclinicr�ZsubTestrZ	get_countrr3)rr�r��methodsr Zincrement_countr	r	r�test_state_access�s,

�*z(Test_ModuleStateAccess.test_state_accessN)rrrrUr\r]rar	r	r	rrGls	rG�__main__)0�collectionsrr�rr�r2r$r&rmr�r�r�r��importlib.machineryrH�importlib.utilrrZtest.supportrZtest.support.script_helperrrrZ�ImportError�
import_modulerr&r�rlr
rZTestCaserr�r�rrr%r'rBr�Z
with_pymallocrDrErGr�mainr	r	r	r�<module>sX


	OSf
G