a
    ze5                     @   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Zd dlZd dlmZmZmZmZmZmZmZ d dlmZmZ d dlZd dlmZmZmZmZ dZ dddddddZ!eeddgej"d  d	d	e#e!d
ddddZ$e$%e! G dd dZ&G dd dej'e&Z(G dd dej'e&Z)G dd dej'e&Z*G dd dej'Z+e,dkr|e-  dS )    N)forgetmake_legacy_pycunloadverbose
no_tracingcreate_empty_filetemp_dir)make_scriptmake_zip_script)	_run_code_run_module_code
run_modulerun_patha  # Check basic code execution
result = ['Top level assignment']
def f():
    result.append('Lower level reference')
f()
del f
# Check the sys module
import sys
run_argv0 = sys.argv[0]
run_name_in_sys_modules = __name__ in sys.modules
module_in_sys_modules = (run_name_in_sys_modules and
                         globals() is sys.modules[__name__].__dict__)
# Check nested operation
import runpy
nested = runpy._run_module_code('x=1\n', mod_name='<run>')
)__name____file__
__cached____package____doc____spec__zTop level assignmentzLower level referenceF   z<run>)xr   
__loader__)sysrunpyresult	run_argv0run_name_in_sys_modulesmodule_in_sys_modulesnestedc                   @   s$   e Zd Zg dZdd Zdd ZdS )CodeExecutionMixin)nameparentorigincachedhas_locationsubmodule_search_locationsc           	      C   s*  |  }|  }t|D ]D}|dr|dr||vrB|| ||d vr|d | q|d}|d}|du r| | n^|jdur| t|jt|j | j	D ]4}d| }|t
||f}|t
||f}| || q| t|t| |D ](}||| f}||| f}| || qdS )zbCheck two namespaces match.

           Ignores any unspecified interpreter created names
        __r   r   Nz	__spec__.)copylist
startswithendswithpopZassertIsNoneloaderassertEqualtypeCHECKED_SPEC_ATTRIBUTESgetattrset)	self	result_nsexpected_nskZresult_specZexpected_specattractualZexpected r8   %/usr/lib/python3.9/test/test_runpy.pyassertNamespaceMatchesP   s4    




z)CodeExecutionMixin.assertNamespaceMatchesc           
      C   s   t  }| }|d }tjd }tj||}|d}| || | tjd | | tj||| d|i}	||d< ||	}| ||	 | || | tjd | | tj||| dS )zCheck that an interface runs the example code correctly

           First argument is a callable accepting the initial globals and
           using them to create the actual namespace
           Second argument is the expected result
        r   r   Nsentinel)	objectr'   r   argvmodulesgetr:   ZassertIsZassertIsNot)
r2   Zcreate_namespaceZexpected_namespacer;   r4   run_nameZsaved_argv0Z	saved_modr3   Z
initial_nsr8   r8   r9   check_code_executionx   s     
z'CodeExecutionMixin.check_code_executionN)r   
__module____qualname__r/   r:   rA   r8   r8   r8   r9   r   D   s   	(r   c                   @   s    e Zd ZdZdd Zdd ZdS )ExecutionLayerTestCasez9Unit tests for runpy._run_code and runpy._run_module_codec                 C   s.   t  }|dd i dd }| || d S )Nr   c                 S   s   t ti | S N)r   example_sourceZinit_globalsr8   r8   r9   	create_ns   s    z7ExecutionLayerTestCase.test_run_code.<locals>.create_ns)example_namespacer'   updaterA   )r2   r4   rH   r8   r8   r9   test_run_code   s    z$ExecutionLayerTestCase.test_run_codec                    sd   d d}d}d}t jj ||dt }| ||||ddd  fdd	}| || d S )
Nz
<Nonsense>zSome other nonsensezNow you're just being silly )r"   r,   T)r   r   r   r   r   r   r   r   c                    s   t t|  S rE   )r   rF   rG   mod_namemod_specr8   r9   rH      s
    z>ExecutionLayerTestCase.test_run_module_code.<locals>.create_ns)	importlib	machinery
