
    z%i0W                    Z   d dl Z d dlmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z m!Z!m"Z" 	 d dl#Z#	 d dl%Z%	 d dl&Z&	 d dl'Z( ejT                  d
      Z+d dl,Z,dZ-d Z.d Z/d Z0 G d d      Z1 G d dejd                        Z3e G d dejd                               Z4 G d dejd                        Z5 G d dejd                        Z6 G d dejd                        Z7 G d dejd                        Z8 G d dejd                        Z9 G d dejd                        Z: G d  d!ejd                        Z; ejx                  e%du d"       G d# d$ejd                               Z= G d% d&ejd                        Z>d'Z? G d( d)ejd                        Z@eAd*k(  r ej                          yy# e$$ r dZ#Y ww xY w# e$$ r dZ%Y w xY w# e$$ r dZ&Y w xY w# e)$ r dZ(Y w xY w)+    N)OrderedDictdeque)support)MISSING_C_DOCSTRINGS)import_helper)threading_helper)warnings_helper)requires_limited_api)assert_python_failureassert_python_okrun_python_until_end	_testcapic                 F    | j                  dd      j                  dd      S )Nzutf-8replace )decoder   )errs    L/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/test/test_capi/test_misc.pydecode_stderrr   8   s     ::gy)11$;;    c                 H    	  t        j                  t        d u d      |       S )Nzsubinterpreters required)unittestskipIf_interpreters)meths    r   requires_subinterpretersr   <   s,    H78??=D0577;= =r   c                     	 | S N selfs    r   testfunctionr#   B   s
    Kr   c                   P    e Zd Zej	                  e      Zej	                  e      Zy)InstanceMethodN)__name__
__module____qualname__r   instancemethodidr#   r    r   r   r%   r%   G   s"    		!	!"	%B++L9Lr   r%   c                       e Zd Zd Z ej
                         d        Zd Z ej                  e
d      d        Z ej                  e
d      d        Z ej                  ed      d        Zd	 Zd
 Zd Zd Zd Zd Zd Z ej                   eed      d      d        Z ej                   eed      d      d        Zd Z ej8                  d      d        Z ej8                  d      d        Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-d) Z.d* Z/d+ Z0d, Z1d- Z2d. Z3d/ Z4d0 Z5d1 Z6 e7jp                  e92      d3        Z:d4 Z;d5 Z<d6 Z=d7 Z>d8 Z?d9 Z@d: ZAd; ZBd< ZCd= ZDd> ZEd? ZFd@ ZGdA ZHdB ZIdC ZJdD ZKdE ZLdF ZMyG)HCAPITestc                 <   t               }| j                  t        |      |j                                | j                  |j	                         |u        | j                  |j                  j
                  t        j
                         | j                  t         j                  j
                  t        j
                         dt         j                  _        | j                  t        j                  d       | j                  t        t        |j                  dd       y )Ntest	attribute)
r%   assertEqualr*   
assertTruer#   __doc__r/   assertRaisesAttributeErrorsetattrr"   insts     r   test_instancemethodzCAPITest.test_instancemethodM   s    D4779-))+t34**22L4H4HI44<<l>R>RS06##-//8.'43D3DkSYZr   c                     t        j                  d      }t        d|      \  }}|\  }}}| j                  |d       dj	                         }| j                  |j                         j                  |      |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.crash_no_current_thread()
        -cr   zFatal Python error: PyThreadState_Get: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL))textwrapdedentr   r0   encoder1   rstrip
startswith)r"   code
run_result	_cmd_line_rcoutr   msgs           r    test_no_FatalError_infinite_loopz)CAPITest.test_no_FatalError_infinite_loopX   s{        !5T4 @
I"S#c"; =CFH	 	
 	

//4	r   c                 L    | j                  t        t        j                         y r   )r3   
ValueErrorr   !make_memoryview_from_NULL_pointerr!   s    r   !test_memoryview_from_NULL_pointerz*CAPITest.test_memoryview_from_NULL_pointern   s    *i&Q&QRr   z(_posixsubprocess required for this test.c                 v    G d dt               }| j                  t        d      5  t        j                  d |       ddddd	d
ddddddddddddddd       d d d         G d dt               }| j                  t        t        j                  d |       ddddd	d
ddddddddddddddd       y # 1 sw Y   YxY w)Nc                       e Zd Zd Zy)1CAPITest.test_seq_bytes_to_charp_array.<locals>.Zc                      yN   r    r!   s    r   __len__z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__u       r   Nr&   r'   r(   rQ   r    r   r   ZrM   t       r   rT   indexingrP   TrP                  	   
                  F            c                       e Zd Zd Zd Zy)rM   c                 "    t         j                  S r   )sysmaxsizer!   s    r   rQ   z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__|   s    {{"r   c                      y)N   xr    )r"   is     r   __getitem__z=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__~       r   N)r&   r'   r(   rQ   ro   r    r   r   rT   z1CAPITest.test_seq_bytes_to_charp_array.<locals>.Z{   s    #r   )objectassertRaisesRegex	TypeError_posixsubprocess	fork_execr3   MemoryErrorr"   rT   s     r   test_seq_bytes_to_charp_arrayz&CAPITest.test_seq_bytes_to_charp_arrayq   s    	 	 ##Iz: 	k&&ACVAa!AbBr"T$rRWXZ[]^`acdik	k	 	
 	+'7'A'AACVAa!AbBr"T$rRWXZ[]^`acdi	k	k 	ks   1B//B8c                      G d dt               }| j                  t        t        j                   |       dgdddddd	d
dddddddddddddd       y )Nc                       e Zd Zd Zy)-CAPITest.test_subprocess_fork_exec.<locals>.Zc                      yrO   r    r!   s    r   rQ   z5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__   rR   r   NrS   r    r   r   rT   r{      rU   r   rT      1TrW   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   Frd   re   rf   rg   )rq   r3   rs   rt   ru   rw   s     r   test_subprocess_fork_execz"CAPITest.test_subprocess_fork_exec   sd    	 	
 	)%5%?%?#tfT&1Qq2bBr$tTVW\]_`bcefhin	pr   z6Signature information for builtins requires docstringsc                 D   | j                  t        j                  j                  d        | j                  t        j                  j                  d        | j                  t        j
                  j                  d        | j                  t        j
                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d       y )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))r0   r   no_docstringr2   __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_newlinesr!   s    r    test_docstring_signature_parsingz)CAPITest.test_docstring_signature_parsing   s    	//77>//BBDI22::DA22EEtL99AA.	099LLdSCCKK7	
 	CCVVX\]DDLL<	 	DDWWY]^;;CC3	5;;NNPcdFFNNPTUFFYY	! 	NNVVM	ONNaa%	'r   c                 x   t         j                  } |       } |       }| j                  ||z  d||f       | j                  |dz  d|df       | j                  d|z  dd|f       |}||z  }| j                  |d||f       |}|dz  }| j                  |d|df       d}||z  }| j                  |dd|f       y )Nmatmul*   imatmul)r   
matmulTyper0   )r"   Mm1m2os        r   &test_c_type_with_matrix_multiplicationz/CAPITest.test_c_type_with_matrix_multiplication   s      SSb8R"45b8R"45b8R"45	RYB/0	RYB/0	RXr2./r   c                     t         j                         }| j                  |j                  d      d       | j                  |j                  dd      d       y )NrP   )rP   NrX   )rX   rX   )r   ipowTyper0   __ipow__)r"   r   s     r   test_c_type_with_ipowzCAPITest.test_c_type_with_ipow   sE      A	2Aq)62r   c                 p   t         j                  rCt        j                  d      }t	        d|      \  }}}t        |      }| j                  |d       y | j                  t              5 }t        j                          d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r:   a#  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)r   Py_DEBUGr;   r<   r   r   assertRegexr3   SystemErrorr   return_null_without_errorstr	exceptionr"   r@   rcrD   r   cms         r   test_return_null_without_errorz'CAPITest.test_return_null_without_error   s     ?? $ D 1t<LBS$CS45 "";/ 623356S.JK6 6   )B,,B5c                 p   t         j                  rCt        j                  d      }t	        d|      \  }}}t        |      }| j                  |d       y | j                  t              5 }t        j                          d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            r:   aq  Fatal 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<   r   r   r   r3   r   r   return_result_with_errorr   r   r   s         r   test_return_result_with_errorz&CAPITest.test_return_result_with_error   s    ?? $ D 1t<LBS$CS78  "";/ 522245S.GH5 5r   c                     t        j                  d      }t        d|      \  }}}t        |      }d|vr| j	                  |d       y | j                  d|       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.getitem_with_error({1: 2}, 1)
        r:   zSystemError: a  Fatal 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   r   r   assertInr"   r@   r   rD   r   s        r   test_getitem_with_errorz CAPITest.test_getitem_with_error  se         -T48CC #%S	C
