o
    GXh                     @   s
  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZ ejZg dZdZefdd	Zed
fddZG dd dejZ dd Z!e"dkre#  dS dS )    N)support)import_helper)	os_helper)make_pkgmake_scriptmake_zip_pkgmake_zip_scriptassert_python_okassert_python_failurespawn_pythonkill_python)Ztest1Ztest2Ztest3a  # 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())
c                 C   s   t | ||}t  |S N)r   	importlibinvalidate_caches)
script_dirscript_basenamesource	to_return r   C/opt/python-3.10.19/usr/lib/python3.10/test/test_cmd_line_script.py_make_test_scriptP   s   r      c                 C   s   t | |||||}t  |S r   )r   r   r   )Zzip_dirZzip_basenameZpkg_namer   r   depthr   r   r   r   _make_test_zip_pkgU   s
   
r   c                   @   s  e Zd Z	dtddZddddZddddZd	d
 Zdd Zej	duddZ
duddZduddZdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&ej	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 Z6dhdi Z7djdk Z8e9:e;j<=dldme9>e?j@Adnoe;BdojCe;BdpjCkdqdrds ZDdS )vCmdLineTestNc
                 C   s  t dkrtd|  tt| | |d d| }
d| }d| }d| }d| }|	d u r2t }	d	|	 }t dkrNtd
 t| t| t| t| | |
d| | |d| | |d| | |d| | |d| | |d| d S )Nr   zOutput from test script %r:r   z__loader__==%az__file__==%az__package__==%rzsys.argv[0]==%azsys.path[0]==%azcwd==%azExpected 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_loaderexpected_cwdZprinted_loaderZprinted_fileZprinted_packageZprinted_argv0Zprinted_path0Zprinted_cwdr   r   r   _check_output]   s0   zCmdLineTest._check_outputcwdc                O   sd   t |tr|g}g t ||t}
t|
d|d|	\}}}| |||| ||||||	 d S )NF
__isolatedZ__cwd)
isinstancestrr   Z!optim_args_from_interpreter_flagsexample_argsr	   r-   )r$   script_exec_argsr'   r(   r)   r*   r+   r/   cmd_line_switchesenv_varsrun_argsrcouterrr   r   r   _check_scriptz   s$   

zCmdLineTest._check_scriptc          
      O   s   t |tr	|f}nt|}|| }t|d|d|\}}}	tdkr6td|  tt|	 td|  | |d|	 d S )NFr0   r   zOutput from test script zExpected output: %rr   )	r2   r3   tupler
   r   r   r   r"   r#   )
r$   r5   Zexpected_msgr/   r6   r7   r8   r9   r:   r;   r   r   r   _check_import_error   s   
zCmdLineTest._check_import_errorc                 C   s2   t dd\}}}ttjjd}| || d S )N-czprint(__loader__)r   )r	   r   r   	machineryBuiltinImporterr#   r"   )r$   r9   r:   r;   expectedr   r   r   test_dash_c_loader   s   zCmdLineTest.test_dash_c_loaderc                 C   sV   t  }z|jd |j  W t|}nt|}w ttjj	d}| 
|| d S )Ns   print(__loader__)
r   )r   stdinwriteflushr   r   r   r@   rA   r#   r"   )r$   pr:   rB   r   r   r   test_stdin_loader   s   zCmdLineTest.test_stdin_loaderFc                 c   s    |rt dtjd}|j}n
t dtjd}|j}z	 |d}|dkr$n|  q|V  W t| |	  d S t| |	  w )Nz-i)stderrT   s   >>> )
r   
subprocessPIPErI   STDOUTstdoutreadreadliner   close)r$   separate_stderrrG   rI   r&   r   r   r   interactive_python   s$   

zCmdLineTest.interactive_pythonc                 C   s\   |  |}|jd |j  | d|j   W d    d S 1 s'w   Y  d S )Ns   print('foo')
s   foo)rS   rD   rE   rF   r   rN   rP   strip)r$   rR   rG   r   r   r   check_repl_stdout_flush   s
   
