HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/test/__pycache__/test_cmd_line_script.cpython-38.opt-1.pyc
U

.D�g�}�@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�8/opt/cppython/lib/python3.8/test/test_cmd_line_script.py�_make_test_scriptNsr�cCst||||||�}t��|Sr)rrr
)Zzip_dirZzip_basenameZpkg_namerr�depthrrrr�_make_test_zip_pkgSs
�rc@s�eZdZdhdd�Zdd�dd�Zdd�dd�Zd	d
�Zdd�Zej	didd��Z
djdd�Zdkdd�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#dBdC�Z$dDdE�Z%ej	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_�Z2d`da�Z3dbdc�Z4ddde�Z5dfdg�Z6dS)l�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:�utf-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��
__isolatedZ__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�|��\}}}	tdkrltd|����tt|	��td|�|�|�d�|	�dS)NFr-rzOutput from test script zExpected output: %rr)	r/r0�tuplerrrrr r!)
r"r2Zexpected_msgr,r3r4r5r6r7r8rrr�_check_import_error�s 
��zCmdLineTest._check_import_errorcCs2tdd�\}}}ttjj��d�}|�||�dS)N�-czprint(__loader__)r)rrr�	machinery�BuiltinImporterr!r )r"r6r7r8�expectedrrr�test_dash_c_loader�szCmdLineTest.test_dash_c_loadercCsNt�}z|j�d�|j��W5t|�}Xttjj��	d�}|�
||�dS)Nsprint(__loader__)
r)r	r
�stdin�write�flushrrr=r>r!r )r"�pr7r?rrr�test_stdin_loader�s
zCmdLineTest.test_stdin_loaderFccsn|rtdtjd�}|j}ntdtjd�}|j}z(|�d�}|dkrDqN|�	�q0|VW5t|�|��XdS)Nz-i)�stderr�s>>> )
r	�
subprocess�PIPErF�STDOUT�stdoutr
�close�read�readline)r"�separate_stderrrDrFr$rrr�interactive_python�s


zCmdLineTest.interactive_pythonc	CsF|�|��2}|j�d�|j��|�d|j�����W5QRXdS)Ns
print('foo')
sfoo)rPrArBrCrrKrN�strip)r"rOrDrrr�check_repl_stdout_flush�s
z#CmdLineTest.check_repl_stdout_flushc	Csp|�|��\}|j�d�|j��|r,|jn|j}|�d|���|�d|���|�d|���W5QRXdS)Ns1/0
s
Traceback sFile "<stdin>"sZeroDivisionError)rPrArBrCrFrKr rN)r"rOrDrFrrr�check_repl_stderr_flush�s
z#CmdLineTest.check_repl_stderr_flushcCs|��dSr�rR�r"rrr�test_repl_stdout_flush�sz"CmdLineTest.test_repl_stdout_flushcCs|�d�dS�NTrTrUrrr�&test_repl_stdout_flush_separate_stderr�sz2CmdLineTest.test_repl_stdout_flush_separate_stderrcCs|��dSr�rSrUrrr�test_repl_stderr_flush�sz"CmdLineTest.test_repl_stderr_flushcCs|�d�dSrWrYrUrrr�&test_repl_stderr_flush_separate_stderr�sz2CmdLineTest.test_repl_stderr_flush_separate_stderrc	Cs:t���(}t|d�}|�||||dtjj�W5QRXdS)N�script�r�temp_dirrr9rr=�SourceFileLoader�r"rr#rrr�test_basic_script�s


�zCmdLineTest.test_basic_scriptc	Cs\t���J}t|d�}tj|dd�t�|�t�|�}|�||||dt	j
j�W5QRXdS)Nr\T��doraise�rr^r�
py_compile�compiler�remove�make_legacy_pycr9rr=�SourcelessFileLoader�r"rr#�pyc_filerrr�test_script_compiled�s