D MMCSIr   c                 ,    t         j                          y r   )r   test_buildvalue_Nr!   s    r   r   zCAPITest.test_buildvalue_N-  s    ##%r   c                 r    t        j                  |      }t        d|      \  }}}| j                  |d       y )Nr:   s`   _testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)r;   r<   r   r   r   s        r   check_negative_refcountz CAPITest.check_negative_refcount0  s9     t$,T48C;	<r   negative_refcountz"need _testcapi.negative_refcount()c                 *    d}| j                  |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        r   r"   r@   s     r   test_negative_refcountzCAPITest.test_negative_refcount:       	$$T*r   decref_freed_objectz$need _testcapi.decref_freed_object()c                 *    d}| j                  |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.decref_freed_object()
        r   r   s     r   test_decref_freed_objectz!CAPITest.test_decref_freed_objectF  r   r   c                 F    ddl m} d }t        d      D ]  } ||f      } y )Nr   MyList  )r   r   range)r"   r   Lrn   s       r   test_trashcan_subclasszCAPITest.test_trashcan_subclassR  s*     	%t 	AtA	r   cpuc                 .    | j                  t               y r   )do_test_trashcan_python_classlistr!   s    r   test_trashcan_python_class1z$CAPITest.test_trashcan_python_class1Z  s    **40r   c                 2    ddl m} | j                  |       y )Nr   r   )r   r   r   )r"   r   s     r   test_trashcan_python_class2z$CAPITest.test_trashcan_python_class2^  s    $**62r   c                      G d d|      }dD ]b  }d }t        d      D ]  } ||f      }||_         |r|f}| j                  |j                  d       ~| j	                  |j                  d       d y )Nc                   ,     e Zd ZdZ fdZ fdZ xZS )6CAPITest.do_test_trashcan_python_class.<locals>.PyListr   c                 H    xj                   dz  c_         t        |   |  y rO   )numsuper__init__)r"   args	__class__s     r   r   z?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__k  s    " $'r   c                 0    xj                   dz  c_         y rO   )r   r"   r   s    r   __del__z>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__n  s    "r   )r&   r'   r(   r   r   r   __classcell__r   s   @r   PyListr   g  s     C(# #r   r   )r   rP   i   r   )r   attrassertGreaterr   r0   )r"   baser   parityr   rn   s         r   r   z&CAPITest.do_test_trashcan_python_classc  s    	#T 	#  	,FA 5\ A4L Dvzz1-VZZ+	,r   c                     | j                  t        j                  j                  d       | j                  t        j                  j                  d       y )Nsomedocz(arg1, arg2))r0   r   HeapDocCTyper2   r   r!   s    r   &test_heap_ctype_doc_and_text_signaturez/CAPITest.test_heap_ctype_doc_and_text_signature  s:    //77C//BBNSr   c                 X    | j                  t        j                  j                  d        y r   )r0   r   NullTpDocTyper2   r!   s    r   test_null_type_doczCAPITest.test_null_type_doc  s    0088$?r   c                 0    G d dt         j                        } |       }t        j                  |      }| j	                  |j
                  d       | j	                  |j                  d       ~| j	                  |dz
  t        j                  |             y )Nc                        e Zd Z fdZ xZS )`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclassc                 0    d| _         t        | 	          y Nre   value2r   r   r   s    r   r   ziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__        "r   r&   r'   r(   r   r   r   s   @r   HeapGcCTypeSubclassr         # #r   r   r^   re   rP   )r   HeapGcCTyperj   getrefcountr0   valuer   )r"   r   subclass_instancetype_refcnts       r   :test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncezCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once  s    	#)"7"7 	#
 01oo&9: 	*00"5*1126 q#//:M*NOr   c                     G d dt         j                         G fdd              }t        j                        }t        j                        }| j	                  |j
                  d       | j	                  |j                  d       ~t        j                  r| j	                  |j                         n| j	                  |dz
  j                         | j	                  |dz   j                         | j	                  |dz
  t        j                               | j	                  |t        j                               y )Nc                        e Zd Z fdZ xZS )dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Ac                 0    d| _         t        | 	          y r   r   r   s    r   r   zmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__  r   r   r   r   s   @r   Ar     r   r   r   c                   ,     e Zd Z fdZfdZ xZS )dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bc                 "    t         |           y r   )r   r   r   s    r   r   zmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__  s     "r   c                 |    | _         t        j                        _        t        j                        _        y r   )r   rj   r   refcnt_in_del)r"   r   Bs    r   r   zlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__  s*    !""%//!"4"%//!"4r   )r&   r'   r(   r   r   r   )r   r   r   s   @r   r   r     s    #5 5r   r   r^   re   rP   )
r   r   rj   r   r0   r   r   r   r   r   )r"   r   r   new_type_refcntr   r   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_once  s   	#	%% 	#
	5 	5 Cooa(//!, 	*00"5*1126  [!//:[1_aoo>1,aoo> 	q#//!*<= 	#//!*<=r   c                 Z   t         j                         }d|_        | j                  |j                  d       | j                  |j                  |j
                         | j                  |j                  ddi       t         j                         }| j                  i |j
                         y Nr   foo)r   HeapCTypeWithDictr   r0   dictobj__dict__r6   s     r   test_heaptype_with_dictz CAPITest.test_heaptype_with_dict  s}    **,2&t}}5r{3**,T]]+r   c                 ~   t         j                         }d|_        | j                  |j                  d       | j                  |j                  ddi       t         j                         }| j                  i |j                         t         j                         }t         j                         }||_        ||_        ~~y r   )r   HeapCTypeWithManagedDictr   r0   r  ba)r"   r7   r  r  s       r   test_heaptype_with_managed_dictz(CAPITest.test_heaptype_with_managed_dict  s    1132&4113T]]+..0..0qr   c                 T     G d dt         j                        } |       }||_        ~y )Nc                       e Zd Zy)2CAPITest.test_sublclassing_managed_dict.<locals>.CNr&   r'   r(   r    r   r   Cr        r   r  )r   r  spam)r"   r  rn   s      r   test_sublclassing_managed_dictz'CAPITest.test_sublclassing_managed_dict  s'    		22 	 Cr   c                 Z   t         j                         }d|_        | j                  |j                  d       | j                  |j                  |j
                         | j                  |j                  ddi       t         j                         }| j                  i |j
                         y r   )r   HeapCTypeWithNegativeDictr   r0   r  r  r6   s     r    test_heaptype_with_negative_dictz)CAPITest.test_heaptype_with_negative_dict  s}    2242&t}}5r{3224T]]+r   c                     t         j                         }t        j                  |      }| j	                   |       |       | j	                  |j
                  |       y r   )r   HeapCTypeWithWeakrefweakrefrefr0   weakreflistr"   r7   r  s      r   test_heaptype_with_weakrefz#CAPITest.test_heaptype_with_weakref  sF    --/kk$%))3/r   c                     t         j                         }t        j                  |      }| j	                   |       |       y r   r   HeapCTypeWithManagedWeakrefr  r  r0   r  s      r   "test_heaptype_with_managed_weakrefz+CAPITest.test_heaptype_with_managed_weakref  s0    446kk$%r   c                      G d dt         j                        } |       }t        j                  |      }| j	                   |       |       y )Nc                       e Zd Zy)5CAPITest.test_sublclassing_managed_weakref.<locals>.CNr  r    r   r   r  r"    r  r   r  r  )r"   r  r7   r  s       r   !test_sublclassing_managed_weakrefz*CAPITest.test_sublclassing_managed_weakref  s=    		55 	 skk$%r   c                     G d dt         j                  t         j                        } G d dt         j                  t         j                        }||fD ]n  } |       }t        j                  |      }| j                   |       |       ||_        ~t        j                   |             }| j                   |       d        p y )Nc                       e Zd Zy)3CAPITest.test_sublclassing_managed_both.<locals>.C1Nr  r    r   r   C1r&    r  r   r'  c                       e Zd Zy)3CAPITest.test_sublclassing_managed_both.<locals>.C2Nr  r    r   r   C2r)    r  r   r*  )r   r  r  r  r  r0   r  assertIs)r"   r'  r*  clsr7   r  s         r   test_sublclassing_managed_bothz'CAPITest.test_sublclassing_managed_both  s    	66	8Z8Z 		33Y5Z5Z 	 8 	'C5D++d#CSUD)DI++ce$CMM#%&	'r   c                 f    t         j                         }t        |      }| j                  |d       y )Ns   1234)r   HeapCTypeWithBufferbytesr0   )r"   r7   r  s      r   test_heaptype_with_bufferz"CAPITest.test_heaptype_with_buffer  s)    ,,.$KG$r   c                 P   t         j                         }t        j                  t         j                        }| j	                  |j
                  d       | j	                  |j                  d       ~| j	                  |dz
  t        j                  t         j                               y Nr^   re   rP   )r   HeapCTypeSubclassrj   r   r0   r   r   )r"   r   r   s      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ooi&A&AB 	*00"5*1126 q#//):U:U*VWr   c                 &   t         j                         }t        j                  t         j                        }t        j                  t         j                        }| j                  |j                  d       | j                  |j                  d       ~t        j                  r+| j                  |t         j                  j                         n-| j                  |dz
  t         j                  j                         | j                  |dz   t         j                  j                         | j                  |dz
  t        j                  t         j                               | j                  |t        j                  t         j                               y r3  )r   HeapCTypeSubclassWithFinalizerrj   r   r4  r0   r   r   r   r   r   )r"   r   r   r   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!  s   %DDFooi&N&NO//)*E*EF 	*00"5*1126   [)*R*R*`*`a[1_i.V.V.d.de1,i.I.I.W.WX 	q#//):b:b*cd 	#//):U:U*VWr   c                     t         j                         }| j                  |j                  d       d|_        | j                  |j                  d       |`| j                  |j                  d       y )Nr^   r`   r   )r   HeapCTypeSetattrr0   pvaluer   )r"   objs     r   test_heaptype_with_setattroz$CAPITest.test_heaptype_with_setattro<  sX    ((*R(	R(IQ'r   c                    t         j                  }| j                  t        |t                     t         j                  |      }| j                  |t               | j                  |j                  d       | j                  t	        |      |        |ddi       }| j                  |t               | j                  |j                  d       y )NHeapCTypeViaMetaclassPyClassViaMetaclassr    )
r   HeapCTypeMetaclassr1   
issubclasstypepytype_fromspec_metaassertIsInstancer0   r&   r+  r"   	metaclassts      r   #test_heaptype_with_custom_metaclassz,CAPITest.test_heaptype_with_custom_metaclassD  s    00	
9d34 **95a&%<=d1gy) +R4a&%:;r   c                    t         j                  }| j                  t        |t                     t         j                  |      }| j                  |t               | j                  |j                  d       | j                  t	        |      |       | j                  t        d      5   |ddi        d d d        y # 1 sw Y   y xY w)Nr?  zcannot create .* instancesr@  r    )r   HeapCTypeMetaclassNullNewr1   rB  rC  rD  rE  r0   r&   r+  rr   rs   rF  s      r   ,test_heaptype_with_custom_metaclass_null_newz5CAPITest.test_heaptype_with_custom_metaclass_null_newS  s    77	
9d34 **95a&%<=d1gy) ##I/KL 	5+R4	5 	5 	5s   (B<<Cc                    t         j                  }| j                  t        t         j                  t                     d}| j                  t        |      5  t         j                  |      }d d d        y # 1 sw Y   y xY w)Nz1Metaclasses with custom tp_new are not supported.)r   HeapCTypeMetaclassCustomNewr1   rB  rC  rr   rs   rD  )r"   rG  rE   rH  s       r   .test_heaptype_with_custom_metaclass_custom_newz7CAPITest.test_heaptype_with_custom_metaclass_custom_newb  s`    99	
9#H#H$OPA##Is3 	:..y9A	: 	: 	:s   A55A>c                     t         j                  } G d d|      }t        j                  dt        f      5  t         j                  |      }d d d        | j                  t        |             | j                  ||       y # 1 sw Y   7xY w)Nc                       e Zd Zy)FCAPITest.test_heaptype_with_custom_metaclass_deprecation.<locals>.BaseNr  r    r   r   BaserR  q  r  r   rS  )rG  z8.* _testcapi.Subclass .* custom tp_new.*in Python 3.14.*)	r   rN  r	   check_warningsDeprecationWarningmake_type_with_baser1   rB  rE  )r"   rG  rS  subs       r   /test_heaptype_with_custom_metaclass_deprecationz8CAPITest.test_heaptype_with_custom_metaclass_deprecationk  s~    99	
	Y 	 ++KM_` 	6 //5C	6 	
3-.c9-	6 	6s   BBc                 L   | j                  t              5   G d dt        j                  t        j                        }d d d        | j                  t              5   G d dt        j                  t        j                        }d d d        y # 1 sw Y   PxY w# 1 sw Y   y xY w)Nc                       e Zd Zy)MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both1Nr  r    r   r   Both1r[        r   r\  c                       e Zd Zy)MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both2Nr  r    r   r   Both2r_    r]  r   r`  )r3   rs   r   r  r  )r"   r\  r`  s      r   5test_multiple_inheritance_ctypes_with_weakref_or_dictz>CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict|  s    y) 		66	8S8S 	 y) 		33Y5S5S 	 		 		 	s   )B)BBB#c                 0   | j                  t              5   G d dt        j                  t              }d d d        | j                  t              5   G d dt        j
                  t              }d d d         G d dt        j                  t              } G d dt        j                  t              } |       }|j                  d	       t        |j                          |       }|j                  d	       t        |j                         t        j                  t        j                  fD ]K  }t        j                  t        j
                  fD ]  } G d
 d||      }  G d d||      }	 G d d||      }
