HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_embed.cpython-37.pyc
B

��g�Q�@s�ddlmZddlZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ejdkZGdd�d�Z
Gdd�de
ej�ZGd	d
�d
e
ej�Zedkr�e��dS)�)�supportN)�
namedtuple�ntc@s2eZdZdd�Zdd�Zdd�dd�Zd	d
�ZdS)�EmbeddingTestsMixincCs�tj�t�}tj�tj�tj�|���}d}tr^dtjkr>dndd}||7}tj�tj�}ntj�|d�}tj�||�|_	}tj�
|�s�|�d|�t��|_
t�|�dS)NZ
_testembedZ_d�z.exeZProgramsz%r doesn't exist)�os�path�abspath�__file__�dirname�
MS_WINDOWS�sys�
executable�join�test_exe�existsZskipTest�getcwd�oldcwd�chdir)�self�hereZbasepathZexenameZextZexepathZexe�r�+/usr/local/lib/python3.7/test/test_embed.py�setUps
zEmbeddingTestsMixin.setUpcCst�|j�dS)N)rrr)rrrr�tearDown%szEmbeddingTestsMixin.tearDownN)�envcGs�|jg}|�|�|dk	r4tr4|��}tjd|d<tj|tjtjd|d�}|�	�\}}|j
dkr�tjr�t
d|�d��t
d|���t
d	|���t
d
�|�|j
dd|j
|f�||fS)z'Runs a test in the embedded interpreterNZ
SYSTEMROOTT)�stdout�stderrZuniversal_newlinesrrz--- z failed ---zstdout:
zstderr:
z------zbad returncode %d, stderr is %r)r�extendr�copyr�environ�
subprocess�Popen�PIPEZcommunicate�
returncoder�verbose�print�assertEqual)rr�args�cmd�p�out�errrrr�run_embedded_interpreter(s(

z,EmbeddingTestsMixin.run_embedded_interpreterccs&|�d�\}}|�|d�d}tdd�}d}g}x�|��D]�}|d�|�krx|�t|�d�tjdkrnt|�|d7}q:|�	t|�d	�t
�||�}|dkr�|�||�||�
��}	tjdkr�t|	�|�|	j�|�|	j�|�|	j�|�|	�t|�d	kr:|d}
|�|	|
�|Vg}q:WdS)
NZ!repeated_init_and_subinterpretersrzS^interp (\d+) <(0x[\dA-F]+)>, thread state <(0x[\dA-F]+)>: id\(modules\) = ([\d]+)$�Interpzid interp tstate modulesrz--- Pass {} ---��)r-r'r�
splitlines�format�lenrr%r&Z
assertLess�re�matchZassertRegex�groupsZ
assertTrue�interp�tstate�modules�append)rr+r,Z
interp_patr.ZnumloopsZcurrent_run�liner5r7�mainrrr�%run_repeated_init_and_subinterpretersCs:



z9EmbeddingTestsMixin.run_repeated_init_and_subinterpreters)�__name__�
__module__�__qualname__rrr-r=rrrrrsrc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�EmbeddingTestscCs,x&|��D]}|d}|�|jd�q
WdS)Nr�0)r=r'�id)r�runr<rrr�test_subinterps_mainxsz#EmbeddingTests.test_subinterps_maincCs\xV|��D]J}|�^}}}t|j�}x.t|�D]"\}}|�|jt||d��q.Wq
WdS)Nr/)r=�intrC�	enumerater'�str)rrDr<�subs�_Zmainid�i�subrrr�test_subinterps_different_ids~s

