Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.116.27.43
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_embed.cpython-310.pyc
o

`b)��@s`ddlmZddlmZddlmZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZe
jdkZejdkZdZdZd	Zd
ZdZd	ZdZdZd
d�Zdd�ZGdd�d�ZGdd�deej �Z!Gdd�deej �Z"Gdd�dej �Z#Gdd�deej �Z$Gdd�deej �Z%Gdd�deej �Z&e'dkr�e�(�dSdS) �)�support)�
import_helper)�	os_helperN)�
namedtuple�nt�darwin����l��cCs.tj�|�}tj�|�d}|���d���S)Nr�_d)�os�path�basename�splitext�casefold�endswith)Zprogram�name�r�8/usr/local/python-3.10/lib/python3.10/test/test_embed.py�debug_build%srcCs,ttj�}t|�D]
}|�d�r||=q	|S)NZPYTHON)�dictr
�environ�list�
startswith)�env�keyrrr�remove_python_envvars+s

�rc@s:eZdZdd�Zdd�Zdddddd�dd	�Zd
d�ZdS)�EmbeddingTestsMixincCs�tj�t�}tj�tj�tj�|���}d}tr/ttj�rdndd}||7}tj�tj�}ntj�	|d�}tj�	||�|_
}tj�|�sM|�d|�t�
�|_t�|�dS)N�
_testembedr�z.exeZProgramsz%r doesn't exist)r
r�abspath�__file__�dirname�
MS_WINDOWSr�sys�
executable�join�test_exe�existsZskipTest�getcwd�oldcwd�chdir)�self�hereZbasepathZexename�extZexepathZexerrr�setUp5s
zEmbeddingTestsMixin.setUpcCst�|j�dS�N)r
r,r+�r-rrr�tearDownHszEmbeddingTestsMixin.tearDownNr)r�timeout�
returncode�input�cwdcGs�|jg}|�|�|durtr|��}tjd|d<tj|tjtjd||d�}z|j	||d�\}	}
Wn|�
�|���|j|krat
jratd|�d��td|	���td	|
���td
�|�|j|d|j|
f�|	|
fS)z'Runs a test in the embedded interpreterNZ
SYSTEMROOTT)�stdout�stderr�universal_newlinesrr7)r6r4z--- z failed ---zstdout:
zstderr:
z------zbad returncode %d, stderr is %r)r(�extendr$�copyr
r�
subprocess�Popen�PIPE�communicate�	terminate�waitr5r�verbose�print�assertEqual)r-rr4r5r6r7�args�cmd�p�out�errrrr�run_embedded_interpreterKs:
�
��z,EmbeddingTestsMixin.run_embedded_interpreterccs$�|�d�\}}|�|d�d}tdd�}d}g}|��D]r}|d�|�kr<|�t|�d�tjdkr7t|�|d7}q|�	t|�d	�t
�||�}|durT|�||�||�
��}	tjdkrct|	�|�|	j�|�|	j�|�|	j�|�|	�t|�d	kr�|d}
|�|	|
�|Vg}qdS)
NZ&test_repeated_init_and_subinterpretersr zS^interp (\d+) <(0x[\dA-F]+)>, thread state <(0x[\dA-F]+)>: id\(modules\) = ([\d]+)$�Interpzid interp tstate modulesr
z--- Pass {} ---r�)rKrEr�
splitlines�format�lenrrCrDZ
assertLess�re�matchZassertRegex�groupsZ
assertTrue�interp�tstate�modules�append)r-rIrJZ
interp_patrLZnumloopsZcurrent_run�linerRrT�mainrrr�%run_repeated_init_and_subinterpretersns@�



��z9EmbeddingTestsMixin.run_repeated_init_and_subinterpreters)�__name__�
__module__�__qualname__r0r3rKrZrrrrr4s�#rc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�EmbeddingTestsi�cCs(|��D]
}|d}|�|jd�qdS)Nr�0)rZrE�id)r-�runrYrrr�test_subinterps_main�s�z#EmbeddingTests.test_subinterps_maincCsT|��D]#}|�^}}}t|j�}t|�D]\}}|�|jt||d��qqdS)Nr
)rZ�intr`�	enumeraterE�str)r-rarY�subs�_Zmainid�i�subrrr�test_subinterps_different_ids�s
��z,EmbeddingTests.test_subinterps_different_idscCsj|��D].}|�^}}}d|vrt�d��|D]}|�|j|j�|�|j|j�|�|j|j�qqdS)NZ0x0zplatform prints pointers as 0x0)rZ�unittestZSkipTestZassertNotEqualrTrUrV)r-rarYrfrgrirrr�test_subinterps_distinct_state�s
��z-EmbeddingTests.test_subinterps_distinct_statecCsP|�d�\}}|�|d�dd�tdtd�D�}d�|�d}|�||�dS)N�test_repeated_init_and_inittabr cSsg|]}d|�d��qS)z	--- Pass z ---r)�.0rhrrr�
<listcomp>�szAEmbeddingTests.test_repeated_init_and_inittab.<locals>.<listcomp>r
�
)rKrE�range�
INIT_LOOPSr')r-rIrJ�linesrrrrm�s
z-EmbeddingTests.test_repeated_init_and_inittabcCs�ttjdd�}|jd|d�\}}tjdkr t�t|�t|�d}d}d�gd	��}|j|||d
�}d|_	|�
|��|�dS)Nzutf-8:surrogateescape)ZPYTHONIOENCODING�test_forced_io_encoding�rr
�utf-8�surrogateescaperp)z--- Use defaults ---�Expected encoding: default�Expected errors: defaultzstdin: {in_encoding}:{errors}zstdout: {out_encoding}:{errors}�'stderr: {out_encoding}:backslashreplacez--- Set errors only ---rxzExpected errors: ignorezstdin: {in_encoding}:ignorezstdout: {out_encoding}:ignorerzz--- Set encoding only ---�Expected encoding: iso8859-1ryzstdin: iso8859-1:{errors}zstdout: iso8859-1:{errors}�"stderr: iso8859-1:backslashreplacez--- Set encoding and errors ---r{zExpected errors: replacezstdin: iso8859-1:replacezstdout: iso8859-1:replacer|)Zin_encodingZout_encoding�errors)rr
rrKrrCrDr'rO�maxDiffrE�strip)r-rrIrJZexpected_stream_encodingZexpected_errors�expected_outputrrrrt�s 
�z&EmbeddingTests.test_forced_io_encodingcCspttjtj�tj�d�}|jd|d�\}}tr|j	}n	tj�t�
�d�}d|�d�}|�||�|�|d�dS)	z�
        Checks some key parts of the C-API that need to work before the runtime
        is initialized (via Py_Initialize()).
        )�
PYTHONPATH�test_pre_initialization_apiruZspamzsys.executable: rpr N)
rr
r�pathsepr'r%rrKr$r(r*�assertInrE)r-rrIrJZ
expected_pathr�rrrr��sz*EmbeddingTests.test_pre_initialization_apicCsJt�}tj�tj�|d<|jd|d�\}}d}|�||�|�|d�dS)z�
        Checks that sys.warnoptions and sys._xoptions can be set before the
        runtime is initialized (otherwise they won't be effective).
        r��#test_pre_initialization_sys_optionsruz�sys.warnoptions: ['once', 'module', 'default']
sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}
warnings.filters[:3]: ['default', 'module', 'once']
r N)	rr
r�r'r%rrKr�rE)r-rrIrJr�rrrr�
s
��z2EmbeddingTests.test_pre_initialization_sys_optionscC�*|�d�\}}|�|d�|�|d�dS)ze
        bpo-20891: Calling PyGILState_Ensure in a non-Python thread must not
        crash.
        �
test_bpo20891r N�rKrE�r-rIrJrrrr��zEmbeddingTests.test_bpo20891cCr�)zf
        bpo-33932: Calling Py_Initialize() twice should do nothing (and not
        crash!).
        �test_initialize_twicer Nr�r�rrrr�$r�z$EmbeddingTests.test_initialize_twicecCs.|�d�\}}|�|��d�|�|d�dS)zS
        bpo-34008: Calling Py_Main() after Py_Initialize() must not fail.
        �test_initialize_pymainz6Py_Main() after Py_Initialize: sys.argv=['-c', 'arg2']r N�rKrE�rstripr�rrrr�-sz%EmbeddingTests.test_initialize_pymaincCs.|�d�\}}|�|��d�|�|d�dS)N�
test_run_mainz%Py_RunMain(): sys.argv=['-c', 'arg2']r r�r�rrrr�5szEmbeddingTests.test_run_maincCs2d}|�d�\}}|�|d|�|�|d�dS)NrM�test_run_main_loopz&Py_RunMain(): sys.argv=['-c', 'arg2']
r r�)r-ZnlooprIrJrrrr�:sz!EmbeddingTests.test_run_main_loopN)r[r\r]r~rbrjrlrmrtr�r�r�r�r�r�r�rrrrr^�s+		r^c
@sDeZdZdZer
dndZe�Ze�Ze	e
dddddd�Zer%e�ddi�e
eedeed�Ze
eeddddddd	�Zgd
�Zide	�dd�d
d�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�de�de�dd�de�idd�ddg�d g�d!g�d"g�d#d�d$d�d%e�d&e�d'e�d(e�d)e�d*e�d+e�d,d�d-ej�d.d��id/d�d0d�d1d�d2d�d3d�d4d�d5d�d6d�d7d�d8d�d9d�d:d�d;e�d<e�d=d�d>d�d?d��ddd@ddddA��Zer�e�dBdi�e
eeddCdD�Ze
eeddddddddddE�Ze�rdedB<ddddF�ZdGgZgdH�Ze�r)e�dI�e�dJ�e�r3dKdKedL�ZniZgdM�Ze�rAe�dN�dZedOdP��Z dQdR�Z!dSdT�Z"dUdV�Z#	d�dWdX�Z$dYdZ�Z%d[d\�Z&d]d^�Z'd_d`�Z(				d�dddaddb�dcdd�Z)dedf�Z*dgdh�Z+didj�Z,dkdl�Z-dmdn�Z.dodp�Z/dqdr�Z0dsdt�Z1dudv�Z2dwdx�Z3dydz�Z4d{d|�Z5d}d~�Z6dd��Z7d�d��Z8d�d��Z9d�d��Z:d�d��Z;d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d�d��ZGeHjId�d���ZJd�d��ZKd�d��ZLeM�Ned��d�d���ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTdS)��InitConfigTestsi�
surrogatepassrwrr
)�_config_init�	allocator�
parse_argv�configure_locale�coerce_c_localeZcoerce_c_locale_warn�	utf8_mode�legacy_windows_fs_encoding)r�r�r�r�)r�r��isolated�use_environmentr��dev_moder�)r�r�r�r�r�r�r��install_signal_handlers�
use_hash_seed�	hash_seed�faulthandler�tracemalloc�import_time�show_ref_countZ	dump_refs�malloc_stats�filesystem_encoding�filesystem_errors�pycache_prefixN�program_namer��argvr �	orig_argv�xoptions�warnoptions�pythonpath_env�homer&�base_executable�prefix�base_prefix�exec_prefix�base_exec_prefix�module_search_pathsZmodule_search_paths_set�
platlibdir�site_import�
bytes_warning�warn_default_encoding�inspect�interactive�optimization_level�parser_debug�write_bytecoderC�quiet�user_site_directory�configure_c_stdio�buffered_stdio�stdio_encoding�stdio_errorsZskip_source_first_line�run_commandZ
run_module�default)�run_filenameZ_install_importlib�check_hash_pycs_mode�pathconfig_warnings�
_init_main�_isolated_interpreter�legacy_windows_stdior)r�r�r�)
r�r�r�r�r�r�r�r�r�r�)ZPy_HasFileSystemDefaultEncodingZPy_HashRandomizationFlagZ$_Py_HasFileSystemDefaultEncodeErrors)ZPy_UTF8Moder�))ZPy_BytesWarningFlagr�)ZPy_DebugFlagr�)ZPy_DontWriteBytecodeFlagr�T)Z Py_FileSystemDefaultEncodeErrorsr�)ZPy_FileSystemDefaultEncodingr�)Z
Py_FrozenFlagr�T)ZPy_IgnoreEnvironmentFlagr�T)ZPy_InspectFlagr�)ZPy_InteractiveFlagr�)ZPy_IsolatedFlagr�)Z
Py_NoSiteFlagr�T)ZPy_NoUserSiteDirectoryr�T)ZPy_OptimizeFlagr�)ZPy_QuietFlagr�)ZPy_UnbufferedStdioFlagr�T)ZPy_VerboseFlagrC))ZPy_LegacyWindowsFSEncodingFlagr�))ZPy_LegacyWindowsStdioFlagr����)r�r��python3_dll)r�r�r�r�)r�cCs
d|_dSr1)�EXPECTED_CONFIG)�clsrrr�
tearDownClasss
zInitConfigTests.tearDownClasscCs<i}|D]}d|vr|�dd�\}}|||<qd||<q|S)N�=r
T)�split)r-Z
xoptions_listr��optr�valuerrr�
main_xoptionss

