a
    ze                     @   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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 )    N)support)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   //usr/lib/python3.9/test/test_cmd_line_script.py_make_test_scriptN   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_pkgS   s
    
r   c                   @   s  e Zd ZdlddZddddZddddZd	d
 Zdd Zej	dmddZ
dnddZdod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 Z8dS )pCmdLineTestNc
                 C   s  t dkr td|  tt| | |d d| }
d| }d| }d| }d| }|	d u rdt }	d	|	 }t dkrt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_scriptx   s$    

zCmdLineTest._check_scriptc          
      O   s   t |tr|f}nt|}|| }t|d|d|\}}}	tdkrltd|  tt|	 td|  | |d|	 d S )NFr.   r   zOutput from test script zExpected output: %rr   )	r0   r1   tupler   r   r   r   r    r!   )
r"   r3   Zexpected_msgr-   r4   r5   r6   r7   r8   r9   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"   r7   r8   r9   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|}0 ttjj	d}| 
|| d S )Ns   print(__loader__)
r   )r	   stdinwriteflushr
   r   r   r>   r?   r!   r    )r"   pr8   r@   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}z8|d}|dkrDqN|  q0|V  W t| |	  nt| |	  0 d S )Nz-i)stderr   s   >>> )
r	   
subprocessPIPErG   STDOUTstdoutreadreadliner
   close)r"   separate_stderrrE   rG   r$   r   r   r   interactive_python   s    


zCmdLineTest.interactive_pythonc                 C   sZ   |  |<}|jd |j  | d|j   W d    n1 sL0    Y  d S )Ns   print('foo')
s   foo)rQ   rB   rC   rD   r   rL   rN   strip)r"   rP   rE   r   r   r   check_repl_stdout_flush   s    
z#CmdLineTest.check_repl_stdout_flushc                 C   s   |  |f}|jd |j  |r,|jn|j}| d|  | d|  | d|  W d    n1 sv0    Y  d S )Ns   1/0
s
   Traceback s   File "<stdin>"s   ZeroDivisionError)rQ   rB   rC   rD   rG   rL   r    rN   )r"   rP   rE   rG   r   r   r   check_repl_stderr_flush   s    
z#CmdLineTest.check_repl_stderr_flushc                 C   s   |    d S r   rS   r"   r   r   r   test_repl_stdout_flush   s    z"CmdLineTest.test_repl_stdout_flushc                 C   s   |  d d S NTrU   rV   r   r   r   &test_repl_stdout_flush_separate_stderr   s    z2CmdLineTest.test_repl_stdout_flush_separate_stderrc                 C   s   |    d S r   rT   rV   r   r   r   test_repl_stderr_flush   s    z"CmdLineTest.test_repl_stderr_flushc                 C   s   |  d d S rX   rZ   rV   r   r   r   &test_repl_stderr_flush_separate_stderr   s    z2CmdLineTest.test_repl_stderr_flush_separate_stderrc              
   C   sR   t  6}t|d}| j||||d tjj|d W d    n1 sD0    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   sn   t  R}| tj|| t|d}tj|}| ||||d t	j
j W d    n1 s`0    Y  d S )Nr]   )r   Ztemp_cwd
assertTruer   pathisabsr   basenamer:   r   r>   r`   )r"   r   r#   Zrelative_namer   r   r   test_script_abspath   s    


zCmdLineTest.test_script_abspathc              	   C   sp   t  T}t|d}tj|dd t| t |}| ||||d t	j
j W d    n1 sb0    Y  d S )Nr]   Tdoraiser   r_   r   
py_compilecompiler   removemake_legacy_pycr:   r   r>   SourcelessFileLoaderr"   r   r#   pyc_filer   r   r   test_script_compiled   s    



z CmdLineTest.test_script_compiledc              	   C   sN   t  2}t|d}| ||||dtjj W d    n1 s@0    Y  d S )N__main__ r^   ra   r   r   r   test_directory   s    


zCmdLineTest.test_directoryc              	   C   sp   t  T}t|d}tj|dd t| t |}| ||||dt	j
j W d    n1 sb0    Y  d S )Nrs   Trh   rt   rj   rp   r   r   r   test_directory_compiled   s    




z#CmdLineTest.test_directory_compiledc                 C   s@   t  $}d| }| || W d    n1 s20    Y  d S )N"can't find '__main__' module in %r)r   r_   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    n1 sN0    Y  d S )Nrs   test_ziprt   )r   r_   r   r   r:   	zipimportzipimporter)r"   r   r#   zip_namerun_namer   r   r   test_zipfile  s    