ModuleSpecrI   r'   rJ   rA   )r2   	mod_fnameZ
mod_loaderZmod_packager4   rH   r8   rM   r9   test_run_module_code   s*    
z+ExecutionLayerTestCase.test_run_module_codeN)r   rB   rC   r   rK   rT   r8   r8   r8   r9   rD      s   	rD   c                   @   s  e Zd ZdZdd Zdd Zdd Zd:d	d
Zd;dddddZdd Z	dd Z
d<dddddZd=dddddZdd Zd>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S )?RunModuleTestCasezUnit tests for runpy.run_modulec                 C   s2   zt | W n ty   Y n0 | d|  d S )NzExpected import error for )r   ImportErrorfail)r2   rN   r8   r8   r9   expect_import_error   s
    z%RunModuleTestCase.expect_import_errorc                 C   s^   |  d |  d |  d |  d |  d |  d |  d |  d |  d	 d S )
Nr   zsys.imp.ericzos.path.halfza.beez.howardz..eatenz.test_runpyz	.unittestmultiprocessing)rX   r2   r8   r8   r9   test_invalid_names   s    







z$RunModuleTestCase.test_invalid_namesc                 C   s   |  tdd d d S )Nr   r   )r-   r   rZ   r8   r8   r9   test_library_module   s    z%RunModuleTestCase.test_library_moduleFc                 C   s,   t | |rd S t j|d}t| |S )N__init__.py)osmkdirpathjoinr   )r2   pkg_dir	namespace	pkg_fnamer8   r8   r9   _add_pkg_dir   s    
zRunModuleTestCase._add_pkg_dir
runpy_testrc   parent_namespacesc                C   sR  |s|r|st dd}|tj d }tjt  }}	tdkrLtd|	 t	j
d| tdkrrtdt	jd  |r|g| }
||
d< |
D ]B}tj|	|}	| |	|}tdkrtd	|	 tdkrtd
| qtj|	|}t|d}|| W d    n1 s
0    Y  tdkr(td
| |d | | }tj||}||||fS )Nz2Can't mark top level module as a namespace package__runpy_pkg__pyr   z  Package tree in:r   z  Updated sys.path:z  Next level in:z
  Created:w.)RuntimeErrorr^   extsepr`   realpathtempfilemkdtempr   printr   insertra   re   openwriterP   utilspec_from_file_location)r2   sourcedepthZmod_baserc   rh   pkg_nameZ
test_fnamerb   Zsub_dirZnamespace_flagsZnamespace_flagrd   rS   mod_filerN   rO   r8   r8   r9   	_make_pkg   s2    
*zRunModuleTestCase._make_pkgc           	      C   sz  t tjD ]}|dr
tj|= q
tdkr2td tjd= tdkrJtd tj|ddD ]\}}}|D ]R}zt	tj
|| W qf ty } ztdkrt| W Y d }~qfd }~0 0 qf|D ]Z}tj
||}zt| W q ty } ztdkrt| W Y d }~qd }~0 0 qqXz t| tdkr:td W n8 tyt } ztdkr`t| W Y d }~n
d }~0 0 d S )	Nri   r   z  Removed sys.modules entriesr   z  Removed sys.path entryF)topdownz  Removed package tree)r(   r   r>   r)   r   rs   r`   r^   walkremovera   OSErrorrmdir)	r2   topentryrootdirsfilesr    exfullnamer8   r8   r9   _del_pkg   s.    

(,
zRunModuleTestCase._del_pkgc                 C   s\   d}|d  |7  < |d |d< |d }t j|j|d }||d< |rX|d  |7  < d S )Ncr   r   r   r   )rP   rw   rx   r    )r2   ns	alter_sysZchar_to_addspecZnew_specr8   r8   r9   _fix_ns_for_legacy_pyc  s    
z(RunModuleTestCase._fix_ns_for_legacy_pycc          
   	      s"  | j t|||d\}}}t t }|||jdd |d  rb||ddd  fdd}	ztd	krt	d
 | 
|	| t  t t| tjst| t t  td	krt	d | |  | 
|	| W | | n| | 0 td	krt	d d S )Nrg   rm   r   r   r   r   r   r   Tr   r   r   c                    s   t |  dS Nr   r   rG   r   rN   r8   r9   rH   6  s    z2RunModuleTestCase._check_module.<locals>.create_nsr   Running from source:Running from compiled:Module executed successfully)r}   rF   r   rI   r'   rJ   r#   
rpartitionr   rs   rA   rP   invalidate_caches
__import__r^   r   r   dont_write_bytecoder   r   r   r   )
r2   rz   r   rc   rh   rb   rS   rO   r4   rH   r8   r   r9   _check_module!  sH    

zRunModuleTestCase._check_modulec             	      s.  | j t|d||d\}}}}|dd t| t }	|	||tj	||d  rn|	|ddd  fdd	}
zt
d
krtd | |
|	 t  t| t| tjst| t| t
d
krtd t  | |	  | |
|	 W | | n| | 0 t
d
kr*td d S )N__main__rg   rm   r   r   Tr   c                    s   t |  dS r   r   rG   r   r{   r8   r9   rH   _  s    z3RunModuleTestCase._check_package.<locals>.create_nsr   r   r   zPackage executed successfully)r}   rF   r   r   rI   r'   rJ   rP   rw   cache_from_sourcer   rs   rA   r   r   r^   r   r   r   r   r   r   r   )r2   rz   r   rc   rh   rb   rS   rN   rO   r4   rH   r8   r   r9   _check_packageI  sJ    



z RunModuleTestCase._check_packagec                 C   s   |dkrt dd}|}t|D ]}|}tj||}q tj|d}t| tdkr`td| tj|d}	| |	 tdkrtd|	 tj|	d}
| |
 tdkrtd	|
 tj|