zInitConfigTests.main_xoptionscCs�t�}t�d�}tjdd|g}tj||tjtjd�}|jr)t	d|j
�d|j����|j
�d�}zt
�|�WSt
jyH|�d|���YdSw)	Na4
            import json
            import sys
            import _testinternalcapi

            configs = _testinternalcapi.get_configs()

            data = json.dumps(configs)
            data = data.encode('utf-8')
            sys.stdout.buffer.write(data)
            sys.stdout.buffer.flush()
        z-S�-c)rr8r9z)failed to get the default config: stdout=z stderr=rv�fail to decode stdout: )r�textwrap�dedentr%r&r=rar?r5�	Exceptionr8r9�decode�json�loads�JSONDecodeError�fail)r-r�coderF�procr8rrr�_get_expected_config_impls&
����z)InitConfigTests._get_expected_config_implcCslt}|jdur|��|_i}|j��D] \}}i}|��D]\}}t|t�r*|��}|||<q|||<q|Sr1)r�r�r��items�
isinstancerr<)r-r��configsZ
config_keyZconfig_value�configrr�rrr�_get_expected_config<s




z$InitConfigTests._get_expected_configcCsD|��}|d}|��D]\}	}
|
|jur||	||	<q|d}|��D]\}	}
|
|jur3||	||	<q$|dr<|tkrFdD]}	|j||	<q>|dsO|j|d<|ddkr�|d|jur`d|d<|d	|jurl|j|d	<|d
|jurwd|d
<|d|jur�d|d<tr�|j}n|d
|jur�tj	�
|d
�}n	tj	�t��d�}|d|jur�||d<|d|jur�||d<|d
|jur�d|d
<|d}
|��D]\}	}
|
|jur�|
|	||	<q�|d|ju�r|d}|dur�|�
tj	j�}g|�|d�|d<|du�r|d��|d<||d�|jD]}	|	|v�r||	||	<�qdS)N�
pre_config�path_configr�)r�r�r�r�r�r
r�rvr�r�r�rwr�rr&r�z./_testembedr�r�r�)r�r��GET_DEFAULT_CONFIG�
API_COMPAT�
IGNORE_CONFIG�UTF8_MODE_ERRORSr$r(r
rr!r'r*r�r�r<�COPY_PRE_CONFIG)r-�expected_preconfig�expected�expected_pathconfigr�api�modify_path_cbr�r�rr�r�Zdefault_executabler�r��pathsrrr�get_expected_configLsl
�
�


�


��z#InitConfigTests.get_expected_configcC�Nt|d�}t|���D]\}}||jur|�|d�||=q|�||�dS)Nr��rrr�r��poprE)r-r�r�r�rr�rrr�check_pre_config��
�z InitConfigTests.check_pre_configcCr�)Nr�r�)r-r�r�r�rr�rrr�check_config�r�zInitConfigTests.check_configc	Cs�|d}|d}t|j�}|jD]"}t|�dkr(|\}}}||r#dnd||<q|\}}||||<q|jD]"}t|�dkrN|\}}}||rIdnd||<q6|\}}||||<q6|�|d|�dS)Nr�r�r	rr
Z
global_config)r�DEFAULT_GLOBAL_CONFIG�COPY_GLOBAL_CONFIGrP�COPY_GLOBAL_PRE_CONFIGrE)	r-r�r�r�r��itemZ
global_keyZcore_keyZoppositerrr�check_global_config�s 




z#InitConfigTests.check_global_configcCsV|d}|jD]}||||<qtjj�|d�|d<|d|d<|�|d|�dS)Nr�r�Zmodule_search_pathr&Zprogram_full_pathr�)�COPY_PATH_CONFIGr
rr�r'rE)r-r�r�r�rrrr�check_path_config�s
z!InitConfigTests.check_path_configF)�
preconfig_apir�
ignore_stderrr7cCs�t�}|	dur|�|	�|}	|dur|}|tkr|j}
n|tkr$|j}
n|j}
|dur-i}t|
fi|��}|dur;i}|durAi}t|jfi|��}|tkrR|j	}n|tkrZ|j
}n|j}t|fi|��}|�||||	||�|j
||	|d�\}}|dur�|ds�d}|dur�|
s�|�|��|�zt�|�}Wntjy�|�d|���Ynw|�||�|�||�|�|�|�||�|S)N)rr7rCr r�)r�update�API_ISOLATED�PRE_CONFIG_ISOLATED�
API_PYTHON�PRE_CONFIG_PYTHON�PRE_CONFIG_COMPATr�PATH_CONFIG�
CONFIG_PYTHON�CONFIG_ISOLATED�
CONFIG_COMPATr�rKrEr�r�r�r�r�r�r�rr)r-ZtestnameZexpected_configr�r�r�r9r�rrrr7Znew_envZdefault_preconfigZdefault_configrIrJr�rrr�check_all_configs�s`
�
��
z!InitConfigTests.check_all_configscC�|jdtd�dS)NZtest_init_initialize_config�r��rr�r2rrr�test_init_default_config��z(InitConfigTests.test_init_default_configcCr)N�test_preinit_compat_configrrr2rrrrrz*InitConfigTests.test_preinit_compat_configcCr)N�test_init_compat_configrrr2rrrrrz'InitConfigTests.test_init_compat_configcCs@ddi}ddddgdddddddddd�
}|jd||td	�dS)
Nr�r
z./globalvarr�default::BytesWarningr)
r�r�r�r�r�r�r�r�rCr�r�r�r��test_init_global_configrr�r-�	preconfigr�rrrrs&��

�z'InitConfigTests.test_init_global_configcCstdd�}idd�dd�dd�dd	�d
d�dd�dd�d
d�dd�dd�dd�dddg�dgd��dd	�dgd��dgd��dd �id!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.�d/|j�d0d1�d2d�d3d��}|jd4||td5�dS)6Nr
�r�r�r�rr�r��{r�rr�r�r�r��	iso8859-1r��replacer�Zconf_pycache_prefixr�z./conf_program_namer�r��arg2r�)�python3�-W�cmdline_warnoption�-X�cmdline_xoptionr��passrr�r�)zconfig_xoption1=3zconfig_xoption2=Zconfig_xoption3r$r�)r"rZconfig_warnoptionr��pass
r�r�r�r�r�r�rCr�r�r�r�r�r�Z
my_platlibdirr�r��alwaysr�r��test_init_from_configr��PYMEM_ALLOCATOR_MALLOCr�rr�rrrrr(s���������	�
��
������ �"�#�$�%�&�'�(�)�*�+�,�-�.�/�1�2�4�
6
�z%InitConfigTests.test_init_from_configcCs�dti}idd�dd�dd�dd�d	d�d
d�dd�dd
�dd�dd�dd�dd�dd�dd�dd�dd�ddg�d|jd��}|jd||td�dS) Nr�r�r
r��*r�rr�r�r�r�r��/my/pathr��env_pycache_prefixr�rrCr�r�rr�rr�r�r��EnvVar�env_platlibdir�r�r��test_init_compat_envrr)rrrrr1[sV���������	�
���
������

�z$InitConfigTests.test_init_compat_envcCs�tdd�}idd�dd�dd�dd�d	d�d
d�dd�dd
�dd�dd�dd�dd�dd�dd�dd�dd�ddg�d|jd��}|jd||td�dS) Nr
rr�r�r+r�rr�r�r�r�r�r,r�r-r�rrCr�r�rr�rr�r�r�r.r/r0�test_init_python_envr)r*r�rrrrrrr2wsX���������	�
���
������

�z$InitConfigTests.test_init_python_envcC�0ttd�}tdddgd�}|jd||td�dS)N�r�r
r��r�r�r��test_init_env_dev_moder)r�PYMEM_ALLOCATOR_DEBUGrr�rrrrr6��
�

�z&InitConfigTests.test_init_env_dev_modecCr3)Nr4r
r�r5�test_init_env_dev_mode_allocr)rr*rr�rrrrr9�r8z,InitConfigTests.test_init_env_dev_mode_alloccCs,dti}dddgd�}|jd||td�dS)Nr�r
r�)r�r�r��test_init_dev_moder)r7rrrrrrr:�s��

�z"InitConfigTests.test_init_dev_modecCsDdti}dggd�tj�d�dddgdgd�}|jd||td	�dS)
Nr��	script.py)r r#�devr;r
r�r<)r�r�r�r�r�r�r��test_preinit_parse_argvr)r7r
rr!rrrrrrr=�s�
�
	
�z'InitConfigTests.test_preinit_parse_argvcCs2ddi}gd�}||dd�}|jd||td�dS)Nr�r)r �-E�-Ir#r<r#�utf8r;)r�r�r��test_preinit_dont_parse_argvr�rr)r-rr�r�rrrrA�s��

�z,InitConfigTests.test_preinit_dont_parse_argvcC� dddd�}|jd|td�dS)Nr
r�r�r�r��test_init_isolated_flagr�rr�r-r�rrrrE�s
�z'InitConfigTests.test_init_isolated_flagcCrC)Nr
rrD�test_preinit_isolated1rrrGrrrrH��
�z&InitConfigTests.test_preinit_isolated1cCrC)Nr
rrD�test_preinit_isolated2rrrGrrrrJ�rIz&InitConfigTests.test_preinit_isolated2cCr)N�test_preinit_isolated_configrrBr2rrrrK�rz,InitConfigTests.test_preinit_isolated_configcCr)N�test_init_isolated_configrrBr2rrrrL�rz)InitConfigTests.test_init_isolated_configcCr)N�test_preinit_python_configrrFr2rrrrM�rz*InitConfigTests.test_preinit_python_configcCr)N�test_init_python_configrrFr2rrrrN�rz'InitConfigTests.test_init_python_configcCs ddd�}|jdi|td�dS)Nr)r�r��test_init_dont_configure_localerrF)r-rrrrrO�s�

�z/InitConfigTests.test_init_dont_configure_localecCs(ddd�}dd�}|jd|t|d�dS)Nz./init_read_setZ
my_executable)r�r&cSs|�dd�|�d�dS)Nr
Ztest_path_insert1Ztest_path_append)�insertrW)rrrr�modify_pathsz7InitConfigTests.test_init_read_set.<locals>.modify_path�test_init_read_set)r�r�rF)r-r�rQrrrrRs�
�z"InitConfigTests.test_init_read_setcCs.dgd�gd�gd�d�}|jd|td�dS)Nr
)Zconfig_xoptionr$Zsysadd_xoptionr�)�ignore:::cmdline_warnoptionzignore:::sysadd_warnoptionzignore:::config_warnoption)r r!rSr#r$)r�r�r�r��test_init_sys_addrrFrGrrrrTs�z!InitConfigTests.test_init_sys_addcCs8d}ddgdd|dgd|ddd�}|jd	|td
�dS)N�Rimport _testinternalcapi, json; print(json.dumps(_testinternalcapi.get_configs()))r�rr �	./python3rpr)r�r�r�r�r��test_init_run_mainrrF�r-r�r�rrrrW#s
�z"InitConfigTests.test_init_run_maincCs<d}ddgdd|dgd|dddd	�}|jd
|tdd�dS)
NrUr�rr rVrprr)r�r�r�r�r�r��test_init_mainz)Run Python code before _Py_InitializeMain)r�r9rFrXrrrrY/s��

�zInitConfigTests.test_init_maincCs.dgd�gd�dddd�}|jd|td	�dS)
Nr)r��arg1�-v�arg3��./argv0r>r�r%rZr[r\r^r&r)r�r�r�r�r�r��test_init_parse_argvrrFrGrrrr_@s�z$InitConfigTests.test_init_parse_argvcCs4ddi}dgd�gd�dd�}|jd||td�dS)Nr�rr]r^)r�r�r�r��test_init_dont_parse_argvrrF)r-r�r�rrrr`Ks��

�z)InitConfigTests.test_init_dont_parse_argvcCsDtrd}|j}nd}tr|j}nt�|�pd}|�|||d��dS)N�pythonr r )r�r�r&)r$r(�MACOS�shutil�whichr)r-r�r�r&rrr�default_program_nameXs�z$InitConfigTests.default_program_namecCsX|��}|dd}|ddddd�}|�|�dtjj�|�i}|jd|t|dd�dS)	Nr�r�r )r�r�r�r�r��TESTPATH�test_init_setpathT�r�rr)r�rer
rr�r'rr��r-r�r�rrrrrghs�

�z!InitConfigTests.test_init_setpathc	CsT|��}|dd}|dddddddd�}dtjj�|�i}|jd|t|d	d
�dS)Nr�r�r Zconf_program_nameZconf_executable)r�r�r�r�r�r�r�r&rf�test_init_setpath_configTrh)r�r
rr�r'rrrirrrrj{s�
�z(InitConfigTests.test_init_setpath_configc
Cs�|��}|dur|dd}|dur|dd}tr |ddStj}tj�|tjd|j�|j	�d��tj�|tjd|j�d|j	���tj�|tjd|j�d|j	��d�gS)Nr�r�r�raz.zip�.�lib-dynload)
r�r$r%�version_infor
rr'r��major�minor)r-r�r�r��verrrrr��s$����z#InitConfigTests.module_search_pathsccsB�t����}tj�|�}trotj}d|j�|j	��}d|j��}t
tj�r-|d7}|d7}|d7}|d7}tj�tj�
|j�|�}tj�tj�
|j�|�}tj�|tj�|��}tj�|tj�|��}t�||�t�||�tj�|tj�|j��}t�|j|�t�|j|�||_|VWd�dS1s�wYdS)Nrarz.dll)�tempfile�TemporaryDirectoryr
r�realpathr$r%rmrnrorr&r'r#r(rrc�copyfile�copystat)r-�tmpdirrp�dllZdll3Zdll_copyZ	dll3_copyZ	exec_copyrrr�tmpdir_with_python�s0�

"�z"InitConfigTests.tmpdir_with_pythonc
Cs�|��}|dd}tjj�|�}|D]}tj�|�sqtj�tj�|d��r/tj�|�}q8q|�d|���|}}|j	||d�}|||||||d�}|�
|�||d�}	|jd|t|	d	�dS)
Nr�r��os.pyzUnable to find home in )r�r�)r�r�r�r�r�r�r�)ZTESTHOMEr��test_init_setpythonhome)r�r)
r�r
rr�r'�isdirr)r#r�r�rerr�)
r-r�r��	paths_strrr�r�r�Zexpected_pathsrrrrrz�s4��
	

�z'InitConfigTests.test_init_setpythonhomecCs6|��}|dd}tjj�|�}||d<d|i}|S)Nr�r�r�r�)r�r
rr�r')r-r�Zall_configsr�r|rrrr�copy_paths_by_env�sz!InitConfigTests.copy_paths_by_envz#Windows does not use pybuilddir.txtc
	Cs�|���[}d}tj�||�}t�|�tj�|d�}t|ddd��
}|�|�Wd�n1s1wY|��}||d<|j}|||d�}|�	|�}	|j
d|t|	d	|d
�Wd�dS1sbwYdS)N�libdirzpybuilddir.txt�wr@��encodingr�)r�r&r�rT)r�rrr7)rxr
rr'�mkdir�open�writer�r(r}rr�)
r-rvZsubdirr~�filename�fpr�r&r�rrrr�test_init_pybuilddir�s*

��
�"�z$InitConfigTests.test_init_pybuilddircCs6|����}t����}tj}ts(tj�|tj	d|j
�d|j��d�}t�|�ntj�|d�}t�|�t
�tjtj�|d��tj�|d�}t|ddd	��}td
||d�td|d�Wd�n1sgwY|��}tsw||d
<n,t|�D]#\}}	|dkr�tj�|tj�|	��||<q{tj�|tj�|	��||<q{||d
<|j}
|}|||
|
|d�}i}
tr�||d<||d<tj}d|j
��}t|
�r�|d7}|d7}tj�tj�|
�|�}||
d<|�|�}|jd||
t|d|d�Wd�n1s�wYWd�dSWd�dS1�swYdS)Nrarkrl�libryz
pyvenv.cfgrr@r�z	home = %s��filez$include-system-site-packages = falser�r)r�r�r�r&r�r�r�rz.DLLr�rT)r�r�rrr7)rxrqrrr%rmr$r
rr'r�rnro�makedirsrcrtr"r�rDr�rdrr(rr#r}rr�)r-rvZpyvenv_homerpZlib_dynloadr�r�r��indexrr&r�r�r�rwrrrr�test_init_pyvenv_cfg
sl��
�
�
�R�z$InitConfigTests.test_init_pyvenv_cfgc
s�t�d��t�d�}�fdd�}|d�}|d�}|d�}|d�}|d	�}|d
�}|��d}	|�|��tjj�|	d�|�|�|	d
�|�|�|	d�|�|�|	d�|�|�|	d�|�|�|	d�dS)N�ctypes�_testinternalcapicst�j|�}d|_�j|_|S)Nr)�getattr�	pythonapi�argtypesZ	c_wchar_p�restype)r�func�r�rr�get_funcXsz8InitConfigTests.test_global_pathconfig.<locals>.get_func�
Py_GetPath�Py_GetPrefix�Py_GetExecPrefix�Py_GetProgramName�Py_GetProgramFullPath�Py_GetPythonHomer�r�r�r�r�r&r�)r�
import_moduleZget_configsrEr�r
rr�)
r-r�r�r�r�r�r�r�r�r�rr�r�test_global_pathconfigIs$

�z&InitConfigTests.test_global_pathconfigcCs<gd�}ttd�}ddd|gd�d�}|jd||td�dS)N)zignore:::PyConfig_Insert0r�z
ignore:::env1z
ignore:::env2zignore:::cmdline1zignore:::cmdline2rzignore:::PySys_AddWarnOption1zignore:::PySys_AddWarnOption2zignore:::PyConfig_BeforeReadzignore:::PyConfig_AfterReadr4r
)r z-Wignore:::cmdline1z-Wignore:::cmdline2)r�r�r�r�r��test_init_warnoptionsr)rr7rr)r-r�rr�rrrr�os
�
	
�z%InitConfigTests.test_init_warnoptionscCs"dddgd�}|jd|td�dS)Nrrzerror::BytesWarning)r�r�r��test_init_set_configrrBrGrrrr��s�
�z$InitConfigTests.test_init_set_configcC�|�d�dS)N�test_get_argc_argv�rKr2rrrr���z"InitConfigTests.test_get_argc_argvr1)NNNNN)NN)Ur[r\r]r~r$r��objectr�r�r��PYMEM_ALLOCATOR_NOT_SETr
rrrr	rrr�r%r�rrr
r�r�r�r;rrr��classmethodr�r�r�r�r�r�r�rrrrrrrr(r1r2r6r9r:r=rArErHrJrKrLrMrNrOrRrTrWrYr_r`rergrjr��
contextlib�contextmanagerrxrzr}rkZskipIfr�r�r�r�r�r�rrrrr�Cs��	���
�������	�
���
���������������!�"�#�$�%�&�'�)�*�+�,�-�.�/�0�1�2�3�4�5�7�8�:�;�<�=�E�����

�	



�E
��<>			


! 

?&	r�c@�eZdZdd�ZdS)�SetConfigTestscCsBtjdddg}tj|tjtjd�}|�|jd|j|j|jf�dS)Nr?z-mztest._test_embed_set_config)r8r9r)	r%r&r=rar?rEr5r8r9)r-rGr�rrr�test_set_config�s�
�zSetConfigTests.test_set_configN)r[r\r]r�rrrrr���r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�
AuditingTestscCr�)N�test_open_code_hookr�r2rrrr��r�z!AuditingTests.test_open_code_hookcCr�)N�
test_auditr�r2rrrr��r�zAuditingTests.test_auditcCr�)N�test_audit_subinterpreterr�r2rrrr��r�z'AuditingTests.test_audit_subinterpretercC�|jdtjdd�dS)N�test_audit_run_commandr
�r4r5�rKr�
SHORT_TIMEOUTr2rrrr���
�z$AuditingTests.test_audit_run_commandcCr�)N�test_audit_run_filer
r�r�r2rrrr��r�z!AuditingTests.test_audit_run_filec	Cs�tj�|jtj�d}t|ddd��}td|d�td|d�Wd�n1s)wYzit��d|i�}|j	d	t
jd
|d�Wt�|�dSt�|�w)N�.pyrrvr�z
import sysr�z&sys.__interactivehook__ = lambda: None�
PYTHONSTARTUP�test_audit_run_interactivehook�
�r4r5r�
r
rr'r+rZTESTFNr�rDrrKrr��unlink�r-Zstartup�frrrrr��s��z,AuditingTests.test_audit_run_interactivehookc	Cs�tj�|jtj�d}t|ddd��}td|d�Wd�n1s#wYzit��d|i�}|j	dt
jd	|d
�Wt�|�dSt�|�w)Nr�rrvr�r%r�r��test_audit_run_startupr�r�r�r�rrrr��s��z$AuditingTests.test_audit_run_startupcCr�)N�test_audit_run_stdinr
r�r�r2rrrr��r�z"AuditingTests.test_audit_run_stdinN)r[r\r]r�r�r�r�r�r�r�r�rrrrr��s
r�c@r�)�	MiscTestscCr�)N�test_unicode_id_initr�r2rrrr��szMiscTests.test_unicode_id_initN)r[r\r]r�rrrrr��r�r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StdPrinterTestsr
cCs,t�d�}|jj}|jf|_|j|_||�S)Nr�)rr�r��PyFile_NewStdPrinterZc_intr�Z	py_objectr�)r-�fdr�r�rrr�create_printer�s


zStdPrinterTests.create_printerc
Cs�d}|j}t�|�}|�tj|�t��\}}|�tj|�|�tj|�zt�||�|�|�}|�|�Wt�||�nt�||�wt�	|d�}|�
||�dd��dS)Nuunicode:é-€-�!
�dr@�backslashreplace)�	STDOUT_FDr
�dupZ
addCleanup�close�pipe�dup2r�r��readrE�encode)r-�messageZ	stdout_fdZstdout_fd_copyZrfdZwfd�printer�datarrr�
test_write�s

zStdPrinterTests.test_writecCsJ|j}|�|�}|�|��|�|�|��t�|��|��|��dSr1)r�r�rE�fileno�isattyr
�flushr��r-r�r�rrr�test_methodss
zStdPrinterTests.test_methodscCs$|j}|�|�}t�|t|��dSr1)r�r�rZcheck_disallow_instantiation�typer�rrr�test_disallow_instantiation
s
z+StdPrinterTests.test_disallow_instantiationN)r[r\r]r�r�r�r�r�rrrrr��sr��__main__))�testrZtest.supportrrrk�collectionsrr�r�r
rQrcr=r%rqr�rr$�platformrbr�r7r*r�rrrrZ
MAX_HASH_SEEDrrrZTestCaser^r�r�r�r�r�r[rYrrrr�<module>sZ

	n"]33�
© 2025 GrazzMean