M y # 1 sw Y   KxY w# 1 sw Y   xY w)Nc                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C1Nr  r    r   r   r'  rd    r]  r   r'  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C2Nr  r    r   r   r*  rf    r]  r   r*  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C3Nr  r    r   r   C3rh    r  r   ri  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C4Nr  r    r   r   C4rk    r  r   rl  r   c                       e Zd Zy)[CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.SNr  r    r   r   Srn    s    r   ro  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.B1Nr  r    r   r   B1rq    r]  r   rr  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.B2Nr  r    r   r   B2rt    r]  r   ru  )r3   rs   r   r  r   r  r  r  appendr   r  __weakref__)r"   r'  r*  ri  rl  r7   r,  cls2ro  rr  ru  s              r   Gtest_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtinzPCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin  sD   y) 	Y00$ 	 y) 	Y33T 		33T 		66 	 tADMMtAD66	8]8]^ 	C"44i6T6TU T R R 	+	 		 	s   E>F>FFc                     t        d      D ]P  }| j                  |      5  | j                  t              5  t        j                  |       d d d        d d d        R y # 1 sw Y   xY w# 1 sw Y   ixY w)NrX   )variant)r   subTestr3   r   r   create_type_from_repeated_slots)r"   r{  s     r   (test_pytype_fromspec_with_repeated_slotsz1CAPITest.test_pytype_fromspec_with_repeated_slots  sy    Qx 	GGg. G&&{3 G==gFGG G	GG GG Gs"   A,A A, A)%A,,A5	categoryc                    t        j                  dd        G d d      }| j                  t              5  t        j                  |      }d d d                }| j                  |j                         d       | j                  t        d      5  d |_        d d d        | j                  |j                         d       d	 |_        | j                  |j                         d
       y # 1 sw Y   xY w# 1 sw Y   ^xY w)Nz-creating immutable classes with mutable bases)   rb   )removec                       e Zd Zd Zy)CCAPITest.test_immutable_type_with_mutable_base.<locals>.MutableBasec                      y)Noriginalr    r!   s    r   r   zHCAPITest.test_immutable_type_with_mutable_base.<locals>.MutableBase.meth  s    !r   N)r&   r'   r(   r   r    r   r   MutableBaser    s    "r   r  r  z-cannot set 'meth' attribute of immutable typec                      y)N
overriddenr    r!   s    r   <lambda>z@CAPITest.test_immutable_type_with_mutable_base.<locals>.<lambda>      r   c                      y)Nchangedr    r!   s    r   r  z@CAPITest.test_immutable_type_with_mutable_base.<locals>.<lambda>  r  r   r  )
warnings_deprecatedassertWarnsrU  r   make_immutable_type_with_baser0   r   rr   rs   )r"   r  ImmutableSubclassinstances       r   %test_immutable_type_with_mutable_basez.CAPITest.test_immutable_type_with_mutable_base  s     	;G	M	" 	" 01 	 ) G G!	 %&*5 ##?A 	? &?"	? 	*5 2)4!	 		? 	?s   C,	C8,C58Dc           	         ddl m} d}d} G d d      }d}|D ]  \  }}}| j                  |||      5  | j                   |||      |       | j                   || |      d	|z          | j                   | ||      |      |       | j                   |||      |       | j                   || |      d	|z          | j                   | ||      |      |       d d d         | j	                  t
        | |d
      d       | j	                  t
        | |d      d       | j	                  t
        |d
d       | j	                  t
        |dd       | j	                  t        |dd       y # 1 sw Y   _xY w)Nr   )pynumber_tobase{   l            c                       e Zd Zd Zd Zy)*CAPITest.test_pynumber_tobase.<locals>.IDXc                     || _         y r   val)r"   r  s     r   r   z3CAPITest.test_pynumber_tobase.<locals>.IDX.__init__  s	    r   c                     | j                   S r   r  r!   s    r   	__index__z4CAPITest.test_pynumber_tobase.<locals>.IDX.__index__  s    xxr   N)r&   r'   r(   r   r  r    r   r   IDXr    s     r   r  ))rX   	0b1111011C0b10000000000000000000000000000000000000000000000000000000000000000)r\   0o1730o2000000000000000000000)r^   12318446744073709551616)   0x7b0x10000000000000000)r   stlt-g     ^@r^   r  )r   r  r|  r0   r3   rs   r   )	r"   r  small_numberlarge_numberr  
test_casesr   small_targetlarge_targets	            r   test_pynumber_tobasezCAPITest.test_pynumber_tobase  s{   -	  	 ;
 1; 		Y,D,4L\J Y  t!DlS  ,!Es\GYZ  \1BD!I<X  t!DlS  ,!Es\GYZ  \1BD!I<XY Y		Y 	)_c%j"E)_c%j"E)_eR@)_eR@+Q?Y Ys   B+E..E8	c                 P    t         j                         }| j                  |d       y Nz<NULL>)r   pyobject_repr_from_nullr0   r"   ss     r   test_pyobject_repr_from_nullz%CAPITest.test_pyobject_repr_from_null  s     --/H%r   c                 P    t         j                         }| j                  |d       y r  )r   pyobject_str_from_nullr0   r  s     r   test_pyobject_str_from_nullz$CAPITest.test_pyobject_str_from_null  s     ,,.H%r   c                 P    t         j                         }| j                  |d       y )Ns   <NULL>)r   pyobject_bytes_from_nullr0   r  s     r   test_pyobject_bytes_from_nullz&CAPITest.test_pyobject_bytes_from_null  s     ..0I&r   c                     t         j                  }d} ||      }t        |dd      }| j                  |j                  |j                         y )Ns%   # -*- coding: latin1 -*-
print('¤')
z<string>exec)r   Py_CompileStringcompiler0   	co_consts)r"   _compiler@   resultexpecteds        r   test_Py_CompileStringzCAPITest.test_Py_CompileString  sE    --?$4V4))8+=+=>r   c                 b   t        j                  d      }g }t        t        d      r|j	                  d       t
        j                  dk7  r|j	                  d       |D ]B  }| j                  |      5  | j                  t        |j                  |             d d d        D y # 1 sw Y   OxY w)Nctypesget_native_idPyThread_get_thread_native_idntPy_FrozenMain)name)
r   import_modulehasattr_threadrv  osr  r|  r1   	pythonapi)r"   r  namesr  s       r   test_export_symbolszCAPITest.test_export_symbols  s     ,,X6 7O,LL89 77d?LL) 	AD4( A(8(8$ ?@A A	AA As   4&B%%B.	c                 4    G d d      } |       }t         j                  |       | j                  |j                  i         |       }| j                  |j                  ddi       t         j                  |       | j                  |j                  i        y )Nc                       e Zd Zd Zy)+CAPITest.test_clear_managed_dict.<locals>.Cc                     d| _         y rO   r  r!   s    r   r   z4CAPITest.test_clear_managed_dict.<locals>.C.__init__  s	    r   N)r&   r'   r(   r   r    r   r   r  r    s    r   r  r  rP   )r   clear_managed_dictr0   r  )r"   r  cs      r   test_clear_managed_dictz CAPITest.test_clear_managed_dict  sx    	 	 C$$Q'R(Cc!W-$$Q'R(r   c                    d } G d d      }| j                  t        j                  |      d       | j                  t        j                  |j                        d       | j                  t        j                   |       j                        d       | j                  t        j                  t              d       | j                  t        j                  |      d       y )Nc                       y r   r    r    r   r   function_examplez:CAPITest.test_eval_get_func_name.<locals>.function_example  r  r   c                       e Zd Zd Zy)+CAPITest.test_eval_get_func_name.<locals>.Ac                      y r   r    r!   s    r   method_examplez:CAPITest.test_eval_get_func_name.<locals>.A.method_example"  r  r   Nr&   r'   r(   r  r    r   r   r   r  !      )r   r   r  r  sumrC  )r0   r   eval_get_func_namer  r  r"   r  r   s      r   test_eval_get_func_namez CAPITest.test_eval_get_func_name  s    #	* 	* 	556FG+	-55a6F6FG)	+55ac6H6HI)	+55c:EB55a8&Ar   c                    d } G d d      }| j                  t        j                  |      d       | j                  t        j                  |j                        d       | j                  t        j                   |       j                        d       | j                  t        j                  t              d       | j                  t        j                  |      d       y )Nc                       y r   r    r    r   r   r  z:CAPITest.test_eval_get_func_desc.<locals>.function_example.  r  r   c                       e Zd Zd Zy)+CAPITest.test_eval_get_func_desc.<locals>.Ac                      y r   r    r!   s    r   r  z:CAPITest.test_eval_get_func_desc.<locals>.A.method_example1  r  r   Nr  r    r   r   r   r  0  r  r   r   z()z object)r0   r   eval_get_func_descr  r  r  s      r   test_eval_get_func_descz CAPITest.test_eval_get_func_desc-  s    #	* 	* 	556FG	55a6F6FG	55ac6H6HI	55c:DA55a8)Dr   c                 *   dd l }d }t        j                  |      }| j                  ||j                         | j                  ||j                         | j                  t              5  t        j                  d        d d d        y # 1 sw Y   y xY w)Nr   c                       y r   r    r    r   r   somez-CAPITest.test_function_get_code.<locals>.some?      r   )	typesr   function_get_coderE  CodeTyper0   __code__r3   r   )r"   r  r  r@   s       r   test_function_get_codezCAPITest.test_function_get_code<  su    	 **40dENN3t}}-{+ 	.''-	. 	. 	.s   *B		Bc                    d }t         j                  |      }| j                  |t               | j	                  ||j
                         | j                  t              5  t         j                  d        d d d        y # 1 sw Y   y xY w)Nc                       y r   r    r    r   r   r  z0CAPITest.test_function_get_globals.<locals>.someJ  r  r   )r   function_get_globalsrE  dictr0   __globals__r3   r   )r"   r  globals_s      r   test_function_get_globalsz"CAPITest.test_function_get_globalsI  sp    	 11$7h-4#3#34{+ 	1**40	1 	1 	1    A??Bc                    d }t         j                  |      }| j                  |t               | j	                  ||j
                         | j                  t              5  t         j                  d        d d d        y # 1 sw Y   y xY w)Nc                       y r   r    r    r   r   r  z/CAPITest.test_function_get_module.<locals>.someU  r  r   )r   function_get_modulerE  r   r0   r'   r3   r   )r"   r  modules      r   test_function_get_modulez!CAPITest.test_function_get_moduleT  sn    	 ..t4fc*1{+ 	0))$/	0 	0 	0r  c                    	 	 dddd}t         j                  |      }| j                  |d       | j                  ||j                         | j	                  t
              5  t         j                  d        d d d        y # 1 sw Y   y xY w)NTkw2c                    y r   r    	pos_only1	pos_only2zerooptionalkw1r
  s         r   r  z1CAPITest.test_function_get_defaults.<locals>.some`       r   pr   N)r   function_get_defaultsr0   __defaults__r3   r   r"   r  defaultss      r   test_function_get_defaultsz#CAPITest.test_function_get_defaults_  s    !$!	 	 2248>24#4#45{+ 	2++D1	2 	2 	2s   "BB
c                    	 	 dddd}d}| j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  |d       d d d        | j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  dd       d d d        | j                  t        j                  |      |       | j                  |j                  |       d}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       d}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |        G d d	t              } |d
ddgd f      }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       t        j                  |d        | j                  t        j                  |      d        | j                  |j                  d        y # 1 sw Y   =xY w# 1 sw Y   xY w)NTr	  c                    y r   r    r  s         r   r  z1CAPITest.test_function_set_defaults.<locals>.somer  r  r   r  rP   r    )qrP   Nc                       e Zd Zy)5CAPITest.test_function_set_defaults.<locals>.tuplesubNr  r    r   r   tuplesubr        r   r  rW   r  r  )r0   r   r  r  r3   r   function_set_defaultstuple)r"   r  old_defaultsnew_defaultsr  s        r   test_function_set_defaultsz#CAPITest.test_function_set_defaultsq  sG   !$!	 	 &88>M**L9{+ 	5++D!4	588>M**L9{+ 	3++Ar2	388>M**L9%''l;88>M**L9 ''l;88>M**L9"u"#sT :;''l;88>M**L9 	''d388>E**D1A	5 	5
	3 	3s   "J4K4J>Kc                    	 	 dddd}t         j                  |      }| j                  |ddi       | j                  ||j                         | j	                  t
              5  t         j                  d        d d d        y # 1 sw Y   y xY w)NTr	  c                    y r   r    r  s         r   r  z4CAPITest.test_function_get_kw_defaults.<locals>.some  r  r   r
  r  )r   function_get_kw_defaultsr0   __kwdefaults__r3   r   r  s      r   test_function_get_kw_defaultsz&CAPITest.test_function_get_kw_defaults  s    !$!	 	 55d;E4=14#6#67{+ 	5..t4	5 	5 	5s   $BBc                    	 	 d	ddd}ddi}| j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  |d       d d d        | j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  di        d d d        | j                  t        j                  |      |       | j                  |j                  |       ddi}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       i }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |        G d dt              } |dd i      }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       t        j                  |d        | j                  t        j                  |      d        | j                  |j                  d        y # 1 sw Y   <xY w# 1 sw Y   xY w)
NTr	  c                    y r   r    r  s         r   r  z4CAPITest.test_function_set_kw_defaults.<locals>.some  r  r   r
  rP   rP   rX   r  c                       e Zd Zy)7CAPITest.test_function_set_kw_defaults.<locals>.dictsubNr  r    r   r   dictsubr/    r   r   r0  r  )r0   r   r(  r)  r3   r   function_set_kw_defaultsr  )r"   r  r#  r$  r0  s        r   test_function_set_kw_defaultsz&CAPITest.test_function_set_kw_defaults  sI   !$!	 	 t};;DA<P,,l;{+ 	8..tQ7	8;;DA<P,,l;{+ 	6..q"5	6;;DA<P,,l;y)**4>;;DA<P,,l; **4>;;DA<P,,l; d t}-**4>;;DA<P,,l; 	**46;;DA4H,,d3A	8 	8
	6 	6s   $J5K5J?Kc                 P    G d dt         j                        } |       }d|_        d|_        d|_        | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       |`| j                  |j                         y )Nc                       e Zd ZdZy);CAPITest.test_unstable_gc_new_with_extra_data.<locals>.Data)xyN)r&   r'   r(   	__slots__r    r   r   Datar5    s    "Ir   r9  r^   re      )r   ObjExtraDatar6  r7  extrar0   assertIsNone)r"   r9  ds      r   $test_unstable_gc_new_with_extra_dataz-CAPITest.test_unstable_gc_new_with_extra_data  s    	#9)) 	# Fb!b!"%G!''"r   c                    t         j                  }| j                   |d      t        j                         t        j                  t        dd      5  | j                   |dj                               d       d d d        | j                   |d      t               | j                   |d      t               y # 1 sw Y   BxY w)Ns   stdout   🐍r   s   nonexisting   )