�z CmdLineTest.test_script_compiledc	Cs:t���(}t|d�}|�||||dtjj�W5QRXdS)N�__main__�r]r`rrr�test_directory�s


�zCmdLineTest.test_directoryc	Cs\t���J}t|d�}tj|dd�t�|�t�|�}|�||||dt	j
j�W5QRXdS)NrmTrbrnrdrjrrr�test_directory_compiled�s




�z#CmdLineTest.test_directory_compiledc	Cs,t���}d|}|�||�W5QRXdS)N�"can't find '__main__' module in %r)rr^r;)r"r�msgrrr�test_directory_error�s
z CmdLineTest.test_directory_errorc	CsHt���6}t|d�}t|d|�\}}|�||||dtj�W5QRXdS)Nrm�test_ziprn)rr^rrr9�	zipimport�zipimporter)r"rr#�zip_name�run_namerrr�test_zipfile�s

�zCmdLineTest.test_zipfilec	Cs\t���J}t|d�}tj|dtjjd�}t|d|�\}}|�||||dt	j
�W5QRXdS�NrmT)rc�invalidation_modertrn)rr^rrerf�PycInvalidationMode�	TIMESTAMPrr9rurv�r"rr#�
compiled_namerwrxrrr�test_zipfile_compiled_timestamps

��z+CmdLineTest.test_zipfile_compiled_timestampc	Cs\t���J}t|d�}tj|dtjjd�}t|d|�\}}|�||||dt	j
�W5QRXdSrz)rr^rrerfr|�CHECKED_HASHrr9rurvr~rrr�"test_zipfile_compiled_checked_hashs

��z.CmdLineTest.test_zipfile_compiled_checked_hashc	Cs\t���J}t|d�}tj|dtjjd�}t|d|�\}}|�||||dt	j
�W5QRXdSrz)rr^rrerfr|�UNCHECKED_HASHrr9rurvr~rrr�$test_zipfile_compiled_unchecked_hashs

��z0CmdLineTest.test_zipfile_compiled_unchecked_hashc	CsFt���4}t|d�}t|d|�\}}d|}|�||�W5QRXdS)NZnot_mainrtrq)rr^rrr;)r"rr#rwrxrrrrr�test_zipfile_error$s


zCmdLineTest.test_zipfile_errorc
CsXt���F}tj�|d�}t|�t|d�}|jddg|||dtj	j
|d�W5QRXdS)N�test_pkgr\�-m�test_pkg.scriptr+�rr^r�path�joinrrr9rr=r_�r"r�pkg_dirr#rrr�test_module_in_package+s

�z"CmdLineTest.test_module_in_packagecCsJt���8}t|ddd�\}}|jddg|||dtj||d�W5QRXdS)Nrtr�r\r�r��Z
PYTHONPATHr,�rr^rr9rurv�r"rrwrxrrr�!test_module_in_package_in_zipfile5s
�z-CmdLineTest.test_module_in_package_in_zipfilecCsNt���<}t|ddddd�\}}|jddg|||dtj||d	�W5QRXdS)
Nrtr�r\�)rr�ztest_pkg.test_pkg.scriptztest_pkg.test_pkgr�r�r�rrr�$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�W5QRXdS)Nr�rmr�r+r�r�rrr�test_packageDs

�zCmdLineTest.test_packagec
Cszt���h}tj�|d�}t|�t|d�}tj|dd�}t�	|�t�
|�}|jddg|||dtj
j|d�W5QRXdS)Nr�rmTrbr�r+)rr^rr�r�rrrerfrgrhr9rr=ri)r"rr�r#rrkrrr�test_package_compiledNs



�z!CmdLineTest.test_package_compiledc	CsFt���4}tj�|d�}t|�d}|jddg||d�W5QRXdS)Nr�z7'test_pkg' is a package and cannot be directly executedr�r+�rr^rr�r�rr;)r"rr�rrrrr�test_package_error[s

zCmdLineTest.test_package_errorc	Cs\t���J}tj�|d�}t|�tj�|d�}t|�d}|jddg||d�W5QRXdS)Nr�rmz^Cannot use package as __main__ module; 'test_pkg' is a package and cannot be directly executedr�r+r�)r"rr�Zmain_dirrrrrr�test_package_recursioncs
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�W5QRXW5QRXdS)
N�r�r�z1import sys; print('init_argv0==%r' % sys.argv[0])r\r�r�r.Frzinit_argv0==%rr)r�r�)rr^�
change_cwdrr�r�rrrr1rrrr r!r*rr=r_)r"rr�r#r6r7r8r?rrr�test_issue8202ns"



�zCmdLineTest.test_issue8202cCs�t����}tj|d��htdd��R}|�d�tdddd�\}}}tdkrVtt|��d	d
}|�	|�
d�|�W5QRXW5QRXW5QRXdS)Nr�r<�wr$z2import sys; print("sys.path[0]==%r" % sys.path[0])F)r.rzsys.path[0]==%rrnr)rr^r��openrBrrrrr r!)r"r�fr6r7r8r?rrr�"test_issue8202_dash_c_file_ignoreds

�z.CmdLineTest.test_issue8202_dash_c_file_ignoredc
Cs�t���|}t|d�}tj|d��Ztdd��D}|�d�td	t�ddi�\}}}|�||||||dt	j
j�W5QRXW5QRXW5QRXdS)
N�otherr�r�r�r$r.Frn)r�r�)rr^rr�r�rBrr1r*rr=r_)r"rr#r�r6r7r8rrr�"test_issue8202_dash_m_file_ignored�s



�
�z.CmdLineTest.test_issue8202_dash_m_file_ignoredc
Cs�t����}tj�|d�}t|ddd��<}|�d�|�d�td�D]}|�d�qD|�d�W5QRXtj|d	��t	|�\}}}W5QRX|�
d
|�|�
d
|�W5QRXdS)Nz
issue20884.pyr��
)�newlinez#coding: iso-8859-1
z"""
�zQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r��)rr^rr�r�r�rB�ranger�rr)r"rr#r��_r6r7r8rrr�test_issue20884�s


zCmdLineTest.test_issue20884c
gsRt���@}tj|d��(tj�|d�}t|f|��|VW5QRXW5QRXdS)Nr�r�)rr^r�rr�r�r)r"�argsrr�rrr�setup_test_pkg�s

�zCmdLineTest.setup_test_pkgcGs<td|�ddi�\}}}tdkr,tt|��|�|d�|S)Nr�r.Fr)r�)rrrrr)r"r�r6r7r8rrr�check_dash_m_failure�s
z CmdLineTest.check_dash_m_failurec	Cs>|���,}t|dd�}|jdt��}|�d|�W5QRXdS)Nr�z+if __name__ == '__main__': raise ValueError�test_pkg.others
ValueError)r�)r�rr�r1r )r"r�r#r8rrr�test_dash_m_error_code_is_one�s
�z)CmdLineTest.test_dash_m_error_code_is_onec
Cs`d}|D]R\}}|�|��:td|�\}}}|�|d�|�||�|�d|�W5QRXqdS)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)rs=No module named.*is a package and cannot be directly executed)zimportlib.nonexistentsNo module named)z	.unittests#Relative module names not supportedr�r�	Traceback)�subTestrr�assertRegex�assertNotIn)r"Ztests�nameZregexr6r�r8rrr�test_dash_m_errors�szCmdLineTest.test_dash_m_errorscCs~t���l}tj|d��Tt�d�tdd��W5QRX|�d�}|�|d�|�d|�|�d|�W5QRXW5QRXdS)Nr�r�ztest_pkg/__init__.pyc�wbsGError while finding module specification.*ImportError.*bad magic numbersis a packager�)	rr^r�r�mkdirr�r�r�r�)r"rr8rrr�test_dash_m_bad_pyc�s