"z#CmdLineTest.check_repl_stdout_flushc                 C   s   |  |4}|jd |j  |r|jn|j}| d|  | d|  | d|  W d    d S 1 s<w   Y  d S )Ns   1/0
s
   Traceback s   File "<stdin>"s   ZeroDivisionError)rS   rD   rE   rF   rI   rN   r"   rP   )r$   rR   rG   rI   r   r   r   check_repl_stderr_flush   s   
"z#CmdLineTest.check_repl_stderr_flushc                 C      |    d S r   rU   r$   r   r   r   test_repl_stdout_flush      z"CmdLineTest.test_repl_stdout_flushc                 C      |  d d S NTrX   rY   r   r   r   &test_repl_stdout_flush_separate_stderr      z2CmdLineTest.test_repl_stdout_flush_separate_stderrc                 C   rW   r   rV   rY   r   r   r   test_repl_stderr_flush   r[   z"CmdLineTest.test_repl_stderr_flushc                 C   r\   r]   r`   rY   r   r   r   &test_repl_stderr_flush_separate_stderr   r_   z2CmdLineTest.test_repl_stderr_flush_separate_stderrc              
   C   sT   t  }t|d}| j||||d tjj|d W d    d S 1 s#w   Y  d S )Nscript)r,   r   temp_dirr   r<   r   r@   SourceFileLoaderr$   r   r%   r   r   r   test_basic_script   s   


"zCmdLineTest.test_basic_scriptc              	   C   sp   t  *}| tj|| t|d}tj|}| ||||d t	j
j W d    d S 1 s1w   Y  d S )Nrc   )r   Ztemp_cwd
assertTruer    pathisabsr   basenamer<   r   r@   rf   )r$   r   r%   Zrelative_namer   r   r   test_script_abspath   s   


"zCmdLineTest.test_script_abspathc              	   C   sr   t  +}t|d}tj|dd t| t|}| 	||||d t
jj W d    d S 1 s2w   Y  d S )Nrc   Tdoraiser   re   r   
py_compilecompiler    remover   make_legacy_pycr<   r   r@   SourcelessFileLoaderr$   r   r%   pyc_filer   r   r   test_script_compiled   s   



"z CmdLineTest.test_script_compiledc              	   C   sP   t  }t|d}| ||||dtjj W d    d S 1 s!w   Y  d S )N__main__ rd   rg   r   r   r   test_directory   s   


"zCmdLineTest.test_directoryc              	   C   sr   t  +}t|d}tj|dd t| t|}| 	||||dt
jj W d    d S 1 s2w   Y  d S )Nry   Trn   rz   rp   rv   r   r   r   test_directory_compiled   s   




"z#CmdLineTest.test_directory_compiledc                 C   sB   t  }d| }| || W d    d S 1 sw   Y  d S )N"can't find '__main__' module in %r)r   re   r>   )r$   r   msgr   r   r   test_directory_error	  s   
"z CmdLineTest.test_directory_errorc              	   C   s^   t  !}t|d}t|d|\}}| ||||dtj W d    d S 1 s(w   Y  d S )Nry   test_ziprz   )r   re   r   r   r<   	zipimportzipimporter)r$   r   r%   zip_namerun_namer   r   r   test_zipfile  s   

"zCmdLineTest.test_zipfilec              	   C   r   t  +}t|d}tj|dtjjd}t|d|\}}| ||||dt	j
 W d    d S 1 s2w   Y  d S Nry   T)ro   invalidation_moder   rz   )r   re   r   rq   rr   PycInvalidationMode	TIMESTAMPr   r<   r   r   r$   r   r%   compiled_namer   r   r   r   r   test_zipfile_compiled_timestamp     

"z+CmdLineTest.test_zipfile_compiled_timestampc              	   C   r   r   )r   re   r   rq   rr   r   CHECKED_HASHr   r<   r   r   r   r   r   r   "test_zipfile_compiled_checked_hash  r   z.CmdLineTest.test_zipfile_compiled_checked_hashc              	   C   r   r   )r   re   r   rq   rr   r   UNCHECKED_HASHr   r<   r   r   r   r   r   r   $test_zipfile_compiled_unchecked_hash)  r   z0CmdLineTest.test_zipfile_compiled_unchecked_hashc                 C   s\   t   }t|d}t|d|\}}d| }| || W d    d S 1 s'w   Y  d S )NZnot_mainr   r}   )r   re   r   r   r>   )r$   r   r%   r   r   r~   r   r   r   test_zipfile_error3  s   