r   sys_getobjectr+  rj   stdoutr   	swap_attrr0   r=   r4   )r"   	getobjects     r   test_sys_getobjectzCAPITest.test_sys_getobject  s    ++	i	*CJJ7sL"5 	CY|':':'<=rB	C 	i/@i(.9		C 	Cs   'B::Cc                 .   t         j                  }dg}dg}	 | j                   |d|      d       | j                  t        j
                  |       | j                   |d|      d       | j                  t        j
                  |       | j                   |dt              d       | j                  t        t        d             | j                   |dt              d       t        j                  t              5  t        `d d d        	 | j                   |dj                         |      d       | j                  t        t        d      |       | j                   |dj                         t              d       | j                  t        t        d             t        j                  t              5  t        t        d       d d d        | j                  t               5   |d|       d d d        y # 1 sw Y   xY w# t        j                  t              5  t        `d d d        w # 1 sw Y   w xY wxY w# 1 sw Y   vxY w# t        j                  t              5  t        t        d       d d d        w # 1 sw Y   w xY wxY w# 1 sw Y   y xY w)Nr   r   s   newattrr   newattrrA  rB  )r   sys_setobjectr0   r+  rj   rI  NULLassertFalser  
contextlibsuppressr4   r=   getattrdelattrr3   UnicodeDecodeError)r"   	setobjectr   r   s       r   test_sys_setobjectzCAPITest.test_sys_setobject  s   ++		
	 Yz591=MM#++u-Yz6:A>MM#++v.Yz48!<WS)45Yz48!<$$^4  K 	+Y|':':'<eDaHMM'#|4e<Y|':':'<dCQGWS,78$$^4 +\*+ 12 	&gu%	& 	&   $$^4  K     + +$$^4 +\*+ + +	& 	&sm   CH <G7BI 6H<$
J7H H9H-$	H9-H62H9<IJ"I<3	J<JJJN)Nr&   r'   r(   r8   r   requires_subprocessrF   rJ   r   
skipUnlessrt   rx   r~   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   requires_resourcer   r   r   r   r   r   r   r  r	  r  r  r  r  r#  r-  r1  r5  r8  r=  rI  rL  rO  rX  ra  ry  r~  r	   ignore_warningsrU  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r*  r2  r?  rG  rS  r    r   r   r,   r,   K   sy   	[ !W  " #*S X)+UVk Wk" X)+UVp Wp X__)MO''O''R0"3K: HDJ<&< X,?@=?+?+ X,AB?A+A+ Wu%1 &1 Wu%3 &3,8T@P"&>P,,0&
&'"%

XX6(<5:."@G %_$$.@A5 B56@<&&'?A.)BE.	1	02$/2b5$/4b#:&r   r,   c                   B    e Zd Z	 ed        Zd Zd Zd Zd Zd Z	d Z
y)	TestHeapTypeRelativec                 0     fd}t        dddddddd	t        j                  t        j                  dz
  t        j                  dz   h      }|D ]9  }|D ]2  }t        ||
      }  j                  di |5   |di | d d d        4 ; y # 1 sw Y   AxY w)Nc                    t         j                  | |       \  }}}}}}|dk(  r9
j                  |j                  |j                         
j                  |d       nd|j                  df|df||z   df||z   df|j                  dfg}t	        |t        j                  d            }	
j                  ||	d	|	 
       
j                  |j                  ||z          
j                  ||z
  t         j                         
j                  |t         j                  z  d       
j                  |t         j                  z  d       y )Nr   )r   zstart of objectzend of base datazsubclass datazend of requested subcls datazend of reserved subcls datazend of object)keyz$Offsets not in expected order, got: rE   )	r   make_sized_heaptypesr0   __basicsize__sortedoperator
itemgetter
assertLessALIGNOF_MAX_ALIGN_T)extra_base_size
extra_sizerS  Subr  data_ptrdata_offset	data_sizeoffsetsordered_offsetsr"   s             r   checkz@TestHeapTypeRelative.test_heaptype_relative_sizes.<locals>.check#  s\   ..#j[2 BD#x;	
 Q  !3!3S5F5FG  A.
 +'');< /2 :-/MN 9,.KL&&8 #)h6I6I!6L"M  _>>OP ! R
   !2!2K)4KL 	J 6 ) = =? [9+H+HH!LY)F)FFJr   r   rP   rX   r     r[   r\   r  re  rf  r    )r`  rq   r_  r  r|  )r"   rm  sizesre  rf  r   s   `     r   test_heaptype_relative_sizesz1TestHeapTypeRelative.test_heaptype_relative_sizes   s    "	KH 1aAq!S,,,,Q.,,Q.0 1  % 	"O# "
