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_cmd_line_script.cpython-37.opt-2.pyc
B

��g�t�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZmZmZmZmZmZe
jZdddgZdZefdd	�Zed
fdd�ZGd
d�dej�Zdd�Zedkr�e�dS)�N)�support)�make_pkg�make_script�make_zip_pkg�make_zip_script�assert_python_ok�assert_python_failure�spawn_python�kill_pythonZtest1Ztest2Ztest3a�# Script may be run with optimisation enabled, so don't rely on assert
# statements being executed
def assertEqual(lhs, rhs):
    if lhs != rhs:
        raise AssertionError('%r != %r' % (lhs, rhs))
def assertIdentical(lhs, rhs):
    if lhs is not rhs:
        raise AssertionError('%r is not %r' % (lhs, rhs))
# Check basic code execution
result = ['Top level assignment']
def f():
    result.append('Lower level reference')
f()
assertEqual(result, ['Top level assignment', 'Lower level reference'])
# Check population of magic variables
assertEqual(__name__, '__main__')
from importlib.machinery import BuiltinImporter
_loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__)
print('__loader__==%a' % _loader)
print('__file__==%a' % __file__)
print('__cached__==%a' % __cached__)
print('__package__==%r' % __package__)
# Check PEP 451 details
import os.path
if __package__ is not None:
    print('__main__ was located through the import system')
    assertIdentical(__spec__.loader, __loader__)
    expected_spec_name = os.path.splitext(os.path.basename(__file__))[0]
    if __package__:
        expected_spec_name = __package__ + "." + expected_spec_name
    assertEqual(__spec__.name, expected_spec_name)
    assertEqual(__spec__.parent, __package__)
    assertIdentical(__spec__.submodule_search_locations, None)
    assertEqual(__spec__.origin, __file__)
    if __spec__.cached is not None:
        assertEqual(__spec__.cached, __cached__)
# Check the sys module
import sys
assertIdentical(globals(), sys.modules[__name__].__dict__)
if __spec__ is not None:
    # XXX: We're not currently making __main__ available under its real name
    pass # assertIdentical(globals(), sys.modules[__spec__.name].__dict__)