"zCmdLineTest.test_zipfile_errorc              
   C   sn   t  )}tj|d}t| t|d}| jddg|||dtj	j
|d W d    d S 1 s0w   Y  d S )Ntest_pkgrc   -mtest_pkg.scriptr.   r   re   r    rj   joinr   r   r<   r   r@   rf   r$   r   pkg_dirr%   r   r   r   test_module_in_package:  s   

"z"CmdLineTest.test_module_in_packagec                 C   s`   t  "}t|ddd\}}| jddg|||dtj||d W d    d S 1 s)w   Y  d S )Nr   r   rc   r   r   Z
PYTHONPATHr/   r   re   r   r<   r   r   r$   r   r   r   r   r   r   !test_module_in_package_in_zipfileD  s   
"z-CmdLineTest.test_module_in_package_in_zipfilec                 C   sd   t  $}t|ddddd\}}| jddg|||dtj||d	 W d    d S 1 s+w   Y  d S )
Nr   r   rc      )r   r   ztest_pkg.test_pkg.scriptztest_pkg.test_pkgr   r   r   r   r   r   $test_module_in_subpackage_in_zipfileK  s   
"z0CmdLineTest.test_module_in_subpackage_in_zipfilec              
   C   sn   t  )}tj|d}t| t|d}| jddg|||dtj	j
|d W d    d S 1 s0w   Y  d S )Nr   ry   r   r.   r   r   r   r   r   test_packageS  s   

"zCmdLineTest.test_packagec              
   C   s   t  :}tj|d}t| t|d}tj|dd}t	| t
|}| jddg|||dtjj|d W d    d S 1 sAw   Y  d S )Nr   ry   Trn   r   r.   )r   re   r    rj   r   r   r   rq   rr   rs   r   rt   r<   r   r@   ru   )r$   r   r   r%   r   rw   r   r   r   test_package_compiled]  s   



"z!CmdLineTest.test_package_compiledc                 C   s\   t   }tj|d}t| d}| jddg||d W d    d S 1 s'w   Y  d S )Nr   z7'test_pkg' is a package and cannot be directly executedr   r.   r   re   r    rj   r   r   r>   )r$   r   r   r~   r   r   r   test_package_errorj  s   
"zCmdLineTest.test_package_errorc                 C   sr   t  +}tj|d}t| tj|d}t| d}| jddg||d W d    d S 1 s2w   Y  d S )Nr   ry   z^Cannot use package as __main__ module; 'test_pkg' is a package and cannot be directly executedr   r.   r   )r$   r   r   Zmain_dirr~   r   r   r   test_package_recursionr  s   
"z"CmdLineTest.test_package_recursionc                 C   s   t  l}t j|dM tj|d}t|d t|d}tddgt	R ddi\}}}t
d	kr6tt| d
d }| |d| | ||||||dtjj W d    n1 s[w   Y  W d    d S W d    d S 1 ssw   Y  d S )Nrj   r   z1import sys; print('init_argv0==%r' % sys.argv[0])rc   r   r   r1   Fr   zinit_argv0==%rr   )r   re   
change_cwdr    rj   r   r   r   r	   r4   r   r   r   r"   r#   r-   r   r@   rf   )r$   r   r   r%   r9   r:   r;   rB   r   r   r   test_issue8202}  s$   



"zCmdLineTest.test_issue8202c              
   C   s   t  d}t j|dE tdddd.}|d tdddd	\}}}td
kr-tt| dd }| 	|
d| W d    n1 sDw   Y  W d    n1 sSw   Y  W d    d S W d    d S 1 skw   Y  d S )Nr   r?   wr   encodingr&   z2import sys; print("sys.path[0]==%r" % sys.path[0])F)r1   r   zsys.path[0]==%rrz   )r   re   r   openrE   r	   r   r   r   r"   r#   )r$   r   fr9   r:   r;   rB   r   r   r   "test_issue8202_dash_c_file_ignored  s$   

"z.CmdLineTest.test_issue8202_dash_c_file_ignoredc                 C   s   t  e}t|d}t j|dA tdddd*}|d tddgtR dd	i\}}}| ||||||d
t	j
j W d    n1 sEw   Y  W d    n1 sTw   Y  W d    d S W d    d S 1 slw   Y  d S )Notherr   r   r   r   r   r&   r1   Frz   )r   re   r   r   r   rE   r	   r4   r-   r   r@   rf   )r$   r   r%   r   r9   r:   r;   r   r   r   "test_issue8202_dash_m_file_ignored  s$   



"z.CmdLineTest.test_issue8202_dash_m_file_ignoredc              	   C   s   t  l}tj|d}t|dddd#}|d |d tdD ]}|d	 q#|d W d    n1 s:w   Y  t j|d
 t	|\}}}W d    n1 sWw   Y  | 
d| | 
d| W d    d S 1 ssw   Y  d S )Nzissue20884.pyr   latin1
)r   newlinez#coding: iso-8859-1
z"""
   zQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r       )r   re   r    rj   r   r   rE   ranger   r	   r   )r$   r   r%   r   _r9   r:   r;   r   r   r   test_issue20884  s   


"zCmdLineTest.test_issue20884c              	   g   s    t  9}t j|d tj|d}t|g|R   |V  W d    n1 s)w   Y  W d    d S W d    d S 1 sAw   Y  d S )Nr   r   )r   re   r   r    rj   r   r   )r$   argsr   r   r   r   r   setup_test_pkg  s   

PzCmdLineTest.setup_test_pkgc                 G   s@   t dg|R ddi\}}}tdkrtt| | |d |S )Nr   r1   Fr   )r
   r   r   r   r   )r$   r   r9   r:   r;   r   r   r   check_dash_m_failure  s
   z CmdLineTest.check_dash_m_failurec                 C   sX   |   }t|dd}| jdgtR  }| d| W d    d S 1 s%w   Y  d S )Nr   z+if __name__ == '__main__': raise ValueErrorztest_pkg.others
   ValueError)r   r   r   r4   r"   )r$   r   r%   r;   r   r   r   test_dash_m_error_code_is_one  s   
"z)CmdLineTest.test_dash_m_error_code_is_onec              	   C   st   d}|D ]3\}}|  |" td|\}}}| |d | || | d| W d    n1 s2w   Y  qd S )N))builtinss   No 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)zos.paths   loader.*cannot handle)r   s=   No module named.*is a package and cannot be directly executed)zimportlib.nonexistents   No module named)z	.unittests#   Relative module names not supportedr   r   	   Traceback)subTestr
   r   assertRegexassertNotIn)r$   ZtestsnameZregexr9   r   r;   r   r   r   test_dash_m_errors  s   zCmdLineTest.test_dash_m_errorsc              
   C   s   t  X}t j|d9 td tdd W d    n1 s!w   Y  | d}| |d | d| | d| W d    n1 sGw   Y  W d    d S W d    d S 1 s_w   Y  d S )Nr   r   ztest_pkg/__init__.pycwbsG   Error while finding module specification.*ImportError.*bad magic numbers   is a packager   )	r   re   r   r    mkdirr   r   r   r   r$   r   r;   r   r   r   test_dash_m_bad_pyc  s   



PzCmdLineTest.test_dash_m_bad_pycc              
   C   s   t  G}t j|d( tdd W d    n1 sw   Y  | d}| d| W d    n1 s6w   Y  W d    d S W d    d S 1 sNw   Y  d S )Nr   z
asyncio.pyr   s>   Try using 'asyncio' instead of 'asyncio.py' as the module name)r   re   r   r   r   r"   r   r   r   r   *test_hint_when_triying_to_import_a_py_file  s   


Pz6CmdLineTest.test_hint_when_triying_to_import_a_py_filec              
   C   s   t tttf}|D ]N}|j}d|}| |7 | |"}| d}| 	|
d| | 	d| | 	d| W d    n1 sBw   Y  W d    n1 sQw   Y  qd S )Nz%raise {0}('Exception in __init__.py')r   asciis   Exception in __init__.pyr   )ImportErrorAttributeError	TypeError
ValueError__name__formatr   r   r   r"   r#   )r$   
exceptions	exceptionZinitr   r;   r   r   r   test_dash_m_init_traceback  s"   

 z&CmdLineTest.test_dash_m_init_tracebackc                 C   sl   |   (}d}t|d| | d}| d| | d| | d| W d    d S 1 s/w   Y  d S )Nz1raise ImportError('Exception in __main__ module')ry   r   s   ImportErrors   Exception in __main__ moduler   )r   r   r   r"   )r$   r   mainr;   r   r   r   test_dash_m_main_traceback  s   

"z&CmdLineTest.test_dash_m_main_tracebackc                 C   s   t d}t D}t|d|}t|\}}}|dd}| t	|d | 
|d d | 
|d d	 | 
|d
 d W d    d S 1 sPw   Y  d S )Nz|            try:
                raise ValueError
            except:
                raise NameError from None
            rc   r   r      r   Z	Tracebackr   z  File    	NameError)textwrapdedentr   re   r   r
   decodesplitr   lenri   
startswithr$   rc   r   r%   exitcoderN   rI   textr   r   r   test_pep_409_verbiage  s   

"z!CmdLineTest.test_pep_409_verbiagec                 C   s   t jrtjdvrtt j}nt jrt j}n| d d}tt	 ||}| 
t j| t|\}}}| t|| dd||f  | d| d S )N)win32darwinzneed os_helper.TESTFN_NONASCIIzprint(ascii(__file__))
r   zstdout=%r stderr=%rr   )r   ZTESTFN_UNDECODABLEsysplatformr    fsdecodeZTESTFN_NONASCIIZskipTestr   r!   Z
addCleanupunlinkr	   r   r   rstripr   )r$   r   r   r%   r9   rN   rI   r   r   r   test_non_ascii,  s    


zCmdLineTest.test_non_asciic                 C   sl   t d}t #}t|d|}t|\}}}|d}| | d W d    d S 1 s/w   Y  d S )Nz            import sys
            error = None
            try:
                raise ValueError('some text')
            except ValueError as err:
                error = err

            if error:
                sys.exit(error)
            rc   r   z	some text)	r   r   r   re   r   r
   r   r   r   r   r   r   r   )test_issue20500_exit_with_exception_valueC  s   


"z5CmdLineTest.test_issue20500_exit_with_exception_valuec                 C   sn   d}t  '}t|d|}t|\}}}tt|d }| d| W d    d S 1 s0w   Y  d S )Nz
1 + 1 = 2
rc   r   z
    ^^^^^
)	r   re   r   r
   ioTextIOWrapperBytesIOrO   r"   r   r   r   r   *test_syntaxerror_unindented_caret_positionU  s   
"z6CmdLineTest.test_syntaxerror_unindented_caret_positionc                 C   s   t d}t M}t|d|}t|\}}}tt|d	 }| 
d| d}t|d|}t|\}}}tt|d	 }| d| | 
d| W d    d S 1 sYw   Y  d S )Nz;            if True:
                1 + 1 = 2
            rc   r   z
    1 + 1 = 2
    ^^^^^
zif True:
    1 + 1 = 2
)r   r   r   re   r   r
   r   r   r   rO   r"   r   r   r   r   r   (test_syntaxerror_indented_caret_position^  s   

"z4CmdLineTest.test_syntaxerror_indented_caret_positionc                 C   sh   d}t  $}t|d|}t|\}}}| | dd  g d W d    d S 1 s-w   Y  d S )Nzfoo = f"""{}
foo"""
rc   )s
       foo"""s             ^s3   SyntaxError: f-string: empty expression not allowedr   re   r   r
   r   
splitlinesr$   rc   r   r%   r   rN   rI   r   r   r   #test_syntaxerror_multi_line_fstringu  s   
"z/CmdLineTest.test_syntaxerror_multi_line_fstringc                 C   sj   d}t  %}t|d|}td|\}}}| | dd  g d W d    d S 1 s.w   Y  d S )Nzfoo = """\q"""
rc   z-Werrorr   )s       foo = """\q"""s             ^^^^^^^^s)   SyntaxError: invalid escape sequence '\q'r   r   r   r   r   3test_syntaxerror_invalid_escape_sequence_multi_line  s   

"z?CmdLineTest.test_syntaxerror_invalid_escape_sequence_multi_linec           	   	   C   s  t d}d | _t s}t V}t|d|}td||d}t| 	 }| 
|d | | || td||d}t| 	 }| 
|| td||d}t| 	 }| 
||| W d    n1 sjw   Y  W d    d S W d    d S 1 sw   Y  d S )Nc            import sys
            for entry in sys.path:
                print(entry)
            ry   z-Esr.   r   z-I)r   r   maxDiffr   re   r   r   r   r   r   r   r   )	r$   rc   work_dirr   r%   rG   Zout_by_nameZ
out_by_dirZout_by_dir_isolatedr   r   r   -test_consistent_sys_path_for_direct_execution  s   
Pz9CmdLineTest.test_consistent_sys_path_for_direct_executionc                 C   s   t d}d | _t e}tj|d}t| t	|d|}t
dd|d}t|  }| |d | | || t
dd|d}t|  }| || tdd|d\}}	}
|
  }| d	|d
  W d    d S 1 stw   Y  d S )Nr   Z
script_pkgry   z-smzscript_pkg.__main__r.   r   z-ImzNo module named script_pkg)r   r   r   r   re   r    rj   r   r   r   r   r   r   r   r   r   r
   r"   )r$   rc   r   r   r%   rG   Zout_by_moduleZout_by_packager   rN   rI   Ztraceback_linesr   r   r   -test_consistent_sys_path_for_module_execution  s&   


"z9CmdLineTest.test_consistent_sys_path_for_module_executionc                 C   sT   d}|  tj| t|dtjtjd}| \}}| d| | 	|j
d d S )Nznonexistingscript.pyT)r   rN   rI   z: can't open file r   )ZassertFalser    rj   existsr   rK   rL   communicater"   ZassertNotEqual
returncode)r$   rc   procr:   r;   r   r   r   test_nonexisting_script  s   z#CmdLineTest.test_nonexisting_scriptz	/dev/fd/0zrequires /dev/fd platformZfreebsdz/devz/dev/fdz.Requires fdescfs mounted on /dev/fd on FreeBSDc              
   C   s   d}t  J}t|d|}t|d&}td|  dddd| fd	}| \}}| |d
 W d    n1 s;w   Y  W d    d S W d    d S 1 sSw   Y  d S )Nz print("12345678912345678912345")z	script.pyrz/dev/fd/Fr   r   r   )	close_fdspass_fdss   12345678912345678912345
)r   re   r   r   r   filenor   r   )r$   rc   r   r%   fprG   r:   r;   r   r   r   test_script_as_dev_fd  s   
$"z!CmdLineTest.test_script_as_dev_fdr   )F)Er   
__module____qualname__r-   r<   r>   rC   rH   
contextlibcontextmanagerrS   rU   rV   rZ   r^   ra   rb   rh   rm   rx   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   r   r   r   r   r   r  unittestZ
skipUnlessr    rj   r   ZskipIfr   r   r   statst_devr  r   r   r   r   r   \   s    
 

	










	%r   c                   C   s   t   d S r   )r   reap_childrenr   r   r   r   tearDownModule  r[   r  ry   )$r  r   importlib.machineryr   r  r   r    Zos.pathrq   rK   r   r   testr   Ztest.supportr   r   Ztest.support.script_helperr   r   r   r   r	   r
   r   r   r   r4   Ztest_sourcer   r   ZTestCaser   r  r   r   r   r   r   r   <module>   s@   (5
      