O'13!T\\)D) "MDM" ""	"" "s   6	BBc                 n    	 t         j                  ddd      }| j                  t        |      g d       y )NrP   rX   r  r-  )r   HeapCCollectionr0   r   )r"   
collections     r   test_HeapCCollectionz)TestHeapTypeRelative.test_HeapCCollectionR  s.    @..q!Q7
j)95r   c                 D   	 t        ddddddddt        j                  t        j                  dz
  t        j                  dz   h      }|D ]  }| j                  |	      5  t        j                  t        j                  | dd      } |ddd      }|j                          | j                  t        |      g d
       |j                         }| j                  t        |      |       | j                  t        |      dhk  d|       d d d         y # 1 sw Y   xY w)Nr   rP   rX   r  rn  r[   r\   r  )rf  r-  zgot )r`  rq   r_  r|  r   subclass_var_heaptypers  set_data_to_3sr0   r   get_dataassertGreaterEquallenr1   set)r"   rp  rf  rg  rt  mems         r   test_heaptype_inherit_itemsizez3TestHeapTypeRelative.test_heaptype_inherit_itemsizeW  s   ;1aAq!S,,,,Q.,,Q.0 1   
	AJ4 	A55--
{AqB Aq\
))+  j!19= ))+''C*=CQC4w@	A 	A
	A	A 	As   B,DD	c                     | j                  t        d      5  t        j                  t        dd       d d d        y # 1 sw Y   y xY w)NzACannot extend variable-size class without Py_TPFLAGS_ITEMS_AT_ENDr]  r   )r3   r   r   subclass_heaptypeintr!   s    r   !test_heaptype_invalid_inheritancez6TestHeapTypeRelative.test_heaptype_invalid_inheritancei  sE    {$;  < 	4 ''R3	4 	4 	4s	   =Ac                    	 t        ddddddddt        j                  t        j                  dz
  t        j                  dz   h      }|D ]  }|D ]  }|D ]N  }| j                  |||	      5  ||k  rt        j                  || |d
      }|j                         d   } |       }| j                  |j                  |j                                |j                  d       | j                  |j                  |j                                | j                  |j                         d       d|_        | j                  |j                  |j                                | j                  |j                         d       | j                  |j                         |j                         | j                  |j                         |j                         | j                  t              5  |j!                          d d d        | j                  t              5  |j#                  d       d d d        n7| j                  t              5  t        j                  || |d
      }d d d        | j                  t              5  t        j                  |||d
      }d d d        d d d        Q | j                  ||      5  | j                  t              5  t        j                  || dd
      }d d d        d d d          y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   xY w)Nr   rP   rX   r  rn  r[   r\   r  )re  rf  offsetTra   rb   ro  )r`  rq   r_  r|  r   make_heaptype_with_membermror0   membget_membset_membrz  get_memb_offsetrc  r3   r   get_memb_relativeset_memb_relative)r"   rp  re  rf  r  rg  rS  r  s           r   test_heaptype_relative_membersz3TestHeapTypeRelative.test_heaptype_relative_memberso  s'   ;1aAq!S,,,,Q.,,Q.0 1  %  	DO# D
# KFoR\ekl K!J."+"E"E /*fd#LC#&779Q<D'*uH ,,X]]H<M<M<OP$--b1 ,,X]]H<M<M<OP ,,X->->-@"E,.HM ,,X]]H<M<M<OP ,,X->->-@"E 33H4L4L4NPTPbPbc OOH,D,D,FHYHYZ!%!2!2;!? = ( : : <=!%!2!2;!? > ( : :1 => > "&!2!2;!? P&/&I&I$3j[&$'PP "..{; K"+"E"E /VT#KCK/K KK6 \\/j\Y D**;7 D'AA+j["dDDD D9D 	D$= => >P PK K/K K6D DD Ds   .E9L3	'L8L3	L'L3	LL3	<L'L3	;MM 	+MLL3	LL3	L$ L3	'L0,L3	3L= M	MMc                    | j                  t        d      5  t        j                  dddd       d d d        | j                  t        d      5  t        j                  dddd       d d d        | j                  t        d      5  t        j                  dddd       d d d        t        j                  dddd      } |       }| j                  t        d      5  |j	                          d d d        | j                  t        d	      5  |j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ^xY w# 1 sw Y   y xY w)
Nz3With Py_RELATIVE_OFFSET, basicsize must be negativer   i  Tz.Member offset out of range \(0\.\.-basicsize\)r  r  z,PyMember_GetOne used with Py_RELATIVE_OFFSETz,PyMember_SetOne used with Py_RELATIVE_OFFSET)rr   r   r   r  r  r  )r"   rg  r  s      r   %test_heaptype_relative_members_errorsz:TestHeapTypeRelative.test_heaptype_relative_members_errors  sb   ##FH 	B //4DA	B ##NP 	C//2tTB	C ##NP 	A//2r4@	A 11!RDA5##LN 	)&&(	) ##LN 	*&&q)	* 	*!	B 	B	C 	C	A 	A	) 	)	* 	*s;   D%D1D=E	
E%D.1D:=E	EEc                    	 | j                  t              5  t        j                  d        d d d        | j                  t              5  t        j                  d       d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY wNr   )r3   rs   r   pyobject_getitemdatar!   s    r   test_pyobject_getitemdata_errorz4TestHeapTypeRelative.test_pyobject_getitemdata_error  sp    By) 	1**40	1 y) 	. **1-	. 	.	1 	1	. 	.s   A)
A5)A25A>N)r&   r'   r(   r
   rq  ru  r~  r  r  r  r  r    r   r   rY  rY    s9    7/" /"b6
A$4&DP**.r   rY  c                       e Zd Zd ZddZ ej                         d        Zd Zd Z	d Z
 G d d	ej                        Z ej                         d
        Z ej                         d        Zed        Zy)TestPendingCallsc                     fd}t        |      D ]C  }t        j                  t        j                         dz         	 t        j                  |      rD y )Nc                  (     j                  d        y r   rv  )ls   r   callbackz6TestPendingCalls.pendingcalls_submit.<locals>.callback  s     HHTNr   g{Gz?)r   timesleeprandomr   _pending_threadfunc)r"   r  nr  rn   s    `   r   pendingcalls_submitz$TestPendingCalls.pendingcalls_submit  sO    	
 q 	AJJv}}t+, 00: 	r   Nc                     d}t        |      |k7  rj	 t	        d      D ]  }||z  }	 |r|j
                  j                         sA|dz  }| j                  |dk  d|t        |      fz         t        |      |k7  rjy )Nr   r   rP   i'  z(timeout waiting for %i callbacks, got %i)r{  r   verboseprintr   eventis_setr1   )r"   r  r  contextcountrn   r  s          r   pendingcalls_waitz"TestPendingCalls.pendingcalls_wait  s    !fk 4[ aCw}}335QJEOOEEM:As1v;FH !fk r   c                 
   d}g } G d dt               } |       }g |_        d|_        ||j                  z  |_        d|_        t        j                         |_        t        j                         |_	        t        |j                        D cg c]$  }t        j                  | j                  |f      & }}t        j                  |      5  | j                  |j                  ||       d d d        y c c}w # 1 sw Y   y xY w)N    c                       e Zd Zy)8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooNr  r    r   r   r   r    r   r   r   rX   r   targetr   )rq   r  r  nThreads	nFinished	threadingLocklockEventr  r   Threadpendingcalls_threadr   start_threadsr  )r"   r  threadsr   r  rn   s         r   test_pendingcalls_threadedz+TestPendingCalls.test_pendingcalls_threaded  s     &%				> ~~'!) "'"2"235 ##4+C+C*15 5 5 ++G4 	:""799a9	: 	:5	: 	:s   )C4C99Dc                    	 | j                  |j                  |j                         |j                  5  |xj                  dz  c_        |j                  }	 d d d        |j                  k(  r|j                  j                          y y # 1 sw Y   4xY w# |j                  5  |xj                  dz  c_        |j                  }	 d d d        n# 1 sw Y   nxY w|j                  k(  r|j                  j                          w w xY wrO   )r  r  r  r  r  r   r  r  r  r  r|  )r"   r  r  s      r   r  z$TestPendingCalls.pendingcalls_thread  s    		$$$WYY		: ;!!Q&!#--	;
 G,,,!!# -; ; ;!!Q&!#--	; ; ;
 G,,,!!# -s.   &B "B

BD#"C	DC2Dc                 T    g }d}| j                  ||       | j                  ||       y )N@   )r  r  )r"   r  r  s      r   test_pendingcalls_non_threadedz/TestPendingCalls.test_pendingcalls_non_threaded   s.    
   A&q!$r   c                 v    d } |       }| j                  t        j                  |      |j                         y )Nc               3      K   d  y wr   r    r    r   r   genfz0TestPendingCalls.test_gen_get_code.<locals>.genf  s     E   )r0   r   gen_get_codegi_code)r"   r  gens      r   test_gen_get_codez"TestPendingCalls.test_gen_get_code
  s+    f//4ckkBr   c                   J    e Zd Zej                  ZddZd Zd Zd Z	d Z
d Zy)	TestPendingCalls.PendingTaskNc                     || _         || _        || _        t        j                         | _        d | _        d | _        d | _        y r   )	r*   reqnotify_doner  	get_identcreator_tidrequester_tid
runner_tidr  )r"   r  taskidr  s       r   r   z%TestPendingCalls.PendingTask.__init__  s?    DGDH*D(224D!%D"DODKr   c                     t        j                         | _        | j                          | j                  | j	                          y y r   )r  r  r  _runr  r!   s    r   runz TestPendingCalls.PendingTask.run  s8    '113DOIIK+  " ,r   c                 &    | j                   | _        y r   )r  r  r!   s    r   r  z!TestPendingCalls.PendingTask._run$  s    ((DKr   c                 p     t        j                          _         fd j                  d       y )Nc                  z    t        j                         vrj                   d       y j                          y )NTensure_added)r  r  _add_pendingr  )r  r"   worker_tidss   r   r  zBTestPendingCalls.PendingTask.run_in_pending_call.<locals>.callback*  s5    
 &&(;%%hT%B
r   Tr  )r  r  r  r  )r"   r  r  s   ``@r   run_in_pending_callz0TestPendingCalls.PendingTask.run_in_pending_call'  s.    !*!4!4!6D hT:r   c                 F    t        j                  | j                  |f      S )Nr  )r  r  r  )r"   r  s     r   create_threadz*TestPendingCalls.PendingTask.create_thread5  s#    ##//!^ r   c                 b    | j                   #t        j                  d       | j                   "y y N{Gz?)r  r  r  r!   s    r   wait_for_resultz,TestPendingCalls.PendingTask.wait_for_result;  s$    ++%

4  ++%r   )NN)r&   r'   r(   _testinternalcapipending_threadfuncr  r   r  r  r  r  r  r    r   r   PendingTaskr    s+    (;;		#	#	;		!r   r  c                     d}| j                  |      fd}t        j                  |      }t        j                  |g      5  	 d d d        | j                  j                  |       y # 1 sw Y   &xY w)Nz1Spam spam spam spam. Lovely spam! Wonderful spam!c                      t        j                         } j                  | h      }t        j                  |g      5  j                          d d d        y # 1 sw Y   y xY wr   )r  r  r  r   r  r  )tidrH  tasks     r   do_the_workzNTestPendingCalls.test_subthreads_can_handle_pending_calls.<locals>.do_the_workD  sT    %%'C""C5)A!//4 '$$&' ' 's   AA!r  )r  r  r  r   r  r0   r  )r"   payloadr  rH  r  s       @r   (test_subthreads_can_handle_pending_callsz9TestPendingCalls.test_subthreads_can_handle_pending_calls?  sm    E(	'
 K0++QC0 		 	g.	 	s   A--A6c                 p   t        j                         }| j                  t        j                         j                  |       t               t               t        j                         fd}fdfd}fdfd}g }t        d      D ]2  }| j                  d| ||      }|j                  |        ||       4 j                          fd	}d
fd}	t        d      D 
cg c]  }
t        j                  |	       }}
t        j                  |      5  	 |D cg c]  }|j                   }}t        d      D 
cg c]  }
t        j                  ||f       }}
t        j                  |      5  	 	 d d d         |        d	 d d d        |D cg c]  }|j                   }}| j!                  ||       |D ]  }| j#                  d|j$                         5  | j'                  |j(                  |       | j'                  |j(                  |j                         | j!                  |j(                  |       d d d         y c c}
w c c}w c c}
w # t        $ r d w xY w# 1 sw Y   xY w# t        $ r d w xY w# 1 sw Y   xY wc c}w # 1 sw Y   xY w)Nc                 J    j                  |        j                  d       y )NTr  )r  _active_queues    r   	queue_putzQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_putY  s    MM$NN4 r   c                  d    	 j                         } | S # t        $ r t        j                  w xY wr   )popleft
IndexErrorqueueEmpty)r  r  s    r   	queue_getzQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_get\  s6    "~~' K  "kk!"s    /c                  l     j                           s	 j                          y y # t        $ r Y y w xY wr   )popreleaseRuntimeError)r  
_done_locks   r   queue_task_donezWTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_task_doneb  s1    KKM3&&(  $ 3s   ' 	33c                  
      S r   r    )r  s   r   queue_emptyzSTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_emptyi  s    :r   c                  F     j                           j                          y r   )acquirer  )r  s   r   
