a ze7@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl ZddlZddlmZddlmZddlmZmZz ddlZWneydZYn0edZddlZeedZdd ZGd d d ZGd d d e j Z!Gddde j Z"Gddde j Z#Gddde j Z$Gddde j Z%Gddde j Z&Gddde j Z'Gddde'Z(e )e*dGddde'Z+e )edGd d!d!e'Z,Gd"d#d#e j Z-e.d$kre /dS)%) OrderedDictN)support)MISSING_C_DOCSTRINGS)assert_python_failureassert_python_ok _testcapiZgettotalrefcountcCs|SNselfr r B/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_capi.py testfunction#sr c@s eZdZeeZeeZdS)InstanceMethodN)__name__ __module__ __qualname__rZinstancemethodidr r r r r r(s rc@s^eZdZddZddZddZddZee d d d Z ee d d d Z e e dddZddZddZddZddZddZddZddZdd Zeeed!d"d#d$Zd%d&Zed'd(d)Zed'd*d+Zd,d-Zd.d/Z d0d1Z!d2d3Z"d4d5Z#d6d7Z$d8d9Z%d:d;Z&dd?Z(d@dAZ)dBdCZ*dDdEZ+dFdGZ,dHS)ICAPITestcCs~t}|t|||||u||jjtj|tjjtjdtj_|tjd|tt |jdddS)Ntest attribute) r assertEqualr assertTruer __doc__r assertRaisesAttributeErrorsetattrr instr r r test_instancemethod.szCAPITest.test_instancemethodcCsvt,tjtjddgtjtjd}Wdn1s:0Y|\}}||d| | d|dS)N-cz4import _testcapi;_testcapi.crash_no_current_thread())stdoutstderrsFatal 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)) rSuppressCrashReport subprocessPopensys executablePIPE communicaterrrstrip startswith)r pouterrr r r test_no_FatalError_infinite_loop9s  $   z)CAPITest.test_no_FatalError_infinite_loopcCs|ttjdSr)r ValueErrorrZ!make_memoryview_from_NULL_pointerr r r r !test_memoryview_from_NULL_pointerKsz*CAPITest.test_memoryview_from_NULL_pointerc Cstd}td}z|Wnty}z|j}t}t|j|d}t}tj|}t} ||d|| ||j||f| ||| | || ||j|df| ||WYd}~nd}~00| ddS)N5ZTESTF) r0 TypeError __traceback__r&exc_inforZ set_exc_info __class__rZassertSequenceEqualr) r Zraised_exceptionnew_excetbZorig_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.cCsGdddt}|ttjd|dddddd d d d d dddddddddGdddt}|ttjd|dddddd d d d d ddddddddddS)Nc@seZdZddZdS)1CAPITest.test_seq_bytes_to_charp_array..ZcSsdSNr3r r r r r __len__is9CAPITest.test_seq_bytes_to_charp_array..Z.__len__Nrrrr>r r r r ZhsrAr3r3 c@seZdZddZddZdS)r<cSstjSr)r&maxsizer r r r r>osr?cSsdS)Nxr )r ir r r __getitem__qsz=CAPITest.test_seq_bytes_to_charp_array..Z.__getitem__N)rrrr>rYr r r r rAns)objectrr4_posixsubprocess fork_exec MemoryErrorr rAr r r test_seq_bytes_to_charp_arrayes , ,z&CAPITest.test_seq_bytes_to_charp_arraycCsPGdddt}|ttj|dgdddddd d d d d ddddddddddS)Nc@seZdZddZdS)z-CAPITest.test_subprocess_fork_exec..ZcSsdSr=r r r r r r>ysz5CAPITest.test_subprocess_fork_exec..Z.__len__Nr@r r r r rAxsrA1rBrCrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrU)rZrr4r[r\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|tj jd|tj jddS)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_parsings<       z)CAPITest.test_docstring_signature_parsingcCstj}|}|}|||d||f||dd|df|d|dd|f|}||}||d||f|}|d}||d|dfd}||}||dd|fdS)Nmatmul*imatmul)rZ matmulTyper)r MZm1Zm2or r r &test_c_type_with_matrix_multiplicationsz/CAPITest.test_c_type_with_matrix_multiplicationcCs2t}||dd||ddddS)Nr3)r3NrD)rDrD)rZipowTyper__ipow__)r rhr r r test_c_type_with_ipowszCAPITest.test_c_type_with_ipowcCs|tr4td}td|\}}}||dddnD|t}t Wdn1s\0Y|t |j ddS)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: returned NULL without setting an error\n\nCurrent thread.*:\n File .*", line 6 in zBreturn_null_without_error.* returned NULL without setting an error) Py_DEBUGtextwrapdedentr assertRegexreplacer SystemErrorrZreturn_null_without_errorstr exceptionr codercr-r.cmr r r test_return_null_without_errors  & z'CAPITest.test_return_null_without_errorcCs|tr4td}td|\}}}||dddnD|t}t Wdn1s\0Y|t |j ddS)Nz import _testcapi from test import support with support.SuppressCrashReport(): _testcapi.return_result_with_error() rrlr"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: returned a result with an error set\n\nCurrent thread.*:\n File .*, line 6 in z>return_result_with_error.* returned a result with an error set) rmrnrorrprqrrrrZreturn_result_with_errorrsrtrur r r test_return_result_with_errors  & z&CAPITest.test_return_result_with_errorcCs tdSr)rtest_buildvalue_Nr r r r r{szCAPITest.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)rassertInr rvrwr-r.r r r test_set_nomemorys   zCAPITest.test_set_nomemoryc CsGdddt}Gdddt}dddd}it|||t|||||fD]R}|t|t||t|t||t |t| qRdS) Ncs4eZdZfddZfddZfddZZS)z9CAPITest.test_mapping_keys_values_items..Mapping1csttSr)listsuperkeysr r7r r r(sz>CAPITest.test_mapping_keys_values_items..Mapping1.keyscsttSr)rrvaluesr rr r r*sz@CAPITest.test_mapping_keys_values_items..Mapping1.valuescsttSr)rritemsr rr r r,sz?CAPITest.test_mapping_keys_values_items..Mapping1.itemsrrrrrr __classcell__r r rr Mapping1's  rcs4eZdZfddZfddZfddZZS)z9CAPITest.test_mapping_keys_values_items..Mapping2csttSr)tuplerrr rr r r/sz>CAPITest.test_mapping_keys_values_items..Mapping2.keyscsttSr)rrrr rr r r1sz@CAPITest.test_mapping_keys_values_items..Mapping2.valuescsttSr)rrrr rr r r3sz?CAPITest.test_mapping_keys_values_items..Mapping2.itemsrr r rr Mapping2.s  rr3rDrB)fooZbarZspam) dictrZassertListEqualrget_mapping_keysrrget_mapping_valuesrget_mapping_itemsr)r rrZdict_objmappingr r r test_mapping_keys_values_items&s         z'CAPITest.test_mapping_keys_values_itemscCsx|ttjd|ttjd|ttjdGddd}|}|ttj||ttj||ttj|dS)Nc@s$eZdZddZddZddZdS)zCCAPITest.test_mapping_keys_values_items_bad_arg..BadMappingcSsdSrr r r r r rGszHCAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.keyscSsdSrr r r r r rIszJCAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.valuescSsdSrr r r r r rKszICAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.itemsN)rrrrrrr r r r BadMappingFsr)rrrrrrr4)r rZ bad_mappingr r r &test_mapping_keys_values_items_bad_argAsz/CAPITest.test_mapping_keys_values_items_bad_argZnegative_refcountz need _testcapi.negative_refcountcCs*td}td|\}}}||ddS)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)rnrorrpr}r r r test_negative_refcountRs  zCAPITest.test_negative_refcountcCs,ddlm}d}tdD]}||f}qdS)NrMyList)rrrange)r rLrXr r r test_trashcan_subclassds  zCAPITest.test_trashcan_subclassZcpucCs|tdSr)do_test_trashcan_python_classrr r r r test_trashcan_python_class1lsz$CAPITest.test_trashcan_python_class1cCsddlm}||dS)Nrr)rrr)r rr r r test_trashcan_python_class2ps z$CAPITest.test_trashcan_python_class2cCshGddd|}dD]N}d}tdD]}||f}||_q$|rD|f}||jd~||jdqdS)Ncs,eZdZdZfddZfddZZS)z6CAPITest.do_test_trashcan_python_class..PyListrcsjd7_tj|dSr=)numr__init__)r argsrr r r}sz?CAPITest.do_test_trashcan_python_class..PyList.__init__csjd8_dSr=)rr rr r __del__sz>CAPITest.do_test_trashcan_python_class..PyList.__del__)rrrrrrrr r rr PyListys r)rr3ir)rattrZ assertGreaterrr)r baserZparityrrXr r r rus   z&CAPITest.do_test_trashcan_python_classcCsZGdddtj}|}t|}||jd||jd~||dt|dS)NcseZdZfddZZS)z`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once..HeapGcCTypeSubclasscsd|_tdSNrTvalue2rrr rr r rsziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once..HeapGcCTypeSubclass.__init__rrrrrr r rr HeapGcCTypeSubclasssrrJrTr3)r HeapGcCTyper& getrefcountrvaluer)r rsubclass_instance type_refcntr r r :test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_onces zCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncecsGdddtjGfddd}t}t}||jd||jd~||dj||dj||dt||tdS)NcseZdZfddZZS)zdCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..Acsd|_tdSrrr rr r rszmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..A.__init__rr r rr Asrcs*eZdZfddZfddZZS)zdCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..BcstdSr)rrr rr r rszmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..B.__init__cs"|_t_t_dSr)r7r&r refcnt_in_delr rBr r rs zlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..B.__del__)rrrrrrr rrr rs rrJrTr3)rrr&rrrrrr rrZnew_type_refcntr rr Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_onces   zYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncecCsXt}d|_||jd||j|j||jddit}|i|jdSNrer)rZHeapCTypeWithDictrrdictobj__dict__rr r r test_heaptype_with_dictsz CAPITest.test_heaptype_with_dictcCsXt}d|_||jd||j|j||jddit}|i|jdSr)rZHeapCTypeWithNegativeDictrrrrrr r r test_heaptype_with_negative_dictsz)CAPITest.test_heaptype_with_negative_dictcCs2t}t|}|||||j|dSr)rZHeapCTypeWithWeakrefweakrefrefrZ weakreflist)r rrr r r test_heaptype_with_weakrefs z#CAPITest.test_heaptype_with_weakrefcCs t}t|}||ddS)Ns1234)rZHeapCTypeWithBufferbytesr)r rbr r r test_heaptype_with_buffersz"CAPITest.test_heaptype_with_buffercCsNt}ttj}||jd||jd~||dttjdSNrJrTr3)rHeapCTypeSubclassr&rrrr)r rrr r r 9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_onces  zBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncecCst}ttj}ttj}||jd||jd~||dtjj||dtjj||dttj||ttjdSr) rZHeapCTypeSubclassWithFinalizerr&rrrrrrrr r r Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_onces  zXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncecCs@t}||jdd|_||jd|`||jddS)NrJrLr)rZHeapCTypeSetattrrZpvaluer)r objr r r test_heaptype_with_setattros z$CAPITest.test_heaptype_with_setattrocCsddlm}||ddd||ddd||ddd ||dd d ||d dd ||d dd||d dd||d d d|t|dd|t|d d|t|dddS)Nr)pynumber_tobase{rDZ 0b1111011rHZ0o173rJ123rPZ0x7biz -0b1111011z-0o173z-123z-0x7bg^@)rrrrr4rr)r rr r r test_pynumber_tobases zCAPITest.test_pynumber_tobasecCst}||ddSNz)rZpyobject_repr_from_nullrr sr r r test_pyobject_repr_from_nullsz%CAPITest.test_pyobject_repr_from_nullcCst}||ddSr)rZpyobject_str_from_nullrrr r r test_pyobject_str_from_null sz$CAPITest.test_pyobject_str_from_nullcCst}||ddS)Ns)rZpyobject_bytes_from_nullrrr r r test_pyobject_bytes_from_null$sz&CAPITest.test_pyobject_bytes_from_nullN)-rrrrr/r1r;unittest skipUnlessr[r_raZskipIfrrcrirkryrzr{r~rrhasattrrrrrZrequires_resourcerrrrrrrrrrrrrrrrr r r r r,sV      )"     #   rc@s6eZdZddZd ddZddZdd Zd d ZdS) TestPendingCallscs>fdd}t|D]$}ttdt|r*qq*qdS)NcsddSr)appendr lr r callback,sz6TestPendingCalls.pendingcalls_submit..callbackg{Gz?)rtimesleeprandomrZ_pending_threadfunc)r rnrrXr rr pendingcalls_submit+s    z$TestPendingCalls.pendingcalls_submitNcCsd}t||krxdr,tjr,tdt|ftdD] }||}q4|rR|jsRq|d7}||dkd|t|fqdrtjrtdt|fdS)NrFz(%i)rr3i'z(timeout waiting for %i callbacks, got %i)lenrverboseprintreventis_setr)r rrcontextcountrXar r r pendingcalls_wait:s      z"TestPendingCalls.pendingcalls_waitcsd}g}Gdddt}|g_d_|j_d_t_t_ fddt jD}t |  j|Wdn1s0YdS)N c@s eZdZdS)z8TestPendingCalls.test_pendingcalls_threaded..fooNrrrr r r r rRr"rrDrcsg|]}tjjfdqS))targetr) threadingThreadpendingcalls_thread).0rXrr r r [sz?TestPendingCalls.test_pendingcalls_threaded..)rZrrnThreads nFinishedrLocklockEventrrrZ start_threadsr)r rthreadsrr rr test_pendingcalls_threadedMs     z+TestPendingCalls.test_pendingcalls_threadedcCszv||j|jW|j8|jd7_|j}drDtjrDtd|Wdn1sX0Y||jkr|j nd|j8|jd7_|j}drtjrtd|Wdn1s0Y||jkr|j 0dS)Nr3Fzfinished threads: ) rrrrrrrrrrset)r rrr r r ras  (   ( z$TestPendingCalls.pendingcalls_threadcCs$g}d}||||||dS)N@)rr)r rrr r r test_pendingcalls_non_threadedms z/TestPendingCalls.test_pendingcalls_non_threaded)N)rrrrrrrrr r r r r)s   rc@s,eZdZddZddZddZddZd S) SubinterpreterTestcCsddl}t\}}d|}t|dT}t|}||d|t |t t j |t |t |Wdn1s0YdS)Nrzif 1: import sys, builtins, pickle with open({:d}, "wb") as f: pickle.dump(id(sys.modules), f) pickle.dump(id(builtins), f) rb)builtinsospipeformatopenrrun_in_subinterprZassertNotEqualpickleloadrr&modules)r rrwrvfretr r r test_subinterpszs    z"SubinterpreterTest.test_subinterpscCsrt\}}d|}t|d>}t|}||d|t|dddWdn1sd0YdS)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) rrZ123xr)rr) rrrrrrrrr)r rrrvrrr r r (test_subinterps_recent_language_featuress     z;SubinterpreterTest.test_subinterps_recent_language_featurescCs(ddl}td|t|jddS)Nrz1import binascii; binascii.Error.foobar = 'foobar'Zfoobar)binasciirrZ assertFalserError)r r r r r test_mutate_exceptions z(SubinterpreterTest.test_mutate_exceptioncCst\}}|tj||tj|td|d}t|t|d}t |}| |dt|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) rrZ addCleanupclosernroexecreadrrr)r rrZscriptZ main_attr_idrZsubinterp_attr_idr r r "test_module_state_shared_in_globals       z5SubinterpreterTest.test_module_state_shared_in_globalN)rrrrr r rr r r r rxs rc@seZdZejddZdS)TestThreadStatecs2fdd}|tj|d}||dS)NcsHgfdd}t||}}tdtdddS)NcstdSr)rr get_identr Zidentsr r rszCTestThreadState.test_thread_state..target..callbackr3rBz/Couldn't find main thread correctly in the list)rZ_test_thread_staterrrrrr)rrrr rr rs   z1TestThreadState.test_thread_state..target)r)rrstartjoin)r rtr r r test_thread_states   z!TestThreadState.test_thread_stateN)rrrrZ reap_threadsrr r r r rsrc@s&eZdZeddeeDdS) Test_testcapiccs0|](}|dr|ds|tt|fVqdS)test__codeN)r+endswithgetattrrrnamer r r szTest_testcapi.N)rrrlocalsupdatedirrr r r r rs rc@s&eZdZeddeeDdS)Test_testinternalcapiccs&|]}|dr|tt|fVqdS)rN)r+r_testinternalcapirr r r r s zTest_testinternalcapi.N)rrrr!r"r#r%r r r r r$s r$c@sleZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZdS)PyMemDebugTestsdebugz(?:0x)?[0-9a-fA-F]+cCsJt td||jd}Wdn1s.0Y|j}|ddS)Nr PYTHONMALLOCasciirq)rr#rr)r.decode)r rvr-r!r r r checks  $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 byteZptr)flags)r,r PTR_REGEXrecompileDOTALLrpr r-Zregexr r r test_buffer_overflows  z$PyMemDebugTests.test_buffer_overflowcCs,|d}d}|j|jd}|||dS)Nz.import _testcapi; _testcapi.pymem_api_misuse()aDebug 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,rr/rpr3r 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|)r rvr-Zexpectedr r r check_malloc_without_gils z(PyMemDebugTests.check_malloc_without_gilcCsd}||dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()r6r rvr r r test_pymem_malloc_without_gil$sz-PyMemDebugTests.test_pymem_malloc_without_gilcCsd}||dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()r7r8r r r test_pyobject_malloc_without_gil*sz0PyMemDebugTests.test_pyobject_malloc_without_gilcCs&td|d}td||jddS)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()rnrorr))r func_namervr r r check_pyobject_is_freed0s z'PyMemDebugTests.check_pyobject_is_freedcCs|ddS)NZcheck_pyobject_null_is_freedr<r r r r test_pyobject_null_is_freed?sz+PyMemDebugTests.test_pyobject_null_is_freedcCs|ddS)NZ%check_pyobject_uninitialized_is_freedr=r r r r $test_pyobject_uninitialized_is_freedBsz4PyMemDebugTests.test_pyobject_uninitialized_is_freedcCs|ddS)NZ'check_pyobject_forbidden_bytes_is_freedr=r r r r &test_pyobject_forbidden_bytes_is_freedEsz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freedcCs|ddS)NZcheck_pyobject_freed_is_freedr=r r r r test_pyobject_freed_is_freedHsz,PyMemDebugTests.test_pyobject_freed_is_freedN)rrrr)r/r,r4r5r6r9r:r<r>r?r@rAr r r r r&sr&c@seZdZdZdS)PyMemMallocDebugTestsZ malloc_debugNrrrr)r r r r rBLsrBz need pymallocc@seZdZdZdS)PyMemPymallocDebugTestsZpymalloc_debugNrCr r r r rDPsrDz need Py_DEBUGc@seZdZdZdS)PyMemDefaultTestsNrCr r r r rEUsrEc@s,eZdZddZddZddZddZd S) Test_ModuleStateAccesscCsNd}tjdj}tj||}tj||}tj|}||||_ dS)NZ!_testmultiphase_meth_state_accessZ_testmultiphase) importlibutil find_specorigin machineryExtensionFileLoaderspec_from_loadermodule_from_spec exec_modulemodule)r fullnamerKloaderspecrQr r r setUpbs  zTest_ModuleStateAccess.setUpcCs0Gddd|jj}|}|||jdS)Nc@s eZdZdS)zQTest_ModuleStateAccess.test_subclass_get_module..StateAccessType_SubclassNrr r r r StateAccessType_SubclassmsrVrQStateAccessTypeZassertIsget_defining_moduler rVinstancer r r test_subclass_get_moduleksz/Test_ModuleStateAccess.test_subclass_get_modulecCs0Gddd|jj}|}|||jdS)NcseZdZfddZZS)z\Test_ModuleStateAccess.test_subclass_get_module_with_super..StateAccessType_Subclasscs tSr)rrYr rr r rYuszpTest_ModuleStateAccess.test_subclass_get_module_with_super..StateAccessType_Subclass.get_defining_module)rrrrYrr r rr rVtsrVrWrZr r r #test_subclass_get_module_with_superssz:Test_ModuleStateAccess.test_subclass_get_module_with_superc Cs|j}|j}|j|jd}|D]N\}}||(|||||d||||||d|d|||||d|ddd|||||d|t |dd Wdn1s0Y|t |dd dWdn1sP0YWdq*1sp0Yq*dS) N)ZclinicZnoclinicrr3rBT)Ztwice)ZthricerD) rQrXZincrement_count_clinicZincrement_count_noclinicrZsubTestrZ get_countrr4)r rrmethodsrZincrement_countr r r test_state_access{s,    * z(Test_ModuleStateAccess.test_state_accessN)rrrrUr\r]rar r r r rG[s rG__main__)0 collectionsrrrrr0r$r&rnrrrrZimportlib.machineryrHimportlib.utilrrZ test.supportrZtest.support.script_helperrrr[ ImportError import_modulerr%rrmr rZTestCaserrrrrr$r&rBrZ with_pymallocrDrErGrmainr r r r sX        OS] G