z,EmbeddingTests.test_subinterps_different_idscCsrxl|��D]`}|�^}}}d|kr,t�d��x<|D]4}|�|j|j�|�|j|j�|�|j|j�q2Wq
WdS)NZ0x0zplatform prints pointers as 0x0)r=�unittestZSkipTestZassertNotEqualr7r8r9)rrDr<rIrJrLrrr�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)ZPYTHONIOENCODINGZforced_io_encoding)rr/zutf-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: latin-1zstdin: latin-1:{errors}zstdout: latin-1:{errors}z stderr: latin-1:backslashreplacez--- Set encoding and errors ---zExpected errors: replacezstdin: latin-1:replacezstdout: latin-1:replace)Zin_encodingZout_encoding�errors)�dictrr r-rr%r&rr2�maxDiffr'�strip)rrr+r,Zexpected_stream_encodingZexpected_errors�expected_outputrrr�test_forced_io_encoding�sN
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()).
        )�
PYTHONPATHZpre_initialization_api)rZspamzsys.executable: rQrN)
rSrr �pathseprr
rr-rrr�assertInr')rrr+r,Z
expected_pathrVrrr�test_pre_initialization_api�sz*EmbeddingTests.test_pre_initialization_apicCsJttjtj�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).
        )rXZpre_initialization_sys_options)rz�sys.warnoptions: ['once', 'module', 'default']
sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}
warnings.filters[:3]: ['default', 'module', 'once']
rN)
rSrr rYrr
rr-rZr')rrr+r,rVrrr�#test_pre_initialization_sys_options�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.
        Zbpo20891rN)r-r')rr+r,rrr�
test_bpo20891�szEmbeddingTests.test_bpo20891cCs*|�d�\}}|�|d�|�|d�dS)zf
        bpo-33932: Calling Py_Initialize() twice should do nothing (and not
        crash!).
        Zinitialize_twicerN)r-r')rr+r,rrr�test_initialize_twice�sz$EmbeddingTests.test_initialize_twicecCs.|�d�\}}|�|��d�|�|d�dS)zS
        bpo-34008: Calling Py_Main() after Py_Initialize() must not fail.
        Zinitialize_pymainz6Py_Main() after Py_Initialize: sys.argv=['-c', 'arg2']rN)r-r'�rstrip)rr+r,rrr�test_initialize_pymain�sz%EmbeddingTests.test_initialize_pymainN)r>r?r@rErMrOrWr[r\r]r^r`rrrrrAws+
	rAc@seZdZdZerdndZdZe�Zdddddddddddddddddgdggddeeeedd	�Z	d
Z
dZdZdddeedddddddddddd
�Z
er�e
�ddd��ddgZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�ZdS))�InitConfigTestsi�
surrogatepassrP)Zdll_pathrZmodule_search_pathsr/rNz./_testembed)�install_signal_handlers�ignore_environment�
use_hash_seed�	hash_seed�	allocator�dev_mode�faulthandler�tracemalloc�import_time�show_ref_count�show_alloc_countZ	dump_refs�malloc_stats�	utf8_modeZcoerce_c_localeZcoerce_c_locale_warn�program_name�argv�program�xoptions�warnoptionsZmodule_search_path_env�home�prefix�base_prefix�exec_prefix�base_exec_prefixZ_disable_importlib)Zmodule_search_path)rqryrwrxrrcrvrt)ZPy_HasFileSystemDefaultEncoding)�Py_BytesWarningFlagZPy_DebugFlag�Py_DontWriteBytecodeFlag� Py_FileSystemDefaultEncodeErrors�Py_FileSystemDefaultEncoding�
Py_FrozenFlagZPy_HashRandomizationFlag�Py_InspectFlag�Py_InteractiveFlag�Py_IsolatedFlag�
Py_NoSiteFlag�Py_NoUserSiteDirectory�Py_OptimizeFlag�Py_QuietFlag�Py_UnbufferedStdioFlag�Py_VerboseFlag)ZPy_LegacyWindowsFSEncodingFlagZPy_LegacyWindowsStdioFlag)ZPy_IgnoreEnvironmentFlagrd)ZPy_UTF8ModerocCs@i}x6|D].}d|kr0|�dd�\}}|||<q
d||<q
W|S)N�=r/T)�split)rZ
xoptions_listrs�opt�key�valuerrr�
main_xoptionsjs