zCmdLineTest.test_zipfilec              	   C   sp   t  T}t|d}tj|dtjjd}t|d|\}}| ||||dt	j
 W d    n1 sb0    Y  d S Nrs   T)ri   invalidation_moderz   rt   )r   r_   r   rk   rl   PycInvalidationMode	TIMESTAMPr   r:   r{   r|   r"   r   r#   compiled_namer}   r~   r   r   r   test_zipfile_compiled_timestamp  s    

z+CmdLineTest.test_zipfile_compiled_timestampc              	   C   sp   t  T}t|d}tj|dtjjd}t|d|\}}| ||||dt	j
 W d    n1 sb0    Y  d S r   )r   r_   r   rk   rl   r   CHECKED_HASHr   r:   r{   r|   r   r   r   r   "test_zipfile_compiled_checked_hash  s    

z.CmdLineTest.test_zipfile_compiled_checked_hashc              	   C   sp   t  T}t|d}tj|dtjjd}t|d|\}}| ||||dt	j
 W d    n1 sb0    Y  d S r   )r   r_   r   rk   rl   r   UNCHECKED_HASHr   r:   r{   r|   r   r   r   r   $test_zipfile_compiled_unchecked_hash'  s    

z0CmdLineTest.test_zipfile_compiled_unchecked_hashc                 C   sZ   t  >}t|d}t|d|\}}d| }| || W d    n1 sL0    Y  d S )NZnot_mainrz   rw   )r   r_   r   r   r<   )r"   r   r#   r}   r~   rx   r   r   r   test_zipfile_error1  s
    

zCmdLineTest.test_zipfile_errorc              
   C   sl   t  P}tj|d}t| t|d}| jddg|||dtj	j
|d W d    n1 s^0    Y  d S )Ntest_pkgr]   -mtest_pkg.scriptr,   r   r_   r   rd   joinr   r   r:   r   r>   r`   r"   r   pkg_dirr#   r   r   r   test_module_in_package8  s    

z"CmdLineTest.test_module_in_packagec                 C   s^   t  B}t|ddd\}}| jddg|||dtj||d W d    n1 sP0    Y  d S )Nrz   r   r]   r   r   Z
PYTHONPATHr-   r   r_   r   r:   r{   r|   r"   r   r}   r~   r   r   r   !test_module_in_package_in_zipfileB  s    
z-CmdLineTest.test_module_in_package_in_zipfilec                 C   sb   t  F}t|ddddd\}}| jddg|||dtj||d	 W d    n1 sT0    Y  d S )
Nrz   r   r]      )r   r   ztest_pkg.test_pkg.scriptztest_pkg.test_pkgr   r   r   r   r   r   $test_module_in_subpackage_in_zipfileI  s    
z0CmdLineTest.test_module_in_subpackage_in_zipfilec              
   C   sl   t  P}tj|d}t| t|d}| jddg|||dtj	j
|d W d    n1 s^0    Y  d S )Nr   rs   r   r,   r   r   r   r   r   test_packageQ  s    

zCmdLineTest.test_packagec              
   C   s   t  r}tj|d}t| t|d}tj|dd}t	| t 
|}| jddg|||dtjj|d W d    n1 s0    Y  d S )Nr   rs   Trh   r   r,   )r   r_   r   rd   r   r   r   rk   rl   rm   rn   r:   r   r>   ro   )r"   r   r   r#   r   rq   r   r   r   test_package_compiled[  s    



z!CmdLineTest.test_package_compiledc                 C   sZ   t  >}tj|d}t| d}| jddg||d W d    n1 sL0    Y  d S )Nr   z7'test_pkg' is a package and cannot be directly executedr   r,   r   r_   r   rd   r   r   r<   )r"   r   r   rx   r   r   r   test_package_errorh  s
    
zCmdLineTest.test_package_errorc                 C   sp   t  T}tj|d}t| tj|d}t| d}| jddg||d W d    n1 sb0    Y  d S )Nr   rs   z^Cannot use package as __main__ module; 'test_pkg' is a package and cannot be directly executedr   r,   r   )r"   r   r   Zmain_dirrx   r   r   r   test_package_recursionp  s    
z"CmdLineTest.test_package_recursionc                 C   s   t  }t j|d tj|d}t|d t|d}tddgt	R ddi\}}}t
d	krltt| d
d }| |d| | ||||||dtjj W d    n1 s0    Y  W d    n1 s0    Y  d S )Nrd   r   z1import sys; print('init_argv0==%r' % sys.argv[0])r]   r   r   r/   Fr   zinit_argv0==%rr   )r   r_   
change_cwdr   rd   r   r   r   r   r2   r   r   r   r    r!   r+   r   r>   r`   )r"   r   r   r#   r7   r8   r9   r@   r   r   r   test_issue8202{  s    