queue_joinzRTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_joink  s      r   re   zrequest )r  r  r  c                 r    	 ry 	         }|j                  |        # t         j                  $ r Y y w xY wr   )r  r  r  )r  r  doner  s     r   	add_taskszQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.add_tasks{  sE    $;D ((5 
 {{ s     66Fc                              s  ry t        j                  d               s  st        j                  d        sy y r  )r  r  )r  r   s   r   	run_taskszQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.run_tasks  s7    !m

4  "m
 

4  r   r  r  r  Tztask )r  r  r0   main_threadidentr   r  r   r  rv  r  r  r   r  BaseExceptionr  assertNotInr|  r*   assertNotEqualr  )r"   main_tidr  r  r  tasksrn   r  r  r  _worker_threadsrH  r  r  runner_tidsr  r  r  r  r   r  s                   @@@@@@r   -test_many_subthreads_can_handle_pending_callsz>TestPendingCalls.test_many_subthreads_can_handle_pending_callsO  s   &&(..066A '^^%
	!		3		! r 	A##qcN+ $ D
 LLdO	 		6 	! $)8- $**)< - -++N; 	0>?1qww??$)!H.  %++9K>R . .%33G<  	& .33q||33;/ 	BDdggY/0 B##D$6$6A##D$6$6H  !3!3[AB B	B1-
 @.
 ) #  ! !	 	& 4B Bsy   9I -J/J3I%JI*4JI?J,J'6AJ,%
J/I<<I??J	JJJJ$,J5	c                 	    d}dt        j                         t        j                  d        fd} j                  d      5   |       \   |       \  t	        j                         dz   fd}t        j                  |      }t        j                  |g      5  t        j                  d	       t        j                        }t        j                  d
       d d d         j                  t                     d d d         j                  d      5   |       \   |       \  t	        j                         dz   fd}t        j                  |      }t        j                  |g      5  t        j                  d	       t        j                        }t        j                  d
       d d d         j                  t                     d d d         j                  d      5   |       \   |       \   |       \  }t	        j                         dz   fd}ddt        j                  ffd	}t        j                  |      }	t        j                  |      }
t        j                  |	|
g      5  s	 st        j                  d
       s:t	        j                   d       t	        j                         kD  rt#        d      s:t        j                  |d	      }d d d        t        j%                  d      } j                  |t                     d d d         j                  d      5   |       \   |       \   |       \  }t	        j                         dz   fd}ddt        j                  ffd	}fd}t        j                  |      }	t        j                  |      }
t        j                  |      }t        j                  |	|
|g      5  	 d d d        t        j                  |d	      }t        j%                  |d      } j                  |t                     d d d        y # 1 sw Y   xY w# 1 sw Y   zxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   rxY w# 1 sw Y   xY w# 1 sw Y   y xY w)N   r   zif True:
            import json
            import os
            import threading
            import time
            import _testinternalcapi
            from test.support import threading_helper
            c                       t        j                         \   j                   fd       j                  fd        fS )Nc                  .    t        j                         S r   r  close)rs   r   r  zTTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe.<locals>.<lambda>      BHHQK r   c                  .    t        j                         S r   r  )ws   r   r  zTTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe.<locals>.<lambda>  r  r   )r  pipe
addCleanup)r  r  r"   s   @@r   create_pipezBTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe  s5    779DAqOO/0OO/0a4Kr   z"add in main, run in subinterpreterr:  c            
      F    t        j                   d d d d       y )Na<  if True:
                    # Wait until this interp has handled the pending call.
                    waiting = False
                    done = False
                    def wait(os_read=os.read):
                        global done, waiting
                        waiting = True
                        os_read(a
  , 1)
                        done = True
                    t = threading.Thread(target=wait)
                    with threading_helper.start_threads([t]):
                        while not waiting:
                            pass
                        os.write(, b'\0')
                        # Loop to trigger the eval breaker.
                        while not done:
                            time.sleep(0.01)
                            if time.time() > zT:
                                raise Exception('timed out!')
                    r   
run_stringinterpidr_donetimeoutw_readys   r   do_workz>TestPendingCalls.test_isolated_subinterpreter.<locals>.do_work  sA    (( 8! "( )" #* +. /6Y 7#4 r   r  rP       z-add in main, run in subinterpreter sub-threadc            
      F    t        j                   d d d d       y )Nzif True:
                    waiting = False
                    done = False
                    def subthread():
                        while not waiting:
                            pass
                        os.write(r"  aO  :
                                raise Exception('timed out!')
                    t = threading.Thread(target=subthread)
                    with threading_helper.start_threads([t]):
                        # Wait until this interp has handled the pending call.
                        waiting = True
                        os.read(z=, 1)
                        done = True
                    r#  r%  s   r   r*  z>TestPendingCalls.test_isolated_subinterpreter.<locals>.do_work  sA    (( 8" #* +. /6Y 7! "( )!4 r   z"add in subinterpreter, run in mainc            
      r    t        j                  d       t        j                   d d d d       y NrP   zif True:
                    # Add the pending call and wait for it to finish.
                    actual = _testinternalcapi.pending_identify(zX)
                    # Signal the subinterpreter to stop.
                    os.write(z&, b'\0')
                    os.write(z4, actual.to_bytes(1, 'little'))
                    r  readr   r$  r&  main_interpidr_readyw_dataw_dones   r   add_jobz>TestPendingCalls.test_isolated_subinterpreter.<locals>.add_job  K    #(( 8AAN P$X &$X &4 r   Fc                      d | d       dy NTrP   r    os_readr  r'  waitings    r   waitz;TestPendingCalls.test_isolated_subinterpreter.<locals>.wait!      "r   r  
timed out!littlez(add in subinterpreter, run in sub-threadc            
      r    t        j                  d       t        j                   d d d d       y r.  r/  r1  s   r   r6  z>TestPendingCalls.test_isolated_subinterpreter.<locals>.add_job<  r7  r   c                      d | d       dy r9  r    r:  s    r   r=  z;TestPendingCalls.test_isolated_subinterpreter.<locals>.waitH  r>  r   c                      s	 st        j                  d        s;t        j                  d       t        j                         kD  rt	        d       s:y y )Nr+  r  r?  )r  writer  r  	Exception)r  r(  r)  r<  s   r   	subthreadz@TestPendingCalls.test_isolated_subinterpreter.<locals>.subthreadM  sI    ! "%(JJt$yy{W,'55 r   )r   creater$  r|  r  r  r  r   r  r  r0  r  pending_identifyrD  r0   r  r  rE  
from_bytesstartjoin)r"   maxtextr   r*  rH  actualr_datar6  r=  t1t2textrF  t3r  r&  r2  r'  r3  r(  r4  r5  r)  r<  s   `             @@@@@@@@@@r   test_isolated_subinterpreterz-TestPendingCalls.test_isolated_subinterpreter  s-     '')   0 		 \\>? "	4*}GW'MNFFiikB&G*   0A!//4 (#*;;HE'( VS]3E"	4H \\IJ !	4*}GW'MNFFiikB&G(   0A!//4 (#*;;HE'( VS]3C!	4F \\>? %	9*}GW'MNFF'MNFFiikB&G  GDWW 
 !!1B!!.B!//R9 	*! "%(JJt$yy{W,'55  wwvq)	* ^^D(3FVS%78K%	9N \\DE (	9*}GW'MNFF'MNFFiikB&G  GDWW 
6 !!1B!!.B!!3B!//R= 7761%D^^D(3FVS%78Q(	9V 	}( (7"	4 "	4|( (5!	4 !	4x	* 	*3%	9 %	9T G(	9V 	s   A R0AR 2#R.A R'AR#R'BS)R40AR4R49S*B<S&S(AS R
	RRR$	R''R14R>	9SSS	SS#r   )r&   r'   r(   r  r  r   requires_working_threadingr  r  r  r  r  SimpleNamespacer  r  r  r   rS  r    r   r   r  r    s    $& 1002: 3:(