from test import test_cmd_line_script
example_args_list = test_cmd_line_script.example_args
assertEqual(sys.argv[1:], example_args_list)
print('sys.argv[0]==%a' % sys.argv[0])
print('sys.path[0]==%a' % sys.path[0])
# Check the working directory
import os
print('cwd==%a' % os.getcwd())
cCst|||�}t��|S)N)r�	importlib�invalidate_caches)�
script_dir�script_basename�source�	to_return�r�5/usr/local/lib/python3.7/test/test_cmd_line_script.py�_make_test_scriptNsr�cCst||||||�}t��|S)N)rrr)Zzip_dirZzip_basenameZpkg_namerr�depthrrrr�_make_test_zip_pkgSs
rc@s�eZdZd`dd�Zdd�dd�Zdd�dd�Zd	d
�Zdd�Zej	dadd��Z
dbdd�Zdcdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#ej	dBdC��Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2dS)d�CmdLineTestNc
Cstdkr td|�tt|��|�|d�d|}
d|}d|}d|}
d|}|	dkrdt��}	d	|	}tdkr�td
�t|�t|�t|
�t|�|�|
�d�|�|�|�d�|�|�|�d�|�|�|
�d�|�|�|�d�|�|�|�d�|�dS)NrzOutput from test script %r:rz__loader__==%az__file__==%az__package__==%rzsys.argv[0]==%azsys.path[0]==%azcwd==%azExpected output:zutf-8)�verbose�print�repr�assertEqual�os�getcwd�assertIn�encode)�self�script_nameZ	exit_code�data�
expected_file�expected_argv0�expected_path0�expected_package�expected_loaderZexpected_cwdZprinted_loaderZprinted_fileZprinted_packageZ
printed_argv0Z
printed_path0Zprinted_cwdrrr�
_check_output[s0zCmdLineTest._check_output)�cwdcOs\t|t�r|g}t��||t�}
t|
d|d�|	��\}}}
|�||||
||||||�	dS)NF)�
__isolated�__cwd)�
isinstance�strrZ!optim_args_from_interpreter_flags�example_argsrr()r �script_exec_argsr#r$r%r&r'r)�cmd_line_switches�env_vars�run_args�rc�out�errrrr�
_check_scriptxs

zCmdLineTest._check_scriptc
Os~t|t�r|f}nt|�}||}t|d|d�|��\}}}	tdkrhtd|�tt|	��td|�|�|�d�|	�dS)NF)r*r+rzOutput from test script %r:zExpected output: %rzutf-8)	r,r-�tuplerrrrrr)
r r/Zexpected_msgr)r0r1r2r3r4r5rrr�_check_import_error�s
zCmdLineTest._check_import_errorcCs2tdd�\}}}ttjj��d�}|�||�dS)Nz-czprint(__loader__)zutf-8)rrr�	machinery�BuiltinImporterrr)r r3r4r5�expectedrrr�test_dash_c_loader�szCmdLineTest.test_dash_c_loadercCsNt�}z|j�d�|j��Wdt|�}Xttjj��	d�}|�
||�dS)Nsprint(__loader__)
zutf-8)r	�stdin�write�flushr
rrr9r:rr)r �pr4r;rrr�test_stdin_loader�s
zCmdLineTest.test_stdin_loaderFccsv|rtddtjd�}|j}ntddtjd�}|j}z,x |�d�}|dkrJP|��q6W|VWdt|�|�	�XdS)Nz-ir)�bufsize�stderr�s>>> )
r	�
subprocess�PIPErCZSTDOUT�stdout�read�readliner
�close)r �separate_stderrr@rCr"rrr�interactive_python�s

zCmdLineTest.interactive_pythonc	CsF|�|��2}|j�d�|j��|�d|j�����WdQRXdS)Ns
print('foo')
sfoo)rLr=r>r?rrGrI�strip)r rKr@rrr�check_repl_stdout_flush�s
z#CmdLineTest.check_repl_stdout_flushc	Csp|�|��\}|j�d�|j��|r,|jn|j}|�d|���|�d|���|�d|���WdQRXdS)Ns1/0
s
Traceback sFile "<stdin>"sZeroDivisionError)rLr=r>r?rCrGrrI)r rKr@rCrrr�check_repl_stderr_flush�s
z#CmdLineTest.check_repl_stderr_flushcCs|��dS)N)rN)r rrr�test_repl_stdout_flush�sz"CmdLineTest.test_repl_stdout_flushcCs|�d�dS)NT)rN)r rrr�&test_repl_stdout_flush_separate_stderr�sz2CmdLineTest.test_repl_stdout_flush_separate_stderrcCs|��dS)N)rO)r rrr�test_repl_stderr_flush�sz"CmdLineTest.test_repl_stderr_flushcCs|�d�dS)NT)rO)r rrr�&test_repl_stderr_flush_separate_stderr�sz2CmdLineTest.test_repl_stderr_flush_separate_stderrc	Cs:t���(}t|d�}|�||||dtjj�WdQRXdS)N�script)r�temp_dirrr6rr9�SourceFileLoader)r r
r!rrr�test_basic_script�s



zCmdLineTest.test_basic_scriptc	Cs\t���J}t|d�}tj|dd�t�|�t�|�}|�||||dt	j
j�WdQRXdS)NrTT)�doraise)rrUr�
py_compile�compiler�remove�make_legacy_pycr6rr9�SourcelessFileLoader)r r
r!�pyc_filerrr�test_script_compiled�s



z CmdLineTest.test_script_compiledc	Cs:t���(}t|d�}|�||||dtjj�WdQRXdS)N�__main__�)rrUrr6rr9rV)r r
r!rrr�test_directory�s



zCmdLineTest.test_directoryc	Cs\t���J}t|d�}tj|dd�t�|�t�|�}|�||||dt	j
j�WdQRXdS)Nr`T)rXra)rrUrrYrZrr[r\r6rr9r])r r
r!r^rrr�test_directory_compiled�s




z#CmdLineTest.test_directory_compiledc	Cs,t���}d|}|�||�WdQRXdS)Nz"can't find '__main__' module in %r)rrUr8)r r
�msgrrr�test_directory_error�s
z CmdLineTest.test_directory_errorc	CsHt���6}t|d�}t|d|�\}}|�||||dtj�WdQRXdS)Nr`�test_zipra)rrUrrr6�	zipimport�zipimporter)r r
r!�zip_name�run_namerrr�test_zipfile�s


zCmdLineTest.test_zipfilec	CsVt���D}t|d�}tj|dd�}t|d|�\}}|�||||dtj�WdQRXdS)Nr`T)rXrfra)	rrUrrYrZrr6rgrh)r r
r!�
compiled_namerirjrrr�test_zipfile_compileds

