Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_embed.cpython-38.pyc
U

>��g���@sddlmZddlZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ejdkZejdkZdZdZdZdZdZdZd	d
�Zdd�ZGd
d�d�ZGdd�deej�ZGdd�deej�ZGdd�deej�Zedkr�e� �dS)�)�supportN)�
namedtuple�nt�darwin���cCs.tj�|�}tj�|�d}|���d���S)Nr�_d)�os�path�basename�splitext�casefold�endswith)Zprogram�name�r�./opt/cppython/lib/python3.8/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�r>dndd}||7}tj�tj�}ntj�	|d�}tj�	||�|_
}tj�|�s�|�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�setUp0s
zEmbeddingTestsMixin.setUpcCst�|j�dS�N)r
r)r(�r*rrr�tearDownCszEmbeddingTestsMixin.tearDownNr)r�timeout�
returncode�input�cwdcGs�|jg}|�|�|dk	r4tr4|��}tjd|d<tj|tjtjd||d�}z|j	||d�\}	}
Wn|�
�|���YnX|j|kr�t
jr�td|�d��td|	���td	|
���td
�|�|j|d|j|
f�|	|
fS)z'Runs a test in the embedded interpreterNZ
SYSTEMROOTT)�stdout�stderr�universal_newlinesrr4)r3r1z--- z failed ---zstdout:
zstderr:
z------zbad returncode %d, stderr is %r)r%�extendr!�copyr
r�
subprocess�Popen�PIPE�communicate�	terminate�waitr2r�verbose�print�assertEqual)r*rr1r2r3r4�args�cmd�p�out�errrrr�run_embedded_interpreterFs:
�
��z,EmbeddingTestsMixin.run_embedded_interpreterccs"|�d�\}}|�|d�d}tdd�}d}g}|��D]�}|d�|�krv|�t|�d�tjdkrlt|�|d7}q8|�	t|�d	�t
�||�}|dkr�|�||�||�
��}	tjdkr�t|	�|�|	j�|�|	j�|�|	j�|�|	�t|�d	kr8|d}
|�|	|
�|Vg}q8dS)
NZ&test_repeated_init_and_subinterpretersrzS^interp (\d+) <(0x[\dA-F]+)>, thread state <(0x[\dA-F]+)>: id\(modules\) = ([\d]+)$�Interpzid interp tstate modulesrz--- Pass {} ---r�)rHrBr�
splitlines�format�lenrr@rAZ
assertLess�re�matchZassertRegex�groupsZ
assertTrue�interp�tstate�modules�append)r*rFrGZ
interp_patrIZnumloopsZcurrent_run�linerOrQ�mainrrr�%run_repeated_init_and_subinterpretersis:



z9EmbeddingTestsMixin.run_repeated_init_and_subinterpreters)�__name__�
__module__�__qualname__r-r0rHrWrrrrr/s�#rc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�EmbeddingTestscCs(|��D]}|d}|�|jd�qdS)Nr�0)rWrB�id)r*�runrVrrr�test_subinterps_main�sz#EmbeddingTests.test_subinterps_maincCsT|��D]F}|�^}}}t|j�}t|�D]"\}}|�|jt||d��q*qdS)Nr)rW�intr]�	enumeraterB�str)r*r^rV�subs�_Zmainid�i�subrrr�test_subinterps_different_ids�s