$%C
.!e++ .!` 1002/ 3/ 1002\B 3\B| ^4 ^4r   r  c                   ~   e Zd Z ej                   eed      d      d        Z ej                   eed      d      d        Zd Z	 ej                   eed      d      d        Z
 ej                  edu d       ej                   eed      d      d	               Zd
 Z ej                  edu d      d        Zy)SubinterpreterTestr  zrequires os.pipe()c                    dd l }t        j                         \  }}dj                  |      }t	        |d      5 }t        j                  |      }| j                  |d       | j                  t        j                  |      t        t        j                               | j                  t        j                  |      t        |             d d d        y # 1 sw Y   y xY w)Nr   zif 1:
            import sys, builtins, pickle
            with open({:d}, "wb") as f:
                pickle.dump(id(sys.modules), f)
                pickle.dump(id(builtins), f)
            rb)builtinsr  r  formatopenr   run_in_subinterpr0   r  pickleloadr*   rj   modules)r"   rZ  r  r  r@   frets          r   test_subinterpsz"SubinterpreterTest.test_subinterps  s    wwy1
 q	 	 !T] 	>a**40CS!$A3;;@A8=		> 	> 	>s   BCCc                 4   t        j                         \  }}dj                  |      }t        |d      5 }t	        j
                  |      }| j                  |d       | j                  t        j                  |      ddd       d d d        y # 1 sw Y   y xY w)Naa  if 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)
            rY  r   123xr  )r  r  )	r  r  r[  r\  r   r]  r0   r^  r_  )r"   r  r  r@   ra  rb  s         r   (test_subinterps_recent_language_featuresz;SubinterpreterTest.test_subinterps_recent_language_features  s    wwy1 q	 	 !T] 	Ha**40CS!$V[[^6-FG	H 	H 	Hs   ABBc                     d}t        j                         }| j                  t        j                  |      dd       t        j                         }| j                  ||d       | j                  ||d       y )Na  if 1:
        import sys, _testinternalcapi

        # Any config value would do, this happens to be the one being
        # double checked at the time this test was written.
        config = _testinternalcapi.get_config()
        config['int_max_str_digits'] = 55555
        _testinternalcapi.set_config(config)
        sub_value = _testinternalcapi.get_config()['int_max_str_digits']
        assert sub_value == 55555, sub_value
        r   z%subinterp code failure, check stderr.z7Expected get_config() to return a new dict on each callzJCAUTION: Tests executed after this may be running under an altered config.)r  
get_configr0   r   r]  assertIsNot)r"   r@   before_configafter_configs       r   (test_py_config_isoloated_per_interpreterz;SubinterpreterTest.test_py_config_isoloated_per_interpreter  sx    

 *44611$7@	B(335|I	K 	<	=r   c                    	 dd l }d}d}d}d}d}d}||z  |z  |z  |z  |z  }g d}	|	D 
cg c]  }
d	|
 	 }}
d
|d<   d|d<   d|d<   |df|df||z  dfdj                         D ]  \  }}t        t        ||            }|\  }}||d}| j	                  |      5  t        j                         \  }}t        j                  d| d      }t        j                  |      5 }t        j                  |fi |}| j                  |d       |j                         }d d d         |j                        }| j                  ||       d d d         dD ]z  }t        t        ||            }| j	                  |      5  t        j                  d      }| j                  t               5  t        j                  |fi | d d d        d d d        | y c c}
w # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   2xY w# 1 sw Y   xY w)Nr   r                 )obmallocforkr  r  daemon_threads
extensionsown_gilallow_use_main_obmalloccheck_multi_interp_extensionsrw  r  TF))TTTTTTT)TFFFFFF)FFFTFTFfeature_flagsrw  z
                    import _testinternalcapi, json, os
                    settings = _testinternalcapi.get_interp_settings()
                    with os.fdopen(zX, "w") as stdin:
                        json.dump(settings, stdin)
                    ))FFFFFFFz
                    import _testinternalcapi
                    _testinternalcapi.get_interp_settings()
                    raise NotImplementedError('unreachable')
                    )jsonitemsr  zipr|  r  r  r;   r<   fdopenr   run_in_subinterp_with_configr0   r0  loadsr3   r  )r"   r~  OBMALLOC
EXTENSIONSTHREADSDAEMON_THREADSFORKEXEC	ALL_FLAGSfeaturesr  kwlistconfigr  kwargs	exp_flagsexp_gilr  r  scriptrD  rb  rD   settingss                           r   test_configured_settingsz+SubinterpreterTest.test_configured_settings  se   	
 	
_t+g5F!"	
 )111F1#,11'q	4r
r

 D!5!:%u-!
 %'	5FH #ff-.F!)Iw!*"H f% 5wwy1! .$ %&3 '*  YYq\ (V!>>vPPC$$S!, ++-C( &4::c?  845 5	5>
 	KF #ff-.Ff% K! . 
 &&|4 K88J6JKK K		KK 28( (5 56K KK KsN   GAG!!9G,G!;+G:&G.=G:GG!!G+	.G73G::H	Nz%test requires _testsinglephase modulec                    	
 	 dd l 
d}dd}d}d}d}||z  |z  |z  |z  dddddd	d
		
 fd}d  _         j                  d      5   |d	d       d d d         j                  d      5   |d	d       d d d         j                  d      5   |d	d       d d d         j                  d      5   |dd       d d d         j                  d      5   |dd       d d d         j                  d      5   |dd       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   ]xY w# 1 sw Y   y xY w)Nr   r  rn  ro  rp  rq  rr  TF)ry  
allow_fork
allow_execallow_threadsallow_daemon_threadsrw  c                    t        |       }| rz  n}|dd}|d|d||||  |r|dkD  n|  |  d
}t        j                         \  }}t        j                  d| d| d      }t        j
                  |      5 }	t        j                  |fi |}
j                  |
d       |	j                         }d d d         j                        }j                  ||       y # 1 sw Y   .xY w)	N)rz  Fr|  r   )
	requestedoverride__initialoverride_afteroverride_restoredsettings__initialsettings_aftersettings_restoredallowed__initialallowed_afterallowed_restoredzu
                from test.test_capi.check_config import run_singlephase_check
                run_singlephase_check(z, z)
                )r  r  r  r;   r<   r  r   r  r0   r0  r  )enabledoverrider  flagsr  r  r  r  r  rD  rb  rD   results
BASE_FLAGSr  base_kwargsr~  r"   s                r   rm  zTSubinterpreterTest.test_overridden_setting_extensions_subinterp_check.<locals>.checkA  s   .5F 07J+JE!& H &%&"*%&%-"*%-(/K8@x!|g!N(/KH 779DAq__ *''/j1# 6& F 1 $::6LVL  a(kkm$ !djjoGWh/$ $s   <9C""C+z*config: check disabled; override: disabledr  z,config: check disabled; override: use configz)config: check disabled; override: enabledrP   z)config: check enabled; override: disabledz+config: check enabled; override: use configz(config: check enabled; override: enabled)r~  maxDiffr|  )r"   r  r  r  r  r  rm  r  r  r  r~  s   `      @@@@r   2test_overridden_setting_extensions_subinterp_checkzESubinterpreterTest.test_overridden_setting_extensions_subinterp_check&  s|   	 	
_t+g5F
!%!$(
%	0 %	0N  \\FG 	%	\\HI 	%O	\\EF 	%O	 \\EF 	$O	\\GH 	$N	\\DE 	$N	 		 		 		 		 		 		 	sH   
D2
D
D)8
D5
E>
EDD&)D25D>E
Ec                     	 dd l }t        j                  d       | j                  t	        |j
                  d             y )Nr   z1import binascii; binascii.Error.foobar = 'foobar'foobar)binasciir   r]  rL  r  Error)r"   r  s     r   test_mutate_exceptionz(SubinterpreterTest.test_mutate_exceptionz  s4    	 	  !TU:;r   $test requires _testmultiphase modulec                    	 t        j                         \  }}| j                  t         j                  |       | j                  t         j                  |       t	        j
                  d| d      }t        |       t        j                  |d      }t        j                  |      }| j                  |d       t        j                  |d      }| j                  ||       y )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)
            d   r   )r  r  r  r  r;   r<   r  r0  r   r]  r0   )r"   r  r  r  main_attr_idrb  subinterp_attr_ids          r   "test_module_state_shared_in_globalz5SubinterpreterTest.test_module_state_shared_in_global  s    	 wwy1!$!$ & S "  	Vwwq#&&v.a GGAsO'89r   )r&   r'   r(   r   rU  r  r  rc  rf  rl  r  r   _testsinglephaser  r  _testmultiphaser  r    r   r   rW  rW    s
   XV,.BC> D> XV,.BCH DH*=B XV,.BCJK DJKX X__%-/VWXV,.BCP D XPd< X___,.TU: V:r   rW  c                   >    e Zd Zeeeee ed      ee	e
eegZd Zd Zy)BuiltinStaticTypesTestsNc                     | j                   D ]C  }| j                  |      5  t        j                  |      }| j	                  |d        d d d        E y # 1 sw Y   PxY wr   )TYPESr|  r   type_get_tp_basesri  )r"   typeobjbasess      r   test_tp_bases_is_setz,BuiltinStaticTypesTests.test_tp_bases_is_set  s]     zz 	.Gg& .!33G<  -. .	.. .   (AA	c                     | j                   D ]C  }| j                  |      5  t        j                  |      }| j	                  |d        d d d        E y # 1 sw Y   PxY wr   )r  r|  r   type_get_tp_mrori  )r"   r  r  s      r   test_tp_mro_is_setz*BuiltinStaticTypesTests.test_tp_mro_is_set  s]     zz 	,Gg& ,//8  d+, ,	,, ,r  )r&   r'   r(   rq   rC  r  r   r  boolr  rE  WarningrU  r  r  r  r    r   r   r  r    s:     	T
E.,r   r  c                   J    e Zd ZdZed        Zej                  d        Zd Z	y)TestStaticTypesFc                 T    | j                   rt        j                  d      d| _         y )Nz%these tests do not support re-runningT)_has_runr   SkipTest)r,  s    r   
setUpClasszTestStaticTypes.setUpClass  s$     <<##$KLLr   c              '   8   K   t        j                  | }| y wr   )r   get_basic_static_type)r"   r   r,  s      r   basic_static_typez!TestStaticTypes.basic_static_type  s     --t4	s   c                 F   | j                         5 }| j                  |j                  t               | j	                  |j
                  t        f       | j                  t        |      t        t                     d d d        | j                  t              5 }| j                  |j                  t               | j	                  |j
                  t        f       | j                  t        |      t        t                     d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   )r  r+  __base__rq   r0   	__bases__rC  )r"   r,  s     r   %test_pytype_ready_always_sets_tp_typez5TestStaticTypes.test_pytype_ready_always_sets_tp_type  s     ##% 	4MM#,,/S]]VI6MM$s)T&\2	4 ##F+ 	4sMM#,,/S]]VI6MM$s)T&\2	4 	4	4 	4	4 	4s   A*DA*DDD N)
r&   r'   r(   r  classmethodr  rM  contextmanagerr  r  r    r   r   r  r    s8    H   4r   r  c                       e Zd Zej                   ej
                         d               Zej                   ej
                         d               Zd Zy)TestThreadStatec                       fd} |        t        j                  |      }|j                          |j                          y )Nc                      g fd} t         j                  |        | x}}t        j                  d       j	                  j                  t        j                               dd       y )Nc                  L     j                  t        j                                y r   )rv  r  r  )identss   r   r  zCTestThreadState.test_thread_state.<locals>.target.<locals>.callback  s    i1134r   rP   r  z/Couldn't find main thread correctly in the list)r   _test_thread_stater  r  r0   r  r  r  )r  r  r  r  r"   s      @r   r  z1TestThreadState.test_thread_state.<locals>.target  sZ    F5 ((2AJJqMV\\)*=*=*?@!NPr   r  )r  r  rJ  rK  )r"   r  rH  s   `  r   test_thread_statez!TestThreadState.test_thread_state  s2    	P 	F+			r   c                     t        j                  d      }t        ddd|      }| j                  d|j                         y )Nz
            import _testcapi

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

            _testcapi._test_thread_state(callback)
            z-Xtracemallocr:   s   callback called)r;   r<   r   r   rD   )r"   r@   rb  s      r    test_gilstate_ensure_no_deadlockz0TestThreadState.test_gilstate_ensure_no_deadlock  s<         t]D$?(#''2r   c                 ,    t         j                          y r   )r   test_current_tstate_matchesr!   s    r   test_gilstate_matches_currentz-TestThreadState.test_gilstate_matches_current  s    --/r   N)	r&   r'   r(   r   reap_threadsrT  r  r  r  r    r   r   r  r    sa    ""0002 3 #( ""00023 3 #30r   r  c                       e Zd Z e       j	                  d  ee      D                ej                  e	      d        Z
d Zy)Test_testcapic              #      K   | ]8  }|j                  d       r%|j                  d      s|t        t        |      f : yw)test__codeN)r?   endswithrO  r   .0r  s     r   	<genexpr>zTest_testcapi.<genexpr>  s=      Pw/g8N 79d34 Ps   >A r  c                 ,    t         j                          y r   )r   test_widecharr!   s    r   r  zTest_testcapi.test_widechar  s    !r   c                 `    | j                  t        j                  t        j                         y r   )r0   r   
Py_Versionrj   
hexversionr!   s    r   test_version_api_dataz#Test_testcapi.test_version_api_data!  s    --s~~>r   N)r&   r'   r(   localsupdatedirr   r	   rW  rU  r  r  r    r   r   r  r    sL    
HOO P #IP P
 %_$$.@A" B"?r   r  c                   R    e Zd Z e       j	                  d  ee      D               y)Test_testinternalcapic              #   b   K   | ]'  }|j                  d       r|t        t        |      f ) yw)r  N)r?   rO  r  r  s     r   r  zTest_testinternalcapi.<genexpr>&  s1      1w/ 7#4d;< 1s   -/N)r&   r'   r(   r  r  r  r  r    r   r   r  r  %  s#    