z!CmdLineTest.test_zipfile_compiledc	CsFt���4}t|d�}t|d|�\}}d|}|�||�WdQRXdS)NZnot_mainrfz"can't find '__main__' module in %r)rrUrrr8)r r
r!rirjrdrrr�test_zipfile_errors


zCmdLineTest.test_zipfile_errorc
CsXt���F}tj�|d�}t|�t|d�}|jddg|||dtj	j
|d�WdQRXdS)N�test_pkgrTz-mztest_pkg.script)r))rrUr�path�joinrrr6rr9rV)r r
�pkg_dirr!rrr�test_module_in_packages

z"CmdLineTest.test_module_in_packagecCsJt���8}t|ddd�\}}|jddg|||dtj||d�WdQRXdS)NrfrorTz-mztest_pkg.script)�
PYTHONPATHr))rrUrr6rgrh)r r
rirjrrr�!test_module_in_package_in_zipfiles

z-CmdLineTest.test_module_in_package_in_zipfilecCsNt���<}t|ddddd�\}}|jddg|||dtj||d	�WdQRXdS)
NrfrorT�)rz-mztest_pkg.test_pkg.scriptztest_pkg.test_pkg)rtr))rrUrr6rgrh)r r
rirjrrr�$test_module_in_subpackage_in_zipfile&s
z0CmdLineTest.test_module_in_subpackage_in_zipfilec
CsXt���F}tj�|d�}t|�t|d�}|jddg|||dtj	j
|d�WdQRXdS)Nror`z-m)r))rrUrrprqrrr6rr9rV)r r
rrr!rrr�test_package.s

zCmdLineTest.test_packagec
Cszt���h}tj�|d�}t|�t|d�}tj|dd�}t�	|�t�
|�}|jddg|||dtj
j|d�WdQRXdS)Nror`T)rXz-m)r))rrUrrprqrrrYrZr[r\r6rr9r])r r
rrr!rlr^rrr�test_package_compiled8s



z!CmdLineTest.test_package_compiledc	CsFt���4}tj�|d�}t|�d}|jddg||d�WdQRXdS)Nroz7'test_pkg' is a package and cannot be directly executedz-m)r))rrUrrprqrr8)r r
rrrdrrr�test_package_errorEs

