a 4êdgO‹ã@säddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl ZddlZddlmZddlmZddlmZmZz ddlZWney¾dZYn0e d¡ZddlZeedƒZdd „ZGd d „d ƒZGd d „d e j ƒZ!Gdd„de j ƒZ"Gdd„de j ƒZ#Gdd„de j ƒZ$Gdd„de j ƒZ%Gdd„de j ƒZ&Gdd„de j ƒZ'Gdd„de'ƒZ(e  )e *¡d¡Gdd„de'ƒƒZ+e  )ed¡Gd d!„d!e'ƒƒZ,Gd"d#„d#e j ƒZ-e.d$kràe  /¡dS)%é)Ú OrderedDictN)Úsupport)ÚMISSING_C_DOCSTRINGS)Úassert_python_failureÚassert_python_okÚ _testcapiZgettotalrefcountcCs|S©N©©Úselfr r ú*/usr/local/lib/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 „ƒZ e  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&dd?„Z(d@dA„Z)dBS)CÚ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ÚPIPEÚ communicaterrÚ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) r0Ú TypeErrorÚ __traceback__r&Úexc_inforZ set_exc_infoÚ __class__rZassertSequenceEqualr) r Zraised_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 d d d ddddddddd¡Gdd„dtƒ}| ttjd|ƒdddddd d d d d ddddddddd¡dS)Nc@seZdZdd„ZdS)ú1CAPITest.test_seq_bytes_to_charp_array..ZcSsdS©Nr3r r r r r Ú__len__isú9CAPITest.test_seq_bytes_to_charp_array..Z.__len__N©rrrr>r r r r ÚZhsrAr3é©r3éééééé é é é é éééééééé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..Z.__getitem__N)rrrr>rYr r r r rAns)Úobjectrr4Ú_posixsubprocessÚ fork_execÚ MemoryError©r rAr r r Útest_seq_bytes_to_charp_arrayes ,ÿ ,ÿz&CAPITest.test_seq_bytes_to_charp_arraycCsPGdd„dtƒ}| ttj|ƒdgdddddd d d d d ddddddddd¡dS)Nc@seZdZdd„ZdS)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 rAxsrAó1rBrCrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrU)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 jd¡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)Nr3)r3NrD)rDrD)rZipowTyperÚ__ipow__)r rhr 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: 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_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() 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_errorás ÿ & ÿz&CAPITest.test_return_result_with_errorcCs t ¡dSr)rÚtest_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)rÚassertIn©r rvrwr-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..Mapping1csttƒ ¡ƒSr)ÚlistÚsuperÚkeysr ©r7r r r(sz>CAPITest.test_mapping_keys_values_items..Mapping1.keyscsttƒ ¡ƒSr)rr€Úvaluesr r‚r r rƒ*sz@CAPITest.test_mapping_keys_values_items..Mapping1.valuescsttƒ ¡ƒSr)rr€Úitemsr r‚r r r„,sz?CAPITest.test_mapping_keys_values_items..Mapping1.items©rrrrrƒr„Ú __classcell__r r r‚r ÚMapping1's  r‡cs4eZdZ‡fdd„Z‡fdd„Z‡fdd„Z‡ZS)z9CAPITest.test_mapping_keys_values_items..Mapping2csttƒ ¡ƒSr)Útupler€rr r‚r r r/sz>CAPITest.test_mapping_keys_values_items..Mapping2.keyscsttƒ ¡ƒSr)rˆr€rƒr r‚r r rƒ1sz@CAPITest.test_mapping_keys_values_items..Mapping2.valuescsttƒ ¡ƒSr)rˆr€r„r r‚r r r„3sz?CAPITest.test_mapping_keys_values_items..Mapping2.itemsr…r r r‚r ÚMapping2.s  r‰r3rDrB)ÚfooZbarZspam) ÚdictrZassertListEqualrÚget_mapping_keysrrÚget_mapping_valuesrƒÚget_mapping_itemsr„)r r‡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..BadMappingcSsdSrr r r r r rGszHCAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.keyscSsdSrr r r r r rƒIszJCAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.valuescSsdSrr r r r r r„KszICAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.itemsN)rrrrrƒr„r r r r Ú BadMappingFsr‘)rrrrŒrrŽr4)r r‘Z bad_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)rnrorrpr}r r r Útest_negative_refcountRs  ÿzCAPITest.test_negative_refcountcCs,ddlm}d}tdƒD]}||fƒ}qdS)Nr©ÚMyListéè)rr•Úrange)r r•ÚLrXr r r Útest_trashcan_subclassds  zCAPITest.test_trashcan_subclassZcpucCs| t¡dSr)Údo_test_trashcan_python_classrr r r r Útest_trashcan_python_class1lsz$CAPITest.test_trashcan_python_class1cCsddlm}| |¡dS)Nrr”)rr•rš)r r•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..PyListrcsˆjd7_tƒj|ŽdSr=)Únumr€Ú__init__)r Úargsr‚r r rž}sz?CAPITest.do_test_trashcan_python_class..PyList.__init__csˆjd8_dSr=)rr r‚r r Ú__del__€sz>CAPITest.do_test_trashcan_python_class..PyList.__del__)rrrrržr r†r r r‚r ÚPyListys r¡)rr3ir)r—ÚattrZ assertGreaterrr)r Úbaser¡Zparityr˜rXr 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..HeapGcCTypeSubclasscsd|_tƒ ¡dS©NrT©Úvalue2r€ržr r‚r r rž“sziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once..HeapGcCTypeSubclass.__init__©rrrržr†r r r‚r ÚHeapGcCTypeSubclass’sr¨rJrTr3)rÚ HeapGcCTyper&Ú getrefcountrÚvaluer¦)r r¨Ú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..Acsd|_tƒ ¡dSr¤r¥r r‚r r rž¤szmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..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..Bcstƒ ¡dSr)r€ržr r‚r r rž©szmCAPITest.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 ©r¯ÚBr r r ¬s zlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..B.__del__)rrrržr r†r r±r‚r r²¨s r²rJrTr3)rr©r&rªrr«r¦r°©r r¬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©NrerŠ)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ÚrefrZ weakreflist)r rr»r r r Útest_heaptype_with_weakrefÙs z#CAPITest.test_heaptype_with_weakrefcCs t ¡}t|ƒ}| |d¡dS)Ns1234)rZHeapCTypeWithBufferÚbytesr)r rÚbr r r Útest_heaptype_with_bufferßsz"CAPITest.test_heaptype_with_buffercCsNt ¡}t tj¡}| |jd¡| |jd¡~| |dt tj¡¡dS©NrJrTr3)rÚHeapCTypeSubclassr&rªrr«r¦)r r¬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)NrJrLr)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é{rDZ 0b1111011rHZ0o173rJÚ123rPZ0x7bi…ÿÿÿz -0b1111011z-0o173z-123z-0x7bgÀ^@)rrÆrrr4rr)r rÆr r r Útest_pynumber_tobases zCAPITest.test_pynumber_tobaseN)*rrrrr/r1r;ÚunittestÚ skipUnlessr[r_raZskipIfrrcrirkryrzr{r~rr’Úhasattrrr“r™rZrequires_resourcer›rœršr®r´r¸r¹r¼r¿rÂrÃrÅrÉr r r r r,sP     ÿ )"  ÿ   #   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 Úcallback sz6TestPendingCalls.pendingcalls_submit..callbackg{®Gáz”?)r—ÚtimeÚsleepÚrandomrZ_pending_threadfunc)r rÐÚnrÑrXr rÏr Úpendingcalls_submits    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–r3i'z(timeout waiting for %i callbacks, got %i)ÚlenrÚverboseÚprintr—ÚeventÚis_setr)r rÐrÕÚcontextÚcountrXÚar r r Úpendingcalls_wait.s     ÿ 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..fooN©rrrr r r r rŠFr"rŠrDrcsg|]}tjˆjˆfd‘qS))ÚtargetrŸ)Ú threadingÚThreadÚpendingcalls_thread)Ú.0rX©rÜr r r Ú Osþÿz?TestPendingCalls.test_pendingcalls_threaded..)rZrÐrÕÚnThreadsÚ nFinishedrãÚLockÚlockÚEventrÚr—rZ start_threadsrß)r rÕÚthreadsrŠr rçr Útest_pendingcalls_threadedAs    þ z+TestPendingCalls.test_pendingcalls_threadedcCsàzv| |j|j¡W|j8|jd7_|j}drDtjrDtd|ƒWdƒn1sX0Y||jkrÜ|j   ¡nd|j8|jd7_|j}dr¨tjr¨td|ƒWdƒn1s¼0Y||jkrÚ|j   ¡0dS)Nr3Fzfinished threads: ) rÖrÐrÕrìrêrrØrÙrérÚÚset)r rÜrêr r r råUs  (  ú ( z$TestPendingCalls.pendingcalls_threadcCs$g}d}| ||¡| ||¡dS)Né@)rÖrß)r rÐrÕr r r Útest_pendingcalls_non_threadedas z/TestPendingCalls.test_pendingcalls_non_threaded)N)rrrrÖrßrïråròr r r r rÍs   rÍc@s$eZdZdd„Zdd„Zdd„ZdS)ÚSubinterpreterTestcCsddl}t ¡\}}d |¡}t|dƒT}t |¡}| |d¡| t   |¡t t 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)r rõÚrÚwrvÚfÚretr r r Útest_subinterpsns û   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÷rørùrrúrrûrü)r rþrÿrvrrr 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)ÚbinasciirrúZ assertFalserÌÚError)r rr r r Útest_mutate_exception’s z(SubinterpreterTest.test_mutate_exceptionN)rrrrrrr r r r rólsró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..target..callbackr3rBz/Couldn't find main thread correctly in the list)rZ_test_thread_staterÒrÓrrÝrãr)rÑrÞr¾r r r râ¥s   ÿz1TestThreadState.test_thread_state..target)râ)rãräÚstartÚjoin)r râÚtr r r Útest_thread_state¢s   z!TestThreadState.test_thread_stateN)rrrrZ reap_threadsr r 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 Ú ¹sþzTest_testcapi.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.N)rrrrrrrr r r r r¾s ÿrc@sleZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„ZdS)ÚPyMemDebugTestsÚdebugz(?:0x)?[0-9a-fA-F]+cCsJt ¡ td||jd}Wdƒn1s.0Y|j}| dd¡S)Nr©Ú PYTHONMALLOCÚasciirq)rr#rrr.Údecode)r rvr-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ÚreÚcompileÚDOTALLrp©r r-Zregexr r r Útest_buffer_overflowÐs  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!rør$rpr(r r r Útest_api_misuseäs  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_gilós z(PyMemDebugTests.check_malloc_without_gilcCsd}| |¡dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()©r+©r rvr r r Útest_pymem_malloc_without_gilùsz-PyMemDebugTests.test_pymem_malloc_without_gilcCsd}| |¡dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()r,r-r r r Ú test_pyobject_malloc_without_gilÿsz0PyMemDebugTests.test_pyobject_malloc_without_gilcCs&t d|›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_freedsû z'PyMemDebugTests.check_pyobject_is_freedcCs| d¡dS)NZcheck_pyobject_null_is_freed©r1r r r r Útest_pyobject_null_is_freedsz+PyMemDebugTests.test_pyobject_null_is_freedcCs| d¡dS)NZ%check_pyobject_uninitialized_is_freedr2r r r r Ú$test_pyobject_uninitialized_is_freedsz4PyMemDebugTests.test_pyobject_uninitialized_is_freedcCs| d¡dS)NZ'check_pyobject_forbidden_bytes_is_freedr2r r r r Ú&test_pyobject_forbidden_bytes_is_freedsz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freedcCs| d¡dS)NZcheck_pyobject_freed_is_freedr2r r r r Útest_pyobject_freed_is_freedsz,PyMemDebugTests.test_pyobject_freed_is_freedN)rrrrr$r!r)r*r+r.r/r1r3r4r5r6r r r r rÄsrc@seZdZdZdS)ÚPyMemMallocDebugTestsZ malloc_debugN©rrrrr r r r r7!sr7z need pymallocc@seZdZdZdS)ÚPyMemPymallocDebugTestsZpymalloc_debugNr8r r r r r9%sr9z need Py_DEBUGc@seZdZdZdS)ÚPyMemDefaultTestsÚNr8r r r r r:*sr:c@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 Úfullnamer@ÚloaderÚspecrFr r r ÚsetUp7s  zTest_ModuleStateAccess.setUpcCs0Gdd„d|jjƒ}|ƒ}| | ¡|j¡dS)Nc@s eZdZdS)zQTest_ModuleStateAccess.test_subclass_get_module..StateAccessType_SubclassNrár r r r ÚStateAccessType_SubclassBsrK©rFÚStateAccessTypeZassertIsÚget_defining_module©r rKÚ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..StateAccessType_Subclasscs tƒ ¡Sr)r€rNr r‚r r rNJszpTest_ModuleStateAccess.test_subclass_get_module_with_super..StateAccessType_Subclass.get_defining_module)rrrrNr†r r r‚r rKIsrKrLrOr r r Ú#test_subclass_get_module_with_superHsz:Test_ModuleStateAccess.test_subclass_get_module_with_superc Cs€|j ¡}|j ¡}|j|jdœ}| ¡D]N\}}| |¡(| | ¡| ¡¡| | ¡d¡|ƒ| | ¡| ¡¡| | ¡d¡|dƒ| | ¡| ¡¡| | ¡d¡|ddd| | ¡| ¡¡| | ¡d¡| t ¡|dd Wdƒn1s0Y| t ¡|dd dƒWdƒn1sP0YWdƒq*1sp0Yq*dS) N)ZclinicZnoclinicrr3rBééþÿÿÿT)Ztwice)ZthricerD) rFrMZincrement_count_clinicZincrement_count_noclinicr„ZsubTestrZ get_countrr4)r rÞr¾ÚmethodsrZincrement_countr r r Útest_state_accessPs,  þ  * z(Test_ModuleStateAccess.test_state_accessN)rrrrJrQrRrVr r r r r<0s r<Ú__main__)0Ú collectionsrrörûrÔr%r$r&rnrãrÒrÊrºZimportlib.machineryr=Úimportlib.utilrrZ test.supportrZtest.support.script_helperrrr[Ú ImportErrorÚ import_modulerrrÌrmr rZTestCaserrÍrórrrrr7rËZ with_pymallocr9r:r<rÚmainr r r r ÚsV        tO4] G