�


�zCmdLineTest.test_dash_m_bad_pyccCs�ttttf}|D]t}|j}d�|�}|�|��P|�|��:}|�d�}|�	|�
d�|�|�	d|�|�	d|�W5QRXW5QRXqdS)Nz%raise {0}('Exception in __init__.py')r��asciisException in __init__.pyr�)�ImportError�AttributeError�	TypeError�
ValueError�__name__�formatr�r�r�r r!)r"�
exceptions�	exceptionZinitr�r8rrr�test_dash_m_init_traceback�s
�
z&CmdLineTest.test_dash_m_init_tracebackc	CsV|���D}d}t|d|�|�d�}|�d|�|�d|�|�d|�W5QRXdS)Nz1raise ImportError('Exception in __main__ module')rmr�sImportErrorsException in __main__ moduler�)r�rr�r )r"r��mainr8rrr�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��W5QRXdS)Nz|            try:
                raise ValueError
            except:
                raise NameError from None
            r\r�r�rGrZ	Tracebackrz  File ��	NameError)�textwrap�dedentrr^rr�decode�splitr�lenZ
assertTrue�
startswith�r"r\rr#�exitcoderKrF�textrrr�test_pep_409_verbiages

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#r6rKrFrrr�test_non_asciis"�

�zCmdLineTest.test_non_asciic	CsRt�d�}t���6}t|d|�}t|�\}}}|�d�}|�|d�W5QRXdS)Nz�            import sys
            error = None
            try:
                raise ValueError('some text')
            except ValueError as err:
                error = err

            if error:
                sys.exit(error)
            r\r�z	some text)r�r�rr^rrr�rr�rrr�)test_issue20500_exit_with_exception_value*s