z,EmbeddingTests.test_subinterps_different_idscCsj|��D]\}|�^}}}d|kr*t�d��|D]4}|�|j|j�|�|j|j�|�|j|j�q.qdS)NZ0x0zplatform prints pointers as 0x0)rW�unittestZSkipTestZassertNotEqualrQrRrS)r*r^rVrcrdrfrrr�test_subinterps_distinct_state�s
z-EmbeddingTests.test_subinterps_distinct_statecCs�ttjdd�}|jd|d�\}}tjdkr@t�t|�t|�d}d}d�d	d
ddd
ddd
ddddddddddddddddg�}|j|||d�}d|_	|�
|��|�dS)Nzutf-8:surrogateescape)ZPYTHONIOENCODING�test_forced_io_encoding�rr�utf-8�surrogateescape�
z--- Use defaults ---zExpected encoding: defaultzExpected errors: defaultzstdin: {in_encoding}:{errors}zstdout: {out_encoding}:{errors}z'stderr: {out_encoding}:backslashreplacez--- Set errors only ---zExpected errors: ignorezstdin: {in_encoding}:ignorezstdout: {out_encoding}:ignorez--- Set encoding only ---zExpected encoding: iso8859-1zstdin: iso8859-1:{errors}zstdout: iso8859-1:{errors}z"stderr: iso8859-1:backslashreplacez--- Set encoding and errors ---zExpected errors: replacezstdin: iso8859-1:replacezstdout: iso8859-1:replace)Zin_encodingZout_encoding�errors)rr
rrHrr@rAr$rL�maxDiffrB�strip)r*rrFrGZexpected_stream_encodingZexpected_errors�expected_outputrrrrj�sR
��z&EmbeddingTests.test_forced_io_encodingcCspttjtj�tj�d�}|jd|d�\}}tr6|j	}ntj�t�
�d�}d|�d�}|�||�|�|d�dS)	z�
        Checks some key parts of the C-API that need to work before the runtine
        is initialized (via Py_Initialize()).
        )�
PYTHONPATH�test_pre_initialization_apirkZspamzsys.executable: rnrN)
rr
r�pathsepr$r"rrHr!r%r'�assertInrB)r*rrFrGZ
expected_pathrrrrrrt�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).
        rs�#test_pre_initialization_sys_optionsrkz�sys.warnoptions: ['once', 'module', 'default']
sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}
warnings.filters[:3]: ['default', 'module', 'once']
rN)	rr
rur$r"rrHrvrB)r*rrFrGrrrrrrw�s�
�z2EmbeddingTests.test_pre_initialization_sys_optionscCs*|�d�\}}|�|d�|�|d�dS)z�
        bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
        calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
        call PyEval_InitThreads() for us in this case.
        �
test_bpo20891rN�rHrB�r*rFrGrrrrxszEmbeddingTests.test_bpo20891cCs*|�d�\}}|�|d�|�|d�dS)zf
        bpo-33932: Calling Py_Initialize() twice should do nothing (and not
        crash!).
        �test_initialize_twicerNryrzrrrr{s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']rN�rHrB�rstriprzrrrr|sz%EmbeddingTests.test_initialize_pymaincCs.|�d�\}}|�|��d�|�|d�dS)N�
test_run_mainz%Py_RunMain(): sys.argv=['-c', 'arg2']rr}rzrrrr'szEmbeddingTests.test_run_mainN)
rXrYrZr_rgrirjrtrwrxr{r|rrrrrr[�s+
	r[c6@s0eZdZdZerdndZe�Ze�Ze	e
dddddd�ZerJe�ddi�e
eedeed�Ze
eeddddddd	�Zd
ddgZe	dddddddddddddeed
eddgggd
d
eeeeeeeddddddddddddeedd
d
d
ddddd�5Ze�re�ddi�e
eeddd�Ze
eedddddddddd�Ze�r@ded<dddd�ZdgZddddddddddd d!d"d#d$d%gZe�r�e�d&�e�d'�d
Zed(d)��Zd*d+�Zd,d-�Zd.d/�Zd�d0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#d�d
d
d8d
d9�d:d;�Z$d<d=�Z%d>d?�Z&d@dA�Z'dBdC�Z(dDdE�Z)dFdG�Z*dHdI�Z+dJdK�Z,dLdM�Z-dNdO�Z.dPdQ�Z/dRdS�Z0dTdU�Z1dVdW�Z2dXdY�Z3dZd[�Z4d\d]�Z5d^d_�Z6d`da�Z7dbdc�Z8ddde�Z9dfdg�Z:dhdi�Z;djdk�Z<dldm�Z=dndo�Z>dpdq�Z?drds�Z@dtdu�ZAd�dvdw�ZBeCjDdxdy��ZEdzd{�ZFd|d}�ZGeH�Ied~�dd���ZJd�d��ZKd�d��ZLd�d��ZMd
S)��InitConfigTestsi�
surrogatepassrmrr)�_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�Nr�default)5r�r�r�r��install_signal_handlers�
use_hash_seed�	hash_seed�faulthandler�tracemalloc�import_time�show_ref_count�show_alloc_countZ	dump_refs�malloc_stats�filesystem_encoding�filesystem_errors�pycache_prefix�program_namer��argv�xoptions�warnoptions�pythonpath_env�homer#�base_executable�prefix�base_prefix�exec_prefix�base_exec_prefix�module_search_paths�site_import�
bytes_warning�inspect�interactive�optimization_level�parser_debug�write_bytecoder@�quiet�user_site_directory�configure_c_stdio�buffered_stdio�stdio_encoding�stdio_errorsZskip_source_first_line�run_commandZ
run_module�run_filenameZ_install_importlib�check_hash_pycs_mode�pathconfig_warnings�
_init_main�legacy_windows_stdio)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_VerboseFlagr@))ZPy_LegacyWindowsFSEncodingFlagr�))ZPy_LegacyWindowsStdioFlagr�cCs
d|_dSr.)�EXPECTED_CONFIG)�clsrrr�
tearDownClass�szInitConfigTests.tearDownClasscCs<i}|D].}d|kr.|�dd�\}}|||<qd||<q|S)N�=rT)�split)r*Z
xoptions_listr��optr�valuerrr�
main_xoptions�s