zCmdLineTest.test_issue8202c              
   C   s   t  }t j|d tdd\}|d tdddd\}}}tdkrVtt| d	d
 }| 	|
d| W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr   r=   wr$   z2import sys; print("sys.path[0]==%r" % sys.path[0])F)r/   r   zsys.path[0]==%rrt   r   )r   r_   r   openrC   r   r   r   r   r    r!   )r"   r   fr7   r8   r9   r@   r   r   r   "test_issue8202_dash_c_file_ignored  s    

z.CmdLineTest.test_issue8202_dash_c_file_ignoredc                 C   s   t  }t|d}t j|d~ tddT}|d tddgtR ddi\}}}| ||||||dt	j
j W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d S )	Notherr   r   r   r$   r/   Frt   )r   r_   r   r   r   rC   r   r2   r+   r   r>   r`   )r"   r   r#   r   r7   r8   r9   r   r   r   "test_issue8202_dash_m_file_ignored  s    



z.CmdLineTest.test_issue8202_dash_m_file_ignoredc              	   C   s   t  }tj|d}t|dddF}|d |d tdD ]}|d qD|d W d    n1 sr0    Y  t j|d	 t	|\}}}W d    n1 s0    Y  | 
d
| | 
d
| W d    n1 s0    Y  d S )Nzissue20884.pyr   
)newlinez#coding: iso-8859-1
z"""
   zQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
r       )r   r_   r   rd   r   r   rC   ranger   r   r   )r"   r   r#   r   _r7   r8   r9   r   r   r   test_issue20884  s    


(,zCmdLineTest.test_issue20884c              	   g   s|   t  `}t j|d4 tj|d}t|g|R   |V  W d    n1 sP0    Y  W d    n1 sn0    Y  d S )Nr   r   )r   r_   r   r   rd   r   r   )r"   argsr   r   r   r   r   setup_test_pkg  s    

zCmdLineTest.setup_test_pkgc                 G   s@   t dg|R ddi\}}}tdkr0tt| | |d |S )Nr   r/   Fr   )r   r   r   r   r   )r"   r   r7   r8   r9   r   r   r   check_dash_m_failure  s
    z CmdLineTest.check_dash_m_failurec                 C   sV   |   :}t|dd}| jdgtR  }| d| W d    n1 sH0    Y  d S )Nr   z+if __name__ == '__main__': raise ValueErrorztest_pkg.others
   ValueError)r   r   r   r2   r    )r"   r   r#   r9   r   r   r   test_dash_m_error_code_is_one  s    
z)CmdLineTest.test_dash_m_error_code_is_onec              	   C   st   d}|D ]f\}}|  |D td|\}}}| |d | || | d| W d    q1 sd0    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regexr7   r   r9   r   r   r   test_dash_m_errors  s    zCmdLineTest.test_dash_m_errorsc              
   C   s   t  }t j|dr td tdd W d    n1 sB0    Y  | d}| |d | d| | d| W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr   r   ztest_pkg/__init__.pycwbsG   Error while finding module specification.*ImportError.*bad magic numbers   is a packager   )	r   r_   r   r   mkdirr   r   r   r   r"   r   r9   r   r   r   test_dash_m_bad_pyc  s    



zCmdLineTest.test_dash_m_bad_pycc              
   C   s   t  |}t j|dP tdd W d    n1 s80    Y  | d}| d| W d    n1 sl0    Y  W d    n1 s0    Y  d S )Nr   z
asyncio.pyr   s>   Try using 'asyncio' instead of 'asyncio.py' as the module name)r   r_   r   r   r   r    r   r   r   r   *test_hint_when_triying_to_import_a_py_file  s    


z6CmdLineTest.test_hint_when_triying_to_import_a_py_filec              
   C   s   t tttf}|D ]}|j}d|}| |n | |D}| d}| 	|
d| | 	d| | 	d| W d    n1 s0    Y  W d    q1 s0    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	exceptioninitr   r9   r   r   r   test_dash_m_init_traceback   s    

z&CmdLineTest.test_dash_m_init_tracebackc                 C   sj   |   N}d}t|d| | d}| d| | d| | d| W d    n1 s\0    Y  d S )Nz1raise ImportError('Exception in __main__ module')rs   r   s   ImportErrors   Exception in __main__ moduler   )r   r   r   r    )r"   r   mainr9   r   r   r   test_dash_m_main_traceback  s    