d
}t| tdkrtd| d S )Nr   z$Relative module test needs depth > 1ri   z
sibling.pyz  Added sibling module:unclez  Added uncle package:Zcousinz  Added cousin package:z	nephew.pyz  Added nephew module:)	
ValueErrorranger^   r`   ra   r   r   rs   re   )r2   base_dirry   rz   r{   Z
module_diriZ
parent_dirZsibling_fnameZ	uncle_dirZ
cousin_dirZnephew_fnamer8   r8   r9   _add_relative_modulesr  s&    

z'RunModuleTestCase._add_relative_modulesNc              	   C   sd  d}|  ||\}}}}|d u r&|}n|}z| ||| |dd }	tdkr\td| t||d}
| |
d | | |
d |	 | d	|
 | d
|
 ~
t	  t
| t| tjs4t| t| tdkrtd| t	  t||d}| |d | | |d |	 | d	| | d
| ~W | | n| | 0 tdkr`td d S )Nza\
from __future__ import absolute_import
from . import sibling
from ..uncle.cousin import nephew
rm   r   r   r   )r@   r   r   ZsiblingZnephewr   r   )r}   r   r   r   rs   r   r-   assertInrP   r   r   r^   r   r   r   r   r   r   )r2   rz   r@   contentsrb   rS   rN   rO   expected_namer{   Zd1Zd2r8   r8   r9   _check_relative_imports  s@    


z)RunModuleTestCase._check_relative_importsc                 C   s.   t dD ] }tdkrtd| | | qd S )N   r   Testing package depth:r   r   rs   r   r2   rz   r8   r8   r9   test_run_module  s    z!RunModuleTestCase.test_run_modulec                 C   s6   t ddD ]&}tdkr td| | j|ddd q
d S Nr   r   r   Trg   r   r   r8   r8   r9   $test_run_module_in_namespace_package  s    z6RunModuleTestCase.test_run_module_in_namespace_packagec                 C   s0   t ddD ] }tdkr td| | | q
d S )Nr   r   r   r   r   rs   r   r   r8   r8   r9   test_run_package  s    z"RunModuleTestCase.test_run_packagec                 C   s~  |  ddd}|\}}}}|dd}| | j| tj|dd}ttt	t
f}|D ]"}|j}| | d|}	t|dd	d
}
|
|	 W d    n1 s0    Y  zt| W n4 |y } z| dt| W Y d }~nd }~0 0 | d| zt|d  W n6 |yF } z| dt| W Y d }~nd }~0 0 | d| W d    qT1 sn0    Y  qTd S )NrL   r   r   	.__main__ri   r]   z raise {0}('{0} in __init__.py.')Zwtasciiencodingzfinding speczNothing raised; expected {}z
.submodule)r}   replace
addCleanupr   r^   r`   ra   rV   AttributeError	TypeErrorr   r   ZsubTestformatru   rv   r   ZassertNotInrW   )r2   r   rb   _rN   init
exceptions	exceptionr    ry   r|   errr8   r8   r9    test_run_package_init_exceptions  s,    

(&&z2RunModuleTestCase.test_run_package_init_exceptionsc              	   C   sp   |  dd\}}}}zJt| | td t| W d    n1 sH0    Y  W | | n| | 0 d S )NrL   r   found in sys\.modules)r}   r   assertWarnsRegexRuntimeWarningr   r   )r2   rb   r   rN   r8   r8   r9   test_submodule_imported_warning  s    (z1RunModuleTestCase.test_submodule_imported_warningc                 C   s   |  ddd\}}}}| | j| |dd}t| | |tj t	 $ t
dt t| W d    n1 sx0    Y  t| | td t| W d    n1 s0    Y  d S )NrL   r   r   r   errorr   )r}   r   r   r   r   r   r   r>   warningscatch_warningssimplefilterr   r   r   )r2   rb   r   rN   packager8   r8   r9    test_package_imported_no_warning  s    
&z2RunModuleTestCase.test_package_imported_no_warningc                 C   s4   t ddD ]$}tdkr td| | j|dd q
d S )Nr   r   r   T)rh   r   r   r8   r8   r9   %test_run_package_in_namespace_package  s    z7RunModuleTestCase.test_run_package_in_namespace_packagec                 C   s4   t ddD ]$}tdkr td| | j|dd q
d S )Nr   r   r   T)rc   r   r   r8   r8   r9   test_run_namespace_package  s    z,RunModuleTestCase.test_run_namespace_packagec                 C   s6   t ddD ]&}tdkr td| | j|ddd q
d S r   r   r   r8   r8   r9   /test_run_namespace_package_in_namespace_package  s    zARunModuleTestCase.test_run_namespace_package_in_namespace_packagec                 C   s2   t dD ]$}tdkrtd| | j|dd qd S )Nr   r   r   Tr   r   r   r8   r8   r9   test_run_module_alter_sys  s    z+RunModuleTestCase.test_run_module_alter_sysc                 C   s4   t ddD ]$}tdkr td| | j|dd q
d S )Nr   r   r   Tr   r   r   r8   r8   r9   test_run_package_alter_sys	  s    z,RunModuleTestCase.test_run_package_alter_sysc                 C   s0   t ddD ] }tdkr td| | | q
d S )N      r   z"Testing relative imports at depth:r   r   rs   r   r   r8   r8   r9   test_explicit_relative_import  s    z/RunModuleTestCase.test_explicit_relative_importc                 C   s2   t ddD ]"}tdkr td| | |d q
d S )Nr   r   r   z'Testing main relative imports at depth:r   r   r   r8   r8   r9   test_main_relative_import  s    z+RunModuleTestCase.test_main_relative_importc              	      s   d}d|  t|\}} }t  t }||tj| 	dd |d  fdd}z| 
|| W | | n| | 0 d S )Nr   z*And now for something completely differentrm   r   r   c                    s   t  | S rE   r   rG   rN   r@   r8   r9   rH   &  s    z2RunModuleTestCase.test_run_name.<locals>.create_ns)r}   rF   r   rI   r'   rJ   rP   rw   r   r   rA   r   )r2   rz   rb   rS   rO   r4   rH   r8   r   r9   test_run_name  s"    


zRunModuleTestCase.test_run_namec                 C   s|  dd l }d}d}ddg}d|d g}t }t }td|D ]V}d	|g| }	||	 |D ]}
||	d	 |
  q\|D ]}
||	d	 |
  qxq:d	|g| }	||	 ||	d
  | d|\}}}}| | j| td|d D ]}| |d| q|	|gD ]H}| 
||j | 
|jtjj |jrD||j n||j q
| t|d| | t|d| d S )Nr   r   ri   r   zuncle.cousinzuncle.cousin.nephewz.siblingr   rm   z.runpy_testrL   r   )pkgutilr1   r   ra   addr}   r   r   r   Zwalk_packagesZassertIsInstanceZ
ModuleInfoZmodule_finderrP   rQ   
FileFinderZispkgr   r    r-   len)r2   r   Z	max_depth	base_nameZpackage_suffixesZmodule_suffixesZexpected_packagesZexpected_modulesrz   r{   r    rb   rS   rN   rO   Z
moduleinfor8   r8   r9   test_pkgutil_walk_packages-  s@    



z,RunModuleTestCase.test_pkgutil_walk_packages)F)rf   )F)F)N)r   rB   rC   r   rX   r[   r\   re   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r8   r8   r9   rU      sB   
()
(
rU   c                   @   s   e Zd ZdZd#ddZd$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edd  Zd!d" ZdS )%RunPathTestCasezUnit tests for runpy.run_pathNFc                 C   s   |d u rt }t||||S rE   )rF   r	   )r2   
script_dirZscript_basenamery   omit_suffixr8   r8   r9   _make_test_scriptT  s
    z!RunPathTestCase._make_test_scriptTc                    s   fdd}t  }	|d u r"|}
n|}
|rJtj|
|}|j}|sRd |_nd  }}|	|||d||ddd | ||	 d  fdd}|r|d u rtj |}|sd |_||	d<  |	d	<  	d
d |	d< | ||	 d S )Nc                    s
   t  | S rE   r   rG   )script_namer8   r9   rH   _  s    z0RunPathTestCase._check_script.<locals>.create_nsrL   T)r   r   r   r   r   r   r   r   zprove.issue15230.is.fixedc                    s   t |  S rE   r   rG   r@   r   r8   r9   rH   |  s    r   r   rm   r   r   )
rI   r'   rP   rw   rx   r#   r,   rJ   rA   r   )r2   r   r   Zexpected_fileZexpected_argv0rN   expect_speccheck_loaderrH   r4   Z	spec_namerO   Z
mod_cachedr8   r   r9   _check_script[  sH    
zRunPathTestCase._check_scriptc                 C   s   t |}| t|t| d S rE   )reescapeZassertRaisesRegexrV   r   )r2   r   msgr8   r8   r9   _check_import_error  s    
z#RunPathTestCase._check_import_errorc                 C   sN   t  4}d}| ||}| j|d||dd W d    n1 s@0    Y  d S Nscript
<run_path>Fr   r   r   r   r2   r   rN   r   r8   r8   r9   test_basic_script  s    
z!RunPathTestCase.test_basic_scriptc                 C   sT   t  :}d}t| ||}| j|d||dd W d    n1 sF0    Y  d S r   )r   pathlibPathr   r   r   r8   r8   r9   "test_basic_script_with_path_object  s    

z2RunPathTestCase.test_basic_script_with_path_objectc                 C   sR   t  8}d}| j||dd}| j|d||dd W d    n1 sD0    Y  d S )Nr   T)r   r   Fr   r   r   r8   r8   r9   test_basic_script_no_suffix  s    
z+RunPathTestCase.test_basic_script_no_suffixc                 C   sf   t  L}d}| ||}tj|dd}t| | j|d||dd W d    n1 sX0    Y  d S )Nr   Tdoraiser   Fr   )r   r   
py_compilecompiler^   r   r   )r2   r   rN   r   compiled_namer8   r8   r9   test_script_compiled  s    

z$RunPathTestCase.test_script_compiledc                 C   sN   t  4}d}| ||}| j|d|||d W d    n1 s@0    Y  d S )Nr   r   rN   r   r   r8   r8   r9   test_directory  s    
zRunPathTestCase.test_directoryc                 C   st   t  Z}d}| ||}tj|dd}t| tjsRt|}| j	|d|||d W d    n1 sf0    Y  d S )Nr   Tr   r   r   )
r   r   r   r   r^   r   r   r   r   r   )r2   r   rN   r   r   Z
legacy_pycr8   r8   r9   test_directory_compiled  s    

z'RunPathTestCase.test_directory_compiledc                 C   sN   t  4}d}| ||}d| }| || W d    n1 s@0    Y  d S )Nnot_main"can't find '__main__' module in %r)r   r   r   )r2   r   rN   r   r   r8   r8   r9   test_directory_error  s
    z$RunPathTestCase.test_directory_errorc              	   C   s`   t  F}d}| ||}t|d|\}}| j|d|||dd W d    n1 sR0    Y  d S )Nr   test_zipr   FrN   r   )r   r   r
   r   )r2   r   rN   r   zip_namefnamer8   r8   r9   test_zipfile  s    zRunPathTestCase.test_zipfilec              	   C   sn   t  T}d}| ||}tj|dd}t|d|\}}| j|d|||dd W d    n1 s`0    Y  d S )Nr   Tr   r  r   Fr  )r   r   r   r   r
   r   )r2   r   rN   r   r   r  r  r8   r8   r9   test_zipfile_compiled  s    z%RunPathTestCase.test_zipfile_compiledc                 C   s^   t  D}d}| ||}t|d|\}}d| }| || W d    n1 sP0    Y  d S )Nr  r  r  )r   r   r
   r   )r2   r   rN   r   r  r  r   r8   r8   r9   test_zipfile_error  s    z"RunPathTestCase.test_zipfile_errorc              	   C   s   t  n}t  H}d}d| }| |||}t|d|\}}| tt| W d    n1 s\0    Y  W d    n1 sz0    Y  d S )Nr   z import runpy
runpy.run_path(%r)
r  )r   r   r
   ZassertRaisesRecursionErrorr   )r2   r   Z	dummy_dirrN   ry   r   r  r  r8   r8   r9   test_main_recursion_error  s    z)RunPathTestCase.test_main_recursion_errorc              	   C   s   t  n}tj|d}t|ddd}|d W d    n1 sD0    Y  t|}| |d d W d    n1 sz0    Y  d S )Nz	script.pyrl   latin1r   u%   
#coding:latin1
s = "non-ASCII: hé"
su   non-ASCII: hé)r   r^   r`   ra   ru   rv   r   r-   )r2   r   filenamefr   r8   r8   r9   test_encoding  s    (zRunPathTestCase.test_encoding)NF)NTT)r   rB   rC   r   r   r   r   r   r   r   r   r   r  r  r	  r
  r  r   r  r  r8   r8   r8   r9   r   Q  s(    
  
-	

	r   c                       s   e Zd ZdZejdkrenej Ze	e
jdd Z f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  ZS )TestExitl   :   win32c                  o   s6   t  }t|V  W d    n1 s(0    Y  d S rE   )r   r   r   )argskwargsZtmp_fnr8   r8   r9   tmp_path  s    zTestExit.tmp_pathc                    s\   |   @}|d  | _}|td t j|i | W d    n1 sN0    Y  d S )Nzham.pyz@                    raise KeyboardInterrupt
                    )r  ham