z5CmdLineTest.test_issue20500_exit_with_exception_valuec	CsXd}t���B}t|d|�}t|�\}}}t�t�|�d���}|�d|�W5QRXdS)Nz
1 + 1 = 2
r\r��
    1 + 1 = 2
    ^)	rr^rr�io�
TextIOWrapper�BytesIOrMr r�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|�W5QRXdS)Nz;            if True:
                1 + 1 = 2
            r\r�r�zif True:
    1 + 1 = 2
�)r�r�rr^rrr�r�r�rMr r�r�rrr�(test_syntaxerror_indented_caret_positionEs

�z4CmdLineTest.test_syntaxerror_indented_caret_positionc	CsTd}t���>}t|d|�}t|�\}}}|�|��dd�dddg�W5QRXdS)Nzfoo = f"""{}
foo"""
r\���s    foo = f"""{}�          ^s3SyntaxError: f-string: empty expression not allowed�rr^rrr�
splitlines�r"r\rr#r�rKrFrrr�#test_syntaxerror_multi_line_fstring\s
��z/CmdLineTest.test_syntaxerror_multi_line_fstringc	CsVd}t���@}t|d|�}td|�\}}}|�|��dd�dddg�W5QRXdS)Nzfoo = """\q
"""
r\z-Werrorr�s    foo = """\qr�s'SyntaxError: invalid escape sequence \qr�r�rrr�3test_syntaxerror_invalid_escape_sequence_multi_linejs
�
��z?CmdLineTest.test_syntaxerror_invalid_escape_sequence_multi_linec	
Cs�t�d�}d|_t����}t����}t|d|�}td||d�}t|����	�}|�
|d|�|�||�td||d�}t|����	�}|�
||�td||d�}t|����	�}|�
|||�W5QRXW5QRXdS)N�c            import sys
            for entry in sys.path:
                print(entry)
            rmz-Esr+rz-I)r�r��maxDiffrr^rr	r
r�r�rr�)	r"r\�work_dirrr#rDZout_by_nameZ
out_by_dirZout_by_dir_isolatedrrr�-test_consistent_sys_path_for_direct_executionzs
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
�W5QRXdS)Nr�Z
script_pkgrmz-smzscript_pkg.__main__r+rz-ImzNo module named script_pkg���)r�r�r�rr^rr�r�r�rr	r
r�r�rr�rr )r"r\r�rr#rDZ
out_by_moduleZout_by_packager�rKrFZtraceback_linesrrr�-test_consistent_sys_path_for_module_execution�s(


�z9CmdLineTest.test_consistent_sys_path_for_module_executioncCsTd}|�tj�|��t|dtjtjd�}|��\}}|�d|�|�	|j
d�dS)Nznonexistingscript.pyT)r�rKrFz: can't open file r)ZassertFalserr��existsr	rHrI�communicater ZassertNotEqual�
returncode)r"r\�procr7r8rrr�test_nonexisting_script�s�z#CmdLineTest.test_nonexisting_script)N)F)F)F)7r��
__module__�__qualname__r*r9r;r@rE�
contextlib�contextmanagerrPrRrSrVrXrZr[rarlrorprsryr�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�rrrrrZsn�
 ��


	










	%rcCst�t�t��dSr)rZrun_unittestr�
reap_childrenrrrr�	test_main�s
r�rm) r�rZimportlib.machineryruZunittestr�rZos.pathrerHr�r��testrZtest.support.script_helperrrrrrrr	r
rr1Ztest_sourcerrZTestCaserr�r�rrrr�<module>s8(
5�
x