HOO 1 #$5 61 1r   r  r  c                   2    e Zd Z	 d Zd Zd Zd Zd Zd Zy)Test_ModuleStateAccessc                 H   d}t         j                  j                  d      j                  }t         j                  j                  ||      }t         j                  j                  ||      }t         j                  j                  |      }|j                  |       || _	        y )N!_testmultiphase_meth_state_accessr  )
	importlibutil	find_specorigin	machineryExtensionFileLoaderspec_from_loadermodule_from_specexec_moduler  )r"   fullnamer  loaderspecr  s         r   setUpzTest_ModuleStateAccess.setUp3  sy    6))*;<CC$$886J~~..x@0066"r   c                     	  G d d| j                   j                        } |       }| j                  |j                         | j                          y )Nc                       e Zd Zy)QTest_ModuleStateAccess.test_subclass_get_module.<locals>.StateAccessType_SubclassNr  r    r   r   StateAccessType_Subclassr  >  r  r   r  r  StateAccessTyper+  get_defining_moduler"   r  r  s      r   test_subclass_get_modulez/Test_ModuleStateAccess.test_subclass_get_module<  s@    1	t{{'B'B 	 ,-h224dkkBr   c                      G d d| j                   j                        } |       }| j                  |j                         | j                          y )Nc                        e Zd Z fdZ xZS )\Test_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclassc                      t         |          S r   )r   r  r   s    r   r  zpTest_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclass.get_defining_moduleF  s    w244r   )r&   r'   r(   r  r   r   s   @r   r  r  E  s    5 5r   r  r  r  s      r   #test_subclass_get_module_with_superz:Test_ModuleStateAccess.test_subclass_get_module_with_superD  s=    	5t{{'B'B 	5 ,-h224dkkBr   c                    	 | j                   j                         }| j                   j                         }|j                  |j                  d}|j	                         D ]  \  }}| j                  |      5  | j                  |j                         |j                                | j                  |j                         d        |        | j                  |j                         |j                                | j                  |j                         d        |d       | j                  |j                         |j                                | j                  |j                         d        |dd       | j                  |j                         |j                                | j                  |j                         d       | j                  t              5   |d	       d d d        | j                  t              5   |dd
d       d d d        d d d         y # 1 sw Y   =xY w# 1 sw Y   !xY w# 1 sw Y   xY w)N)clinicnoclinicr   rP   r  rn  r{  T)twice)thricerX   )
r  r  increment_count_clinicincrement_count_noclinicr  r|  r0   	get_countr3   rs   )r"   r  r  methodsr  increment_counts         r   test_state_accessz(Test_ModuleStateAccess.test_state_accessL  s   	 KK'')KK'') ..22

 &-]]_ 	-!D/d# -  >  2!  >  2"  >  2$/  >  2&&y1 .#1-. &&y1 -#Aq!,-'- -	-". .- -'- -s=   7E'H<
H$(H<H0H<$H-)H<0H95H<<I	c                     | j                   j                         }| j                  t              5  |j	                          d d d        y # 1 sw Y   y xY wr   )r  r  r3   rs   getmodulebydef_bad_def)r"   r  s     r   test_get_module_bad_defz.Test_ModuleStateAccess.test_get_module_bad_defr  sE     ;;..0y) 	.++-	. 	. 	.s   A

Ac                      G d dt         | j                  j                        }| j                   |       j	                         | j                         y )Nc                       e Zd Zy)FTest_ModuleStateAccess.test_get_module_static_in_mro.<locals>.SubclassNr  r    r   r   Subclassr)  ~  r  r   r*  )r  r  r  r+  r  )r"   r*  s     r   test_get_module_static_in_mroz4Test_ModuleStateAccess.test_get_module_static_in_mroz  s7    	}dkk&A&A 	hj446Dr   N)	r&   r'   r(   r
  r  r  r#  r&  r+  r    r   r   r  r  +  s'    /CC$-L.Er   r  c                   .    e Zd Zed        Zd Zd Zd Zy)TestInternalFrameApic                  *    t        j                         S r   )rj   	_getframer    r   r   funczTestInternalFrameApi.func  s    }}r   c                     | j                         }t        j                  |      }| j                  || j                   j                         y r   )r0  r  iframe_getcoder+  r  )r"   framer@   s      r   	test_codezTestInternalFrameApi.test_code  s5    		 //6dDII../r   c                     | j                         }t        j                  |      }| j                  |d       | j	                  |t        | j                   j                  j                               y r  )r0  r  iframe_getlastir   rc  r{  r  co_code)r"   r3  lastis      r   
test_lastizTestInternalFrameApi.test_lasti  sP    		!11%85!$s499#5#5#=#=>?r   c                     | j                         }t        j                  |      }| j                   j                  j                  }| j                  ||dz          y )NrX   )r0  r  iframe_getliner  co_firstlinenor0   )r"   r3  line	firstlines       r   	test_linezTestInternalFrameApi.test_line  sF    		 //6II&&55	y1}-r   N)r&   r'   r(   staticmethodr0  r4  r9  r?  r    r   r   r-  r-    s$     0
@.r   r-  r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	Test_Pep523APIc                    g }t         }|t         z   }	 t        |      D ]#  }||k(  rt        j                  |        |        % 	 t        j                          |t         z  }| j                  t        |      t        |             t        ||d      D ]  \  }}	| j                  ||	        y # t        j                          w xY w)NT)strict)"SUFFICIENT_TO_DEOPT_AND_SPECIALIZEr   r  set_eval_frame_recordset_eval_frame_defaultr0   r{  r  )
r"   r0  r  actual_callsrJ  r  rn   expected_callsr  rM  s
             r   do_testzTest_Pep523API.do_test  s    2::	75\ :%;;LI
 446!CC^,c,.?@ #NL N 	/HfXv.	/ 446s   1B/ /Cc                 P     G d d      fd}ddg}| j                  ||       y )Nc                       e Zd Zd Zy)4Test_Pep523API.test_inlined_binary_subscr.<locals>.Cc                      y r   r    )r"   others     r   ro   z@Test_Pep523API.test_inlined_binary_subscr.<locals>.C.__getitem__  rp   r   N)r&   r'   r(   ro   r    r   r   r  rM    s    r   r  c                               d    y Nr   r    )r  s   r   r0  z7Test_Pep523API.test_inlined_binary_subscr.<locals>.func  s    CGr   r0  ro   rJ  )r"   r0  r  r  s      @r   test_inlined_binary_subscrz)Test_Pep523API.test_inlined_binary_subscr  s*    	 		'T5!r   c                 D    ddfd}g d}| j                  ||       y )Nc                      y r   r    r6  s    r   innerz/Test_Pep523API.test_inlined_call.<locals>.inner  r  r   c                  $                d       y rQ  r    rW  s   r   r0  z.Test_Pep523API.test_inlined_call.<locals>.func  s    G"Ir   )r0  rW  rW  )r   rR  r"   r0  r  rW  s      @r   test_inlined_callz Test_Pep523API.test_inlined_call  s"    		 +T5!r   c                 B    d fd}ddg}| j                  ||       y )Nc                      y r   r    rV  s    r   rW  z;Test_Pep523API.test_inlined_call_function_ex.<locals>.inner  r  r   c                        dg  y rQ  r    rY  s   r   r0  z:Test_Pep523API.test_inlined_call_function_ex.<locals>.func  s    B4Lr   r0  rW  rR  rZ  s      @r   test_inlined_call_function_exz,Test_Pep523API.test_inlined_call_function_ex  s%    		!T5!r   c                 B    d fd}g d}| j                  ||       y )Nc               3      K   d y wrQ  r    r    r   r   r  z1Test_Pep523API.test_inlined_for_iter.<locals>.gen       Hr  c                              D ]  }  y r   r    )r  r  s    r   r0  z2Test_Pep523API.test_inlined_for_iter.<locals>.func  s    U r   )r0  r  r  r  rR  )r"   r0  r  r  s      @r   test_inlined_for_iterz$Test_Pep523API.test_inlined_for_iter  s"    		 .T5!r   c                 h     G d d       G d d      fd}g d}| j                  ||       y )Nc                       e Zd Zed        Zy)0Test_Pep523API.test_inlined_load_attr.<locals>.Cc                      yrQ  r    r!   s    r   r  z2Test_Pep523API.test_inlined_load_attr.<locals>.C.a  s    r   N)r&   r'   r(   propertyr  r    r   r   r  rg    s     r   r  c                       e Zd Zd Zy)0Test_Pep523API.test_inlined_load_attr.<locals>.Dc                      yrQ  r    )r"   r  s     r   __getattribute__zATest_Pep523API.test_inlined_load_attr.<locals>.D.__getattribute__  s    r   N)r&   r'   r(   rm  r    r   r   Drk    s    r   rn  c                  J             j                            j                    y r   r  )r  rn  s   r   r0  z3Test_Pep523API.test_inlined_load_attr.<locals>.func  s    CEECEEr   )r0  r  rm  rR  )r"   r0  r  r  rn  s      @@r   test_inlined_load_attrz%Test_Pep523API.test_inlined_load_attr  s1    	 		 		 2T5!r   c                 N    d fdfd}g d}| j                  ||       y )Nc               3      K   d y wrQ  r    r    r   r   rW  z/Test_Pep523API.test_inlined_send.<locals>.inner  rb  r  c               3   0   K            E d {    y 7 wr   r    rY  s   r   outerz/Test_Pep523API.test_inlined_send.<locals>.outer  s     ws   c                  &    t                        y r   )r   )rt  s   r   r0  z.Test_Pep523API.test_inlined_send.<locals>.func  s    Mr   )r0  rt  rt  rW  rW  rt  rW  rR  )r"   r0  r  rW  rt  s      @@r   test_inlined_sendz Test_Pep523API.test_inlined_send  s%    			NT5!r   N)
r&   r'   r(   rJ  rS  r[  r_  rd  rp  rv  r    r   r   rB  rB    s%    / """"""r   rB  __main__)Cr  collectionsr   r   rM  importlib.machineryr  importlib.utilr~  r  r^  r  r  
subprocessrj   r;   r  r  r  r   r  r  ra  r.   r   test.supportr   r   r   r	   r
   test.support.script_helperr   r   r   rt   ImportErrorr  r  _xxsubinterpretersr   ModuleNotFoundErrorr  r   r  rK  r   r   r#   r%   TestCaser,   rY  r  rW  r  r  r  r  r  r   r  r-  rE  rB  r&   mainr    r   r   <module>r     sQ    *     	     
          - & ) ( - d d.
 (M''4	  <=
: :M&x   M&b W.8,, W. W.tV4x(( V4rU:** U:p,h// ,B 4h''  4F(0h'' (0V?H%% ?1H-- 1 D(*PQTEX.. TE RTEn.8,, .0 &) "K"X&& K"\ zHMMO UF    O    MsH   G5 	H H H 5H ?H HHHHH*)H*