write_texttextwrapdedentsuperrun)r2   r  r  tmpr  	__class__r8   r9   r    s    
zTestExit.runc                 O   sB   t j|i |dt jd}| |jd | |j| j d S )NT)textstderrz
KeyboardInterrupt
)	
subprocessr  PIPEZ
assertTruer"  r*   r-   
returncodeEXPECTED_CODE)r2   r  r  procr8   r8   r9   assertSigInt  s    zTestExit.assertSigIntc                 C   s   |  tj| jg d S rE   )r(  r   
executabler  rZ   r8   r8   r9   test_pymain_run_file  s    zTestExit.test_pymain_run_filec                 C   s8   | j j}|d }|td | jtj|g|d d S )Nzrun_module.pyzU                import runpy
                runpy.run_module("ham")
                cwdr  r!   r  r  r  r(  r   r)  )r2   r  r   r8   r8   r9   %test_pymain_run_file_runpy_run_module  s    z.TestExit.test_pymain_run_file_runpy_run_modulec                 C   s8   | j j}|d }|td | jtj|g|d d S )Nzrun_module_as_main.pyz^                import runpy
                runpy._run_module_as_main("ham")
                r+  r-  )r2   r  Zrun_module_as_mainr8   r8   r9   -test_pymain_run_file_runpy_run_module_as_main$  s    z6TestExit.test_pymain_run_file_runpy_run_module_as_mainc                 C   s   | j tjddg| jjd d S )N-cz%import runpy; runpy.run_module('ham')r+  r(  r   r)  r  r!   rZ   r8   r8   r9   "test_pymain_run_command_run_module1  s    