zInitConfigTests.main_xoptionscCs�t�}t�d�}tjdd|g}tj||tjtjd�}|jrRt	d|j
�d|j����|j
�d�}zt
�|�WSt
jk
r�|�d|���YnXdS)	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)rr5r6z)failed to get the default config: stdout=z stderr=rl�fail to decode stdout: )r�textwrap�dedentr"r#r:r^r<r2�	Exceptionr5r6�decode�json�loads�JSONDecodeError�fail)r*r�coderC�procr5rrr�_get_expected_config_impl�s
�z)InitConfigTests._get_expected_config_implcCslt}|jdkr|��|_i}|j��D]@\}}i}|��D]"\}}t|t�rT|��}|||<q:|||<q&|Sr.)r�r�r��items�
isinstancerr9)r*r��configsZ
config_keyZconfig_value�configrr�rrr�_get_expected_config	s




z$InitConfigTests._get_expected_configcCs|j}|��}|d}|��D]\}	}
|
|jkr||	||	<q|drN|tkrbdD]}	|j||	<qR|dst|j|d<|ddkr�|d|jkr�d|d<|d|jkr�|j|d<|d	|jkr�d|d	<|d
|jkr�d|d
<tr�|j}n4|d|jk	�rt	j
�|d�}nt	j
�t	�
�d
�}|d|jk�r2||d<|d|jk�rJ||d<|d|jk�rbd|d<|d}|��D]"\}	}
|
|jk�rr||	||	<�qr|d}
|
dk	�r�|
�t	j
j�}||d�|d<|dk	�r�|d��|d<||d�|jD]}	|	|k�r�||	||	<�q�dS)N�
pre_configr�)r�r�r�r�r�rr�rlr�r�r�rmr�rr#r�z./_testembedr�r�r�)�	__class__r�r��GET_DEFAULT_CONFIG�
API_COMPAT�
IGNORE_CONFIG�UTF8_MODE_ERRORSr!r%r
rrr$r'r�rur9�COPY_PRE_CONFIG)r*�expected_preconfig�expectedr�api�modify_path_cbr�r�r�rr�Zdefault_executabler�r��pathsrrr�get_expected_configsZ