z&CmdLineTest.test_dash_m_main_tracebackc                 C   s   t d}t }t|d|}t|\}}}|dd}| t	|d | 
|d d | 
|d d	 | 
|d
 d W d    n1 s0    Y  d S )Nz|            try:
                raise ValueError
            except:
                raise NameError from None
            r]   r   r      r   Z	Tracebackr   z  File    	NameError)textwrapdedentr   r_   r   r   decodesplitr   lenrc   
startswithr"   r]   r   r#   exitcoderL   rG   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 support.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#   r7   rL   rG   r   r   r   test_non_ascii*  s"    

zCmdLineTest.test_non_asciic                 C   sj   t d}t D}t|d|}t|\}}}|d}| | d W d    n1 s\0    Y  d S )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   r   r_   r   r   r   r   r   r   r   r   r   )test_issue20500_exit_with_exception_valueA  s    


z5CmdLineTest.test_issue20500_exit_with_exception_valuec                 C   sl   d}t  L}t|d|}t|\}}}tt|d }| d| W d    n1 s^0    Y  d S )Nz
1 + 1 = 2
r]   r   
    1 + 1 = 2
    ^)	r   r_   r   r   ioTextIOWrapperBytesIOrM   r    r   r   r   r   *test_syntaxerror_unindented_caret_positionS  s    
z6CmdLineTest.test_syntaxerror_unindented_caret_positionc                 C   s   t d}t }t|d|}t|\}}}tt|d	 }| 
d| d}t|d|}t|\}}}tt|d	 }| d| | 
d| W d    n1 s0    Y  d S )Nz;            if True:
                1 + 1 = 2
            r]   r   r   zif True:
    1 + 1 = 2
)r   r   r   r_   r   r   r   r   r   rM   r    r   r   r   r   r   (test_syntaxerror_indented_caret_position\  s    

z4CmdLineTest.test_syntaxerror_indented_caret_positionc                 C   sf   d}t  F}t|d|}t|\}}}| | dd  g d W d    n1 sX0    Y  d S )Nzfoo = f"""{}
foo"""
r]   )s
       foo"""             ^s3   SyntaxError: f-string: empty expression not allowedr   r_   r   r   r   
splitlinesr"   r]   r   r#   r   rL   rG   r   r   r   #test_syntaxerror_multi_line_fstrings  s    
z/CmdLineTest.test_syntaxerror_multi_line_fstringc                 C   sh   d}t  H}t|d|}td|\}}}| | dd  g d W d    n1 sZ0    Y  d S )Nzfoo = """\q"""
r]   z-Werrorr   )s       foo = """\q"""r   s'   SyntaxError: invalid escape sequence \qr   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 }t }t|d|}td||d}t| 	 }| 
|d | | || td||d}t| 	 }| 
|| td||d}t| 	 }| 
||| W d    n1 s0    Y  W d    n1 s0    Y  d S )Nc            import sys
            for entry in sys.path:
                print(entry)
            rs   z-Esr,   r   z-I)r   r   maxDiffr   r_   r   r	   r
   r   r   r   r   )	r"   r]   work_dirr   r#   rE   Zout_by_nameZ
out_by_dirZout_by_dir_isolatedr   r   r   -test_consistent_sys_path_for_direct_execution  s    
z9CmdLineTest.test_consistent_sys_path_for_direct_executionc                 C   s   t d}d | _t }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    n1 s0    Y  d S )Nr   Z
script_pkgrs   z-smzscript_pkg.__main__r,   r   z-ImzNo module named script_pkg)r   r   r   r   r_   r   rd   r   r   r   r	   r
   r   r   r   r   r   r    )r"   r]   r   r   r#   rE   Zout_by_moduleZout_by_packager   rL   rG   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   rL   rG   z: can't open file r   )ZassertFalser   rd   existsr	   rI   rJ   communicater    ZassertNotEqual
returncode)r"   r]   procr8   r9   r   r   r   test_nonexisting_script  s    z#CmdLineTest.test_nonexisting_script)N)F)F)F)9r   
__module____qualname__r+   r:   r<   rA   rF   
contextlibcontextmanagerrQ   rS   rT   rW   rY   r[   r\   rb   rg   rr   ru   rv   ry   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   r   r   Z   sr    
 

	










	%r   c                   C   s   t   d S r   )r   reap_childrenr   r   r   r   tearDownModule  s    r   rs   )!r   r   Zimportlib.machineryr{   Zunittestr   r   Zos.pathrk   rI   r   r   testr   Ztest.support.script_helperr   r   r   r   r   r   r	   r
   r   r2   Ztest_sourcer   r   ZTestCaser   r   r   r   r   r   r   r   <module>   s8   (5
     