z+TestExit.test_pymain_run_command_run_modulec                 C   s   | j tjddg| jjd d S )Nr0  
import hamr+  r1  rZ   r8   r8   r9   test_pymain_run_command7  s    z TestExit.test_pymain_run_commandc                 C   s   | j tjgd| jjd d S )Nr3  )inputr,  r1  rZ   r8   r8   r9   test_pymain_run_stdin:  s    zTestExit.test_pymain_run_stdinc                 C   s$   | j }| jtjd|jg|jd d S )Nz-mr+  )r  r(  r   r)  stemr!   )r2   r  r8   r8   r9   test_pymain_run_module=  s    zTestExit.test_pymain_run_module)r   rB   rC   ZSTATUS_CONTROL_C_EXITr   platformsignalSIGINTr&  staticmethod
contextlibcontextmanagerr  r  r(  r*  r.  r/  r2  r4  r6  r8  __classcell__r8   r8   r  r9   r    s"   r  r   ).r=  Zimportlib.machineryrP   importlib.utilZos.pathr^   r   r   r   r:  r#  r   rq   r  Zunittestr   Ztest.supportr   r   r   r   r   r   r   Ztest.support.script_helperr	   r
   r   r   r   r   r   rF   Zimplicit_namespacer=   dictrI   rJ   r   ZTestCaserD   rU   r   r  r   mainr8   r8   r8   r9   <module>   s\   $	

O'    %M