zCmdLineTest.test_package_errorc	Cs\t���J}tj�|d�}t|�tj�|d�}t|�d}|jddg||d�WdQRXdS)Nror`z^Cannot use package as __main__ module; 'test_pkg' is a package and cannot be directly executedz-m)r))rrUrrprqrr8)r r
rrZmain_dirrdrrr�test_package_recursionMs
z"CmdLineTest.test_package_recursioncCs�t����}tj|d���tj�|d�}t|d�t|d�}tdt	�ddi�\}}}t
d	krftt|��d
d}|�
|�d�|�|�||||||dtjj�WdQRXWdQRXdS)
N)rproz1import sys; print('init_argv0==%r' % sys.argv[0])rT�-m�test_pkg.scriptr*Frzinit_argv0==%rzutf-8)r|r})rrU�
change_cwdrrprqrrrr.rrrrrr(rr9rV)r r
rrr!r3r4r5r;rrr�test_issue8202Xs



zCmdLineTest.test_issue8202cCs�t����}tj|d��htdd��R}|�d�tdddd�\}}}tdkrVtt|��d	d
}|�	|�
d�|�WdQRXWdQRXWdQRXdS)N)rpz-c�wr"z2import sys; print("sys.path[0]==%r" % sys.path[0])F)r*rzsys.path[0]==%rrazutf-8)rrUr~�openr>rrrrrr)r r
�fr3r4r5r;rrr�"test_issue8202_dash_c_file_ignoredis

z.CmdLineTest.test_issue8202_dash_c_file_ignoredc
Cs�t���|}t|d�}tj|d��Ztdd��D}|�d�td	t�ddi�\}}}|�||||||dt	j
j�WdQRXWdQRXWdQRXdS)
N�other)rp�-mr�r"r*Fra)r�r�)rrUrr~r�r>rr.r(rr9rV)r r
r!r�r3r4r5rrr�"test_issue8202_dash_m_file_ignoredxs




z.CmdLineTest.test_issue8202_dash_m_file_ignoredc
Cs�t����}tj�|d�}t|ddd��@}|�d�|�d�xtd�D]}|�d�qFW|�d�WdQRXtj|d	��t	|�\}}}WdQRX|�
d
|�|�
d
|�WdQRXdS)Nz
issue20884.pyr��
)�newlinez#coding: iso-8859-1
z"""
�zQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
)rp�)rrUrrprqr�r>�ranger~rr)r r
r!r��_r3r4r5rrr�test_issue20884�s


zCmdLineTest.test_issue20884c
gsRt���@}tj|d��(tj�|d�}t|f|��|VWdQRXWdQRXdS)N)rpro)rrUr~rrprqr)r �argsr
rrrrr�setup_test_pkg�s

zCmdLineTest.setup_test_pkgcGs<td|�ddi�\}}}tdkr,tt|��|�|d�|S)N�-mr*Fr)r�)rrrrr)r r�r3r4r5rrr�check_dash_m_failure�s
z CmdLineTest.check_dash_m_failurec	Cs>|���,}t|dd�}|jdt��}|�d|�WdQRXdS)Nr�z+if __name__ == '__main__': raise ValueError�test_pkg.others
ValueError)r�)r�rr�r.r)r rrr!r5rrr�test_dash_m_error_code_is_one�s

z)CmdLineTest.test_dash_m_error_code_is_onec
Csdd}xZ|D]R\}}|�|��:td|�\}}}|�|d�|�||�|�d|�WdQRXq
WdS)N))�builtinssNo code object available)z
builtins.xs=Error while finding module specification.*ModuleNotFoundError)zbuiltins.x.ys]Error while finding module specification.*ModuleNotFoundError.*No module named.*not a package)zos.pathsloader.*cannot handle)rs=No module named.*is a package and cannot be directly executed)zimportlib.nonexistantsNo module named)z	.unittests#Relative module names not supportedz-mrs	Traceback)�subTestrr�assertRegex�assertNotIn)r Ztests�nameZregexr3r�r5rrr�test_dash_m_errors�szCmdLineTest.test_dash_m_errorscCs~t���l}tj|d��Tt�d�tdd��WdQRX|�d�}|�|d�|�d|�|�d|�WdQRXWdQRXdS)N)rproztest_pkg/__init__.pyc�wbsGError while finding module specification.*ImportError.*bad magic numbersis a packages	Traceback)	rrUr~r�mkdirr�r�r�r�)r r
r5rrr�test_dash_m_bad_pyc�s



zCmdLineTest.test_dash_m_bad_pyccCs�ttttf}x||D]t}|j}d�|�}|�|��P|�|��:}|�d�}|�	|�
d�|�|�	d|�|�	d|�WdQRXWdQRXqWdS)Nz%raise {0}('Exception in __init__.py')ro�asciisException in __init__.pys	Traceback)�ImportError�AttributeError�	TypeError�
ValueError�__name__�formatr�r�r�rr)r �
exceptionsZ	exceptionZinitrrr5rrr�test_dash_m_init_traceback�s


z&CmdLineTest.test_dash_m_init_tracebackc	CsV|���D}d}t|d|�|�d�}|�d|�|�d|�|�d|�WdQRXdS)Nz1raise ImportError('Exception in __main__ module')r`rosImportErrorsException in __main__ modules	Traceback)r�rr�r)r rr�mainr5rrr�test_dash_m_main_traceback�s

z&CmdLineTest.test_dash_m_main_tracebackc	Cs�t�d�}t���|}t|d|�}t|�\}}}|�d��d�}|�t	|�d�|�
|d�d��|�
|d�d	��|�
|d
�d��WdQRXdS)Nz|            try:
                raise ValueError
            except:
                raise NameError from None
            rTr�r�rDrZ	Tracebackrz  File ��	NameError)�textwrap�dedentrrUrr�decode�splitr�lenZ
assertTrue�
startswith)r rTr
r!�exitcoderGrC�textrrr�test_pep_409_verbiage�s
z!CmdLineTest.test_pep_409_verbiagecCs�tjrtjdkrt�tj�}ntjr,tj}n
|�d�d}ttj	||�}|�
tj|�t|�\}}}|�
t|�|���d�d||f�|�
d|�dS)N)�win32�darwinzneed support.TESTFN_NONASCIIzprint(ascii(__file__))
r�zstdout=%r stderr=%rr)rZTESTFN_UNDECODABLE�sys�platformr�fsdecodeZTESTFN_NONASCIIZskipTestr�curdirZ
addCleanup�unlinkrrr��rstripr�)r r�rr!r3rGrCrrr�test_non_ascii�s