zInitConfigTests.main_xoptionscCsh|d}|d}x|jD]
}||=qWi}x|jD]}||||<q2W|�|d�|d<|�||�dS)N�core_config�main_configrs)�UNTESTED_MAIN_CONFIG�COPY_MAIN_CONFIGr�r')r�configr�r�r��expectedrrr�check_main_configts
z!InitConfigTests.check_main_configcCs�t|jf|�}t|jf|�}t�d�}tjdd|f}t|�}|dsTd|d<d|d<tj||tj	tj
d�}|jr�td	|j
�d
|j����|j
�d�}t�|�}x*|��D]\}	}
|
|jkr�||	||	<q�Wx*|��D]\}	}
|
|jkr�||	||	<q�W||fS)Na[
            import json
            import sys

            data = {
                'prefix': sys.prefix,
                'base_prefix': sys.base_prefix,
                'exec_prefix': sys.exec_prefix,
                'base_exec_prefix': sys.base_exec_prefix,
                'Py_FileSystemDefaultEncoding': sys.getfilesystemencoding(),
                'Py_FileSystemDefaultEncodeErrors': sys.getfilesystemencodeerrors(),
            }

            data = json.dumps(data)
            data = data.encode('utf-8')
            sys.stdout.buffer.write(data)
            sys.stdout.buffer.flush()
        z-Sz-cr�rB�PYTHONCOERCECLOCALE�
PYTHONUTF8)rrrz)failed to get the default config: stdout=z stderr=zutf-8)rS�DEFAULT_CORE_CONFIG�DEFAULT_GLOBAL_CONFIG�textwrap�dedentr
rr!rDr#ZSTDOUTr$�	Exceptionrr�decode�json�loads�items�GET_DEFAULT_CONFIG)r�
expected_core�expected_globalr�coder(�procrr�r�r�rrr�get_expected_config�s.



z#InitConfigTests.get_expected_configcCs8t|d�}x|jD]}|�|d�qW|�||�dS)Nr�)rS�UNTESTED_CORE_CONFIG�popr')rr�r�r�r�rrr�check_core_config�sz!InitConfigTests.check_core_configcCs�|d}xN|jD]D}t|�dkr@|\}}}||r6dnd||<q|\}}||||<qWt|d�}	x|jD]
}
|	|
=qlW|�|	|�dS)Nr��rr/�
global_config)�COPY_GLOBAL_CONFIGr3rS�UNTESTED_GLOBAL_CONFIGr')rr�r�rr��itemZ
global_keyZcore_keyZoppositer�r�rrr�check_global_config�s

z#InitConfigTests.check_global_configc	Cs�ttj�}x t|�D]}|�d�r||=qWd|d<d|d<|j||d�\}}t�|�}|�|||�\}}|�	||�|�
|�|�|||�dS)NZPYTHONrBr�r�)r)rSrr �list�
startswithr-r�r�r�r�r�r�)	rZtestnamer�r�rr�r+r,r�rrr�check_config�s




zInitConfigTests.check_configcCs|�dii�dS)NZinit_default_config)r�)rrrr�test_init_default_config�sz(InitConfigTests.test_init_default_configcCs>ddd�}dd|jddddddddddd�
}|�d||�dS)Nz./globalvarr/)rprozutf-8�)
rzr{r|r}rr�r�r�r�r�r�r~r�Zinit_global_config)�UTF8_MODE_ERRORSr�)rr�r�rrr�test_init_global_config�s z'InitConfigTests.test_init_global_configcCsTdddddddddddddgd	d
ddgd
dgdd�}|jddd�}|�d||�dS)Nrr/�{�malloc_debugr�z./conf_program_namez-c�passZconf_programzcore_xoption1=3zcore_xoption2=Z
core_xoption3�defaultzerror::ResourceWarning)rcrerfrgrjrkrlrmrnrorprqrrrsrtrizutf-8)r|r}r�Zinit_from_config)r�r�)rr�r�rrr�test_init_from_config�s(z%InitConfigTests.test_init_from_configc
CsBdddddddddd�	}d|jddddddd�}|�d||�dS)	Nr/�*r�r�)	rerfrgrjrkrnrorirhzutf-8)r{r|r}rr�r�r�r�Zinit_env)r�r�)rr�r�rrr�
test_init_envs$zInitConfigTests.test_init_envcCsdddd�}|�d|i�dS)Nr/�debug)rhrirgZ
init_dev_mode)r�)rr�rrr�test_init_dev_mode)sz"InitConfigTests.test_init_dev_modecCs$ddi}ddd�}|�d||�dS)Nrdr/)r�r�Z
init_isolated)r�)rr�r�rrr�test_init_isolated1sz"InitConfigTests.test_init_isolated)r>r?r@rTrr�r��objectr�r�r�r�r�r��updater�r�r�r�r�r�r�r�r�r�r�r�r�rrrrras�

/ra�__main__)ZtestrrN�collectionsrr�rr4r!r
r��namerrZTestCaserArar>r<rrrr�<module>s"
f=