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)zsome doc©©Úselfrrú*/usr/local/lib/python3.9/test/test_capi.pyÚ testfunction#sr c@s eZdZe e¡Ze e¡ZdS)ÚInstanceMethodN)Ú__name__Ú __module__Ú __qualname__rZinstancemethodÚidr rrrr r (s r c@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 Úinstrrr Ú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Úerrrrr Ú test_no_FatalError_infinite_loop9s  ÿü$   ÿúz)CAPITest.test_no_FatalError_infinite_loopcCs| ttj¡dS©N)rÚ ValueErrorrZ!make_memoryview_from_NULL_pointerr rrr Ú!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_inforrr Ú 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©Nr3rr rrr Ú__len__isú9CAPITest.test_seq_bytes_to_charp_array..Z.__len__N©rrrr>rrrr ÚZhsrAr3é©r3éééééé é é é é ééééééééc@seZdZdd„Zdd„ZdS)r<cSstjSr/)r%Úmaxsizer rrr r>osr?cSsdS)Nóxr)r Úirrr Ú __getitem__qsz=CAPITest.test_seq_bytes_to_charp_array..Z.__getitem__N)rrrr>rYrrrr rAns)Úobjectrr4Ú_posixsubprocessÚ fork_execÚ MemoryError©r rArrr Ú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=rr rrr r>ysz5CAPITest.test_subprocess_fork_exec..Z.__len__Nr@rrrr rAxsrAó1rBrCrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrU)rZrr4r[r\r^rrr Ú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 rrr Ú 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Úorrr Ú&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 rhrrr Ú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-Úcmrrr Ú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_errorrsrtrurrr Útest_return_result_with_errorás ÿ & ÿz&CAPITest.test_return_result_with_errorcCs t ¡dSr/)rÚtest_buildvalue_Nr rrr 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-rrr Ú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 ©r7rr r(sz>CAPITest.test_mapping_keys_values_items..Mapping1.keyscsttƒ ¡ƒSr/)rr€Úvaluesr r‚rr rƒ*sz@CAPITest.test_mapping_keys_values_items..Mapping1.valuescsttƒ ¡ƒSr/)rr€Úitemsr r‚rr r„,sz?CAPITest.test_mapping_keys_values_items..Mapping1.items©rrrrrƒr„Ú __classcell__rrr‚r ÚMapping1's  r‡cs4eZdZ‡fdd„Z‡fdd„Z‡fdd„Z‡ZS)z9CAPITest.test_mapping_keys_values_items..Mapping2csttƒ ¡ƒSr/)Útupler€rr r‚rr r/sz>CAPITest.test_mapping_keys_values_items..Mapping2.keyscsttƒ ¡ƒSr/)rˆr€rƒr r‚rr rƒ1sz@CAPITest.test_mapping_keys_values_items..Mapping2.valuescsttƒ ¡ƒSr/)rˆr€r„r r‚rr r„3sz?CAPITest.test_mapping_keys_values_items..Mapping2.itemsr…rrr‚r ÚMapping2.s  r‰r3rDrB)ÚfooZbarZspam) ÚdictrZassertListEqualrÚget_mapping_keysrrÚget_mapping_valuesrƒÚget_mapping_itemsr„)r r‡r‰Zdict_objÚmappingrrr Ú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..BadMappingcSsdSr/rr rrr rGszHCAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.keyscSsdSr/rr rrr rƒIszJCAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.valuescSsdSr/rr rrr r„KszICAPITest.test_mapping_keys_values_items_bad_arg..BadMapping.itemsN)rrrrrƒr„rrrr Ú BadMappingFsr‘)rrrrŒrrŽr4)r r‘Z bad_mappingrrr Ú&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}rrr Útest_negative_refcountRs  ÿzCAPITest.test_negative_refcountcCs,ddlm}d}tdƒD]}||fƒ}qdS)Nr©ÚMyListéè)rr•Úrange)r r•ÚLrXrrr Útest_trashcan_subclassds  zCAPITest.test_trashcan_subclassZcpucCs| t¡dSr/)Údo_test_trashcan_python_classrr rrr Útest_trashcan_python_class1lsz$CAPITest.test_trashcan_python_class1cCsddlm}| |¡dS)Nrr”)rr•rš)r r•rrr Ú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‚rr rž}sz?CAPITest.do_test_trashcan_python_class..PyList.__init__csˆjd8_dSr=)rr r‚rr Ú__del__€sz>CAPITest.do_test_trashcan_python_class..PyList.__del__)rrrrržr r†rrr‚r ÚPyListys r¡)rr3ir)r—ÚattrZ assertGreaterrr)r Úbaser¡Zparityr˜rXrrr 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‚rr rž“sziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once..HeapGcCTypeSubclass.__init__©rrrržr†rrr‚r ÚHeapGcCTypeSubclass’sr¨rJrTr3)rÚ HeapGcCTyper%Ú getrefcountrÚvaluer¦)r r¨Úsubclass_instanceÚ type_refcntrrr Ú: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‚rr rž¤szmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..A.__init__r§rrr‚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‚rr 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¯ÚBrr r ¬s zlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once..B.__del__)rrrržr r†rr±r‚r r²¨s r²rJrTr3)rr©r%rªrr«r¦r°©r r¬r­Znew_type_refcntrr±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__rrrr Útest_heaptype_with_dictÅsz CAPITest.test_heaptype_with_dictcCsXt ¡}d|_| |jd¡| |j|j¡| |jddi¡t ¡}| i|j¡dSrµ)rZHeapCTypeWithNegativeDictrŠrr¶r·rrrr Ú test_heaptype_with_negative_dictÏsz)CAPITest.test_heaptype_with_negative_dictcCs2t ¡}t |¡}| |ƒ|¡| |j|¡dSr/)rZHeapCTypeWithWeakrefÚweakrefÚrefrZ weakreflist)r rr»rrr Útest_heaptype_with_weakrefÙs z#CAPITest.test_heaptype_with_weakrefcCs t ¡}t|ƒ}| |d¡dS)Ns1234)rZHeapCTypeWithBufferÚbytesr)r rÚbrrr Ú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­rrr Ú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³rrr Ú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 Úobjrrr Ú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Ærrr Ú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Érrrr 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©Úlrr Úcallback sz6TestPendingCalls.pendingcalls_submit..callbackg{®Gáz”?)r—ÚtimeÚsleepÚrandomrZ_pending_threadfunc)r rÐÚnrÑrXrrÏ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Úarrr Ú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©rrrrrrr rŠFr!rŠrDrcsg|]}tjˆjˆfd‘qS))ÚtargetrŸ)Ú threadingÚThreadÚpendingcalls_thread)Ú.0rX©rÜr rr Ú Osþÿz?TestPendingCalls.test_pendingcalls_threaded..)rZrÐrÕÚnThreadsÚ nFinishedrãÚLockÚlockÚEventrÚr—rZ start_threadsrß)r rÕÚthreadsrŠrrç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êrrr råUs  (  ú ( z$TestPendingCalls.pendingcalls_threadcCs$g}d}| ||¡| ||¡dS)Né@)rÖrß)r rÐrÕrrr Útest_pendingcalls_non_threadedas z/TestPendingCalls.test_pendingcalls_non_threaded)N)rrrrÖrßrïråròrrrr 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Úretrrr Ú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ÿrvrrrrr Ú(test_subinterps_recent_language_features}s  ô   z;SubinterpreterTest.test_subinterps_recent_language_featurescCs(ddl}t d¡| 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'Zfoobar)ÚbinasciirrúZ assertFalserÌÚError)r rrrr Útest_mutate_exception’s z(SubinterpreterTest.test_mutate_exceptionN)rrrrrrrrrr 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©Zidentsrr 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âÚtrr r Útest_thread_state¢s   z!TestThreadState.test_thread_stateN)rrrrZ reap_threadsr rrrr r src@s&eZdZeƒ dd„eeƒDƒ¡dS)Ú Test_testcapiccs0|](}| d¡r| d¡s|tt|ƒfVqdS)Útest_Ú_codeN)r*ÚendswithÚgetattrr©ræÚnamerrr Ú ¹sþzTest_testcapi.N)rrrÚlocalsÚupdateÚdirrrrrr r¸s ÿrc@s&eZdZeƒ dd„eeƒDƒ¡dS)ÚTest_testinternalcapiccs&|]}| d¡r|tt|ƒfVqdS)rN)r*rÚ_testinternalcapirrrr r¿s þzTest_testinternalcapi.N)rrrrrrrrrrr 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 rrr Ú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,Zregexrrr Ú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(rrr Ú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,Zexpectedrrr Úcheck_malloc_without_gilós z(PyMemDebugTests.check_malloc_without_gilcCsd}| |¡dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()©r+©r rvrrr Útest_pymem_malloc_without_gilùsz-PyMemDebugTests.test_pymem_malloc_without_gilcCsd}| |¡dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()r,r-rrr Ú 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_namervrrr Úcheck_pyobject_is_freedsû z'PyMemDebugTests.check_pyobject_is_freedcCs| d¡dS)NZcheck_pyobject_null_is_freed©r1r rrr Útest_pyobject_null_is_freedsz+PyMemDebugTests.test_pyobject_null_is_freedcCs| d¡dS)NZ%check_pyobject_uninitialized_is_freedr2r rrr Ú$test_pyobject_uninitialized_is_freedsz4PyMemDebugTests.test_pyobject_uninitialized_is_freedcCs| d¡dS)NZ'check_pyobject_forbidden_bytes_is_freedr2r rrr Ú&test_pyobject_forbidden_bytes_is_freedsz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freedcCs| d¡dS)NZcheck_pyobject_freed_is_freedr2r rrr Útest_pyobject_freed_is_freedsz,PyMemDebugTests.test_pyobject_freed_is_freedN)rrrrr$r!r)r*r+r.r/r1r3r4r5r6rrrr rÄsrc@seZdZdZdS)ÚPyMemMallocDebugTestsZ malloc_debugN©rrrrrrrr r7!sr7z need pymallocc@seZdZdZdS)ÚPyMemPymallocDebugTestsZpymalloc_debugNr8rrrr r9%sr9z need Py_DEBUGc@seZdZdZdS)ÚPyMemDefaultTestsÚNr8rrrr r:*sr:c@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚTest_ModuleStateAccessz%Test access to module start (PEP 573)cCsNd}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ÚspecrFrrr ÚsetUp7s  zTest_ModuleStateAccess.setUpcCs0Gdd„d|jjƒ}|ƒ}| | ¡|j¡dS)z#PyType_GetModule for defining_classc@s eZdZdS)zQTest_ModuleStateAccess.test_subclass_get_module..StateAccessType_SubclassNrárrrr ÚStateAccessType_SubclassBsrKN©rFÚStateAccessTypeZassertIsÚget_defining_module©r rKÚinstancerrr Ú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‚rr rNJszpTest_ModuleStateAccess.test_subclass_get_module_with_super..StateAccessType_Subclass.get_defining_module)rrrrNr†rrr‚r rKIsrKrLrOrrr Ú#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*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. )ZclinicZnoclinicrr3rBééþÿÿÿT)Ztwice)ZthriceNrD) rFrMZincrement_count_clinicZincrement_count_noclinicr„ZsubTestrZ get_countrr4)r rÞr¾ÚmethodsrZincrement_countrrr Útest_state_accessPs,  þ  * z(Test_ModuleStateAccess.test_state_accessN)rrrrrJrQrRrVrrrr 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 r ZTestCaserrÍrórrrrr7rËZ with_pymallocr9r:r<rÚmainrrrr ÚsV        tO4] G