zCmdLineTest.test_non_asciic	CsRt�d�}t���6}t|d|�}t|�\}}}|�d�}|�|d�WdQRXdS)Nz�            import sys
            error = None
            try:
                raise ValueError('some text')
            except ValueError as err:
                error = err

            if error:
                sys.exit(error)
            rTr�z	some text)r�r�rrUrrr�r)r rTr
r!r�rGrCr�rrr�)test_issue20500_exit_with_exception_values


z5CmdLineTest.test_issue20500_exit_with_exception_valuec	CsXd}t���B}t|d|�}t|�\}}}t�t�|�d���}|�d|�WdQRXdS)Nz
1 + 1 = 2
rTr�z
    1 + 1 = 2
    ^)	rrUrr�io�
TextIOWrapper�BytesIOrHr)r rTr
r!r�rGrCr�rrr�*test_syntaxerror_unindented_caret_position&s
z6CmdLineTest.test_syntaxerror_unindented_caret_positionc	Cs�t�d�}t����}t|d|�}t|�\}}}t�t�|�d��	�}|�
d|�d}t|d|�}t|�\}}}t�t�|�d��	�}|�d|�|�
d|�WdQRXdS)Nz;            if True:
                1 + 1 = 2
            rTr�z
    1 + 1 = 2
    ^zif True:
    1 + 1 = 2
�)r�r�rrUrrr�r�r�rHrr�)r rTr
r!r�rGrCr�rrr�(test_syntaxerror_indented_caret_position/s
z4CmdLineTest.test_syntaxerror_indented_caret_positionc	
Cs�t�d�}d|_t����}t����}t|d|�}td||d�}t|����	�}|�
|d|�|�||�td||d�}t|����	�}|�
||�td||d�}t|����	�}|�
|||�WdQRXWdQRXdS)Nzc            import sys
            for entry in sys.path:
                print(entry)
            r`z-Es)r)rz-I)r�r��maxDiffrrUrr	r
r��
splitlinesrr�)	r rT�work_dirr
r!r@Zout_by_nameZ
out_by_dirZout_by_dir_isolatedrrr�-test_consistent_sys_path_for_direct_executionFsz9CmdLineTest.test_consistent_sys_path_for_direct_executionc	Cs�t�d�}d|_t����}tj�|d�}t�|�t	|d|�}t
dd|d�}t|����
�}|�|d|�|�||�t
dd|d�}t|����
�}|�||�tdd|d�\}}	}
|
���
�}|�d	|d
�WdQRXdS)Nzc            import sys
            for entry in sys.path:
                print(entry)
            Z
script_pkgr`z-smzscript_pkg.__main__)r)rz-ImzNo module named script_pkg���)r�r�r�rrUrrprqr�rr	r
r�r�rr�rr)r rTr�r
r!r@Z
out_by_moduleZout_by_packager�rGrCZtraceback_linesrrr�-test_consistent_sys_path_for_module_executiones$

z9CmdLineTest.test_consistent_sys_path_for_module_executioncCsTd}|�tj�|��t|dtjtjd�}|��\}}|�d|�|�	|j
d�dS)Nznonexistingscript.pyT)r�rGrCz: can't open file r)ZassertFalserrp�existsr	rErFZcommunicaterZassertNotEqual�
returncode)r rT�procr4r5rrr�test_nonexisting_script�s
z#CmdLineTest.test_nonexisting_script)N)F)F)F)3r��
__module__�__qualname__r(r6r8r<rA�
contextlib�contextmanagerrLrNrOrPrQrRrSrWr_rbrcrerkrmrnrsrurwrxryrzr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrZs^




	






	%rcCst�t�t��dS)N)rZrun_unittestrZ
reap_childrenrrrr�	test_main�s
r�r`) r�rZimportlib.machineryrgZunittestr�rZos.pathrYrEr�r�ZtestrZtest.support.script_helperrrrrrrr	r
rr.Ztest_sourcerrZTestCaserr�r�rrrr�<module>s4(
5D