z#InitConfigTests.get_expected_configcCsNt|d�}t|���D]$\}}||jkr|�|d�||=q|�||�dS)Nr��rrr�r��poprB)r*r�r�r�rr�rrr�check_pre_configXs
z InitConfigTests.check_pre_configcCsNt|d�}t|���D]$\}}||jkr|�|d�||=q|�||�dS)Nr�r�)r*r�r�r�rr�rrr�check_config`s
zInitConfigTests.check_configc	Cs�|d}|d}t|j�}|jD]D}t|�dkrP|\}}}||rFdnd||<q |\}}||||<q |jD]D}t|�dkr�|\}}}||r�dnd||<ql|\}}||||<ql|�|d|�dS)Nr�r�rrrZ
global_config)r�DEFAULT_GLOBAL_CONFIG�COPY_GLOBAL_CONFIGrM�COPY_GLOBAL_PRE_CONFIGrB)	r*r�r�r�r��itemZ
global_keyZcore_keyZoppositerrr�check_global_confighs 




z#InitConfigTests.check_global_configF)�
preconfig_apir�
ignore_stderrr4cCsXt�}|dk	r|�|�|}|dkr(|}|tkr8|j}n|tkrH|j}n|j}|dkrZi}t|f|�}|dkrri}|tkr�|j}
n|tkr�|j	}
n|j
}
t|
f|�}|�|||||�|j|||
d�\}}|dkr�|ds�d}|dk	r�|	s�|�
|��|�zt�|�}Wn(tjk
�r0|�d|���YnX|�||�|�||�|�|�|S)N)rr4r@rr�)r�update�API_ISOLATED�PRE_CONFIG_ISOLATED�
API_PYTHON�PRE_CONFIG_PYTHON�PRE_CONFIG_COMPATr�
CONFIG_PYTHON�CONFIG_ISOLATED�
CONFIG_COMPATr�rHrBr~r�r�r�r�r�r�r�)r*ZtestnameZexpected_configr�r�r6r�r�rr�r4Znew_envZdefault_preconfigZdefault_configrFrGr�rrr�check_all_configs~sX
��

z!InitConfigTests.check_all_configscCs|jdtd�dS)NZtest_init_initialize_config�r��r�r�r/rrr�test_init_default_config�sz(InitConfigTests.test_init_default_configcCs|jdtd�dS)N�test_preinit_compat_configr�r�r/rrrr��sz*InitConfigTests.test_preinit_compat_configcCs|jdtd�dS)N�test_init_compat_configr�r�r/rrrr��sz'InitConfigTests.test_init_compat_configcCs@ddi}ddddgdddddddddd�
}|jd||td	�dS)
Nr�rz./globalvarr�default::BytesWarningr)
r�r�r�r�r�r�r�r�r@r�r�r�r��test_init_global_configr�r��r*�	preconfigr�rrrr��s(��
�z'InitConfigTests.test_init_global_configc Csvtdd�}dddddddddddd	d
dgddd
ddgdddgdddddddddddddddd�}|jd||td�dS)Nr�r�r�r�{r�	iso8859-1�replaceZconf_pycache_prefixz./conf_program_namer��arg2zconfig_xoption1=3zconfig_xoption2=Zconfig_xoption3�cmdline_xoptionZcmdline_warnoptionr�Zconfig_warnoption�pass
�always)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r@r�r�r�r�r�r�r��test_init_from_configr���PYMEM_ALLOCATOR_MALLOCr�r�r�rrrr�sZ����.
�z%InitConfigTests.test_init_from_configcCsHdti}dddddddddddddd	ddd
gd�}|jd||td
�dS)Nr�r�*r�/my/path�env_pycache_prefixrr�r�EnvVar�r�r�r�r�r�r�r�r�r�r�r@r�r�r�r�r�r��test_init_compat_envr�rr�rrrr
s0��
�z$InitConfigTests.test_init_compat_envcCsJtdd�}dddddddddddddd	ddd
gd�}|jd||td
�dS)Nrr�rrr	r
rr�rrr�test_init_python_envr�)rr�r�r�rrrr!s0��
�z$InitConfigTests.test_init_python_envcCs0ttd�}tdddgd�}|jd||td�dS)N�r�rr��r�r�r��test_init_env_dev_moder�)r�PYMEM_ALLOCATOR_DEBUGr�r�r�rrrr<s
�
�z&InitConfigTests.test_init_env_dev_modecCs0ttd�}tdddgd�}|jd||td�dS)Nrrr�r�test_init_env_dev_mode_allocr�)rrr�r�r�rrrrDs
�
�z,InitConfigTests.test_init_env_dev_mode_alloccCs,dti}dddgd�}|jd||td�dS)Nr�rr�)r�r�r��test_init_dev_moder��rr�r�r�rrrrLs��
�z"InitConfigTests.test_init_dev_modecCs6dti}dgddddgdgd�}|jd||td�dS)	Nr��	script.pyrr��dev)r�r�r�r�r�r��test_preinit_parse_argvr�rr�rrrrXs��
�z'InitConfigTests.test_preinit_parse_argvcCs8ddi}dddddddd	gdd
�}|jd||td�dS)
Nr�r�python3�-Ez-Iz-Xr�utf8r)r�r��test_preinit_dont_parse_argvr��r�r�r�rrrris���
�z,InitConfigTests.test_preinit_dont_parse_argvcCs dddd�}|jd|td�dS)Nrr�r�r�r��test_init_isolated_flagr��r�r��r*r�rrrrvs
�z'InitConfigTests.test_init_isolated_flagcCs dddd�}|jd|td�dS)Nrrr�test_preinit_isolated1r�r�r!rrrr"~s
�z&InitConfigTests.test_preinit_isolated1cCs dddd�}|jd|td�dS)Nrrr�test_preinit_isolated2r�r�r!rrrr#�s
�z&InitConfigTests.test_preinit_isolated2cCs|jdtd�dS)N�test_preinit_isolated_configr�rr/rrrr$�sz,InitConfigTests.test_preinit_isolated_configcCs|jdtd�dS)N�test_init_isolated_configr�rr/rrrr%�sz)InitConfigTests.test_init_isolated_configcCs|jdtd�dS)N�test_preinit_python_configr�r r/rrrr&�sz*InitConfigTests.test_preinit_python_configcCs|jdtd�dS)N�test_init_python_configr�r r/rrrr'�sz'InitConfigTests.test_init_python_configcCs ddd�}|jdi|td�dS)Nr)r�r��test_init_dont_configure_localer�r )r*r�rrrr(�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)NrZtest_path_insert1Ztest_path_append)�insertrT)rrrr�modify_path�sz7InitConfigTests.test_init_read_set.<locals>.modify_path�test_init_read_set)r�r�r )r*r�r*rrrr+�s��z"InitConfigTests.test_init_read_setcCs.dddddgdddgd	�}|jd
|td�dS)NrZconfig_xoptionrZsysadd_xoptionr�zignore:::cmdline_warnoptionzignore:::sysadd_warnoptionzignore:::config_warnoption)r�r�r��test_init_sys_addr�r r!rrrr,�s���z!InitConfigTests.test_init_sys_addcCs.d}ddgd|ddd�}|jd|td	�dS)
N�Rimport _testinternalcapi, json; print(json.dumps(_testinternalcapi.get_configs()))r�r�	./python3rnr)r�r�r�r��test_init_run_mainr�r �r*r�r�rrrr/�s�z"InitConfigTests.test_init_run_maincCs2d}ddgd|dddd�}|jd	|td
d�dS)Nr-r�rr.rnrr)r�r�r�r�r��test_init_mainz)Run Python code before _Py_InitializeMain)r�r6r r0rrrr1�s��zInitConfigTests.test_init_maincCs,dddddgdddd	�}|jd
|td�dS)Nrr��arg1�-v�arg3�./argv0rr)r�r�r�r�r��test_init_parse_argvr�r r!rrrr6�s
�z$InitConfigTests.test_init_parse_argvcCs8ddi}dddddddd	gdd
�}|jd||td�dS)
Nr�rr5rr��passr2r3r4)r�r�r��test_init_dont_parse_argvr�r )r*r�r�rrrr8�s��
�z)InitConfigTests.test_init_dont_parse_argvcCsDtrd}|j}nd}tr |j}nt�|�p,d}|�|||d��dS)N�pythonrr)r�r�r#)r!r%�MACOS�shutil�whichr�)r*r�r�r#rrr�default_program_name�s�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�r=r
rrur$r�r��r*r�r�rrrrr?s�
�z!InitConfigTests.test_init_setpathc	CsT|��}|dd}|dddddddd�}dtjj�|�i}|jd|t|d	d
�dS)Nr�r�rZconf_program_nameZconf_executable)r�r�r�r�r�r�r�r#r>�test_init_setpath_configTr@)r�r
rrur$r�r�rArrrrBs"��z(InitConfigTests.test_init_setpath_configc
Cs�|��}|dkr|dd}|dkr0|dd}tr@|ddStj}tj�|dd|j�|j�d��tj�|dd|j�d|j���tj�|dd|j�d|j��d�gSdS)	Nr�r�r��libr9z.zip�.�lib-dynload)	r�r!r"�version_infor
rr$�major�minor)r*r�r�r��verrrrr�)s&
�
�
��z#InitConfigTests.module_search_pathsc	cs,t����}tj�|�}tr�tj}d|j�|j	��}d|j��}t
tj�rZ|d7}|d7}|d7}|d7}tj�tj�
|j�|�}tj�tj�
|j�|�}tj�|tj�|��}tj�|tj�|��}t�||�t�||�tj�|tj�|j��}t�|j|�t�|j|�||_|VW5QRXdS)Nr9r	z.dll)�tempfile�TemporaryDirectoryr
r�realpathr!r"rFrGrHrr#r$r r%rr;�copyfile�copystat)r*�tmpdirrIZdllZdll3Zdll_copyZ	dll3_copyZ	exec_copyrrr�tmpdir_with_python<s,
z"InitConfigTests.tmpdir_with_pythoncCs�|��}|dd}tjj�|�}|D]8}tj�|�s8q&tj�tj�|d��r&tj�|�}qpq&|�d|���|}}t	j
}|j||d�}	||	|||||d�}|�|�||d�}
|j
d|t|
d	�dS)
Nr�r��os.pyzUnable to find home in )r�r�)r�r�r�r�r�r�r�)ZTESTHOMErs�test_init_setpythonhome)r�r)r�r
rrur$�isdirr&r r�r"rFr�r=r�r�)r*r�r��	paths_strrr�r�r�rIZexpected_pathsrrrrrR^s6�	

�z'InitConfigTests.test_init_setpythonhomecCs6|��}|dd}tjj�|�}||d<d|i}|S)Nr�r�r�rs)r�r
rrur$)r*r�Zall_configsr�rTrrrr�copy_paths_by_envsz!InitConfigTests.copy_paths_by_envz#Windows does not use pybuilddir.txtc

Cs�|����}d}tj�||�}t�|�tj�|d�}t|ddd��}|�|�W5QRX|��}||d<|j}|||d�}|�	|�}	|j
d|t|	d	|d
�W5QRXdS)N�libdirzpybuilddir.txt�wr��encoding���)r�r#r�r�T�r�rr�r4)rPr
rr$�mkdir�open�writer�r%rUr�r�)
r*rOZsubdirrV�filename�fpr�r#r�rrrr�test_init_pybuilddir�s*

�
�z$InitConfigTests.test_init_pybuilddircCs�|�����}t�����}tj}tsPtj�|dd|j	�d|j
��d�}t�|�n0tj�|d�}t�|�t�
tjtj�|d��tj�|d�}t|ddd	��"}td
||d�td|d�W5QRX|��}ts�||d
<nZt|�D]H\}}	|dk�rtj�|tj�|	��||<q�tj�|tj�|	��||<q�||d
<|j}
|}|||
|
|d�}t�rd||d<||d<|�|�}
|jd|t|
d|d�}t�r�|�|ddtj�|tj�|jdd���W5QRXW5QRXdS)NrCr9rDrErQz
pyvenv.cfgrWrrXz	home = %s��filez$include-system-site-packages = falserZr)r�r�r�r#r�r�r�r�Tr[ZwindowsZpython3_dll)rPrJrKr"rFr!r
rr$rGrH�makedirsr;rMrr]rAr�rarr%rUr�r�rBr�)r*rOZpyvenv_homerIZlib_dynloadr_r`r��indexrr#r�r�r�actualrrr�test_init_pyvenv_cfg�sj��


�
�
��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)�getattrZ	pythonapiZargtypesZ	c_wchar_pZrestype)r�func�rhrr�get_func�s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_configsrBr�r
rru)
r*rirmrnrorprqrrrsr�rrlr�test_global_pathconfig�s$

�z&InitConfigTests.test_global_pathconfigcCsHddddddddd	d
dg}ttd�}d
d
d
|d�}|jd||td�dS)Nzignore:::PyConfig_Insert0r�z
ignore:::env1z
ignore:::env2zignore:::cmdline1zignore:::cmdline2r�zignore:::PySys_AddWarnOption1zignore:::PySys_AddWarnOption2zignore:::PyConfig_BeforeReadzignore:::PyConfig_AfterReadrr)r�r�r�r��test_init_warnoptionsr�)rrr�r�)r*r�r�r�rrrrvs*�
�
�z%InitConfigTests.test_init_warnoptions)N)NNNN)NN)NrXrYrZrpr!r��objectr�r�r��PYMEM_ALLOCATOR_NOT_SETr�r�rr�r�r�r�r�r�r�r�r�r�r�r8r��classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrrrrr"r#r$r%r&r'r(r+r,r/r1r6r8r=r?rBr��
contextlib�contextmanagerrPrRrUrhZskipIfrargrurvrrrrr�-s��	�����A������



�
?��36
			


!!

=&r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�
AuditingTestscCs|�d�dS)N�test_open_code_hook�rHr/rrrr}!sz!AuditingTests.test_open_code_hookcCs|�d�dS)N�
test_auditr~r/rrrr$szAuditingTests.test_auditcCs|�d�dS)N�test_audit_subinterpreterr~r/rrrr�'sz'AuditingTests.test_audit_subinterpretercCs|jdddd�dS)N�test_audit_run_commandrr�r1r2r~r/rrrr�*sz$AuditingTests.test_audit_run_commandcCs|jdddd�dS)N�test_audit_run_filerrr�r~r/rrrr�-sz!AuditingTests.test_audit_run_filec	Cs�tj�|jtj�tjpdd}t|ddd��}td|d�td|d�W5QRXz$t
�d	|i�}|jd
dd|d
�W5t�	|�XdS)Nr�.pyrWrlrXz
import sysrbz&sys.__interactivehook__ = lambda: None�
PYTHONSTARTUP�test_audit_run_interactivehookrJ�
�r1r2r�r
rr$r(rZTESTFNZFS_NONASCIIr]rA�unlinkrrH�r*Zstartup�frrrrr�0s �
z,AuditingTests.test_audit_run_interactivehookc	Cs|tj�|jtj�tjpdd}t|ddd��}td|d�W5QRXz$t
�d|i�}|jd	d
d|d�W5t�	|�XdS)
Nrr�rWrlrXr7rbr��test_audit_run_startuprJr�r�r�r�rrrr�<s �
z$AuditingTests.test_audit_run_startupcCs|jdddd�dS)N�test_audit_run_stdinrrr�r~r/rrrr�Gsz"AuditingTests.test_audit_run_stdinN)rXrYrZr}rr�r�r�r�r�r�rrrrr| sr|�__main__)!�testrrh�collectionsrrzr�r
rNr;r:r"rJr�rr!�platformr:rxrrr�r�r�rrrZTestCaser[r�r|rXrVrrrr�<module>sF

	nz*

F1le Man4ger