o
    g                     @   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 d dlmZmZmZ d dl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re/  dS dS )    N)
no_tracingverbose)forgetmake_legacy_pycunload)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r.|dr.||vr!|| ||d vr.|d | q|d}|d}|du rC| | n/|jdurT| t|jt|j | j	D ]}d| }|t
||f}|t
||f}| || qW| t|t| |D ]}||| f}||| f}| || q~d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   E/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_runpy.pyassertNamespaceMatchesP   s8   




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init_globalsr8   r8   r9   	create_ns      z7ExecutionLayerTestCase.test_run_code.<locals>.create_ns)example_namespacer'   updaterA   )r2   r4   rI   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   rI      s
   z>ExecutionLayerTestCase.test_run_module_code.<locals>.create_ns)	importlib	machinery
ModuleSpecrK   r'   rL   rA   )r2   	mod_fnameZ
mod_loaderZmod_packager4   rI   r8   rO   r9   test_run_module_code   s*   
z+ExecutionLayerTestCase.test_run_module_codeN)r   rB   rC   r   rM   rV   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   s4   zt | W n
 ty   Y d S w | d|  d S )NzExpected import error for )r   ImportErrorfail)r2   rP   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)rZ   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   r\   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re   parent_namespacesc                C   sN  |s|r
|s
t dd}|tj d }tjt  }}	tdkr&td|	 t	j
d| tdkr9tdt	jd  |rh|g| }
||
d< |
D ]!}tj|	|}	| |	|}tdkr^td	|	 tdkrgtd
| qFtj|	|}t|d}|| W d    n1 sw   Y  tdkrt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`   extseprb   realpathtempfilemkdtempr   printr   insertrc   rg   openwriterR   utilspec_from_file_location)r2   sourcedepthZmod_basere   rj   pkg_nameZ
test_fnamerd   Zsub_dirZnamespace_flagsZnamespace_flagrf   rU   mod_filerP   rQ   r8   r8   r9   	_make_pkg   s6   
zRunModuleTestCase._make_pkgc           	      C   s  t tjD ]}|drtj|= qtdkrtd tjd= tdkr%td tj|ddD ]]\}}}|D ](}zt	tj
|| W q3 ty[ } ztdkrQt| W Y d }~q3d }~ww |D ]*}tj
||}zt| W q^ ty } ztdkr~t| W Y d }~q^d }~ww q,zt| tdkrtd W d S W d S  ty } ztdkrt| W Y d }~d S W Y d }~d S d }~ww )	Nrk   r   z  Removed sys.modules entriesr   z  Removed sys.path entryF)topdownz  Removed package tree)r(   r   r>   r)   r   ru   rb   r`   walkremoverc   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< |r.|d  |7  < d S d S )Ncr   r   r   r   )rR   ry   rz   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  r1||ddd  fdd}	zGtd	krBt	d
 | 
|	| t  t t| tjsyt| t t  td	krmt	d | |  | 
|	| W | | n| | w td	krt	d d S d S )Nri   ro   r   r   r   r   r   r   Tr   r   r   c                       t |  dS Nr   r   rG   r   rP   r8   r9   rI   6     z2RunModuleTestCase._check_module.<locals>.create_nsr   Running from source:Running from compiled:Module executed successfully)r   rF   r   rK   r'   rL   r#   
rpartitionr   ru   rA   rR   invalidate_caches
__import__r`   r   r   dont_write_bytecoder   r   r   r   )
r2   r|   r   re   rj   rd   rU   rQ   r4   rI   r8   r   r9   _check_module!  sJ   

zRunModuleTestCase._check_modulec             	      s0  | j t|d||d\}}}}|dd t| t }	|	||tj	||d  r7|	|ddd  fdd	}
zGt
d
krHtd | |
|	 t  t| t| tjst| t| t
d
krotd t  | |	  | |
|	 W | | n| | w t
d
krtd d S d S )N__main__ri   ro   r   r   Tr   c                    r   r   r   rG   r   r}   r8   r9   rI   _  r   z3RunModuleTestCase._check_package.<locals>.create_nsr   r   r   zPackage executed successfully)r   rF   r   r   rK   r'   rL   rR   ry   cache_from_sourcer   ru   rA   r   r   r`   r   r   r   r   r   r   r   )r2   r|   r   re   rj   rd   rU   rP   rQ   r4   rI   r8   r   r9   _check_packageI  sL   



z RunModuleTestCase._check_packagec                 C   s   |dkrt dd}|}t|D ]}|}tj||}qtj|d}t| tdkr0td| tj|d}	| |	 tdkrEtd|	 tj|	d}
| |
 tdkrZtd	|
 tj|
d
}t| tdkrptd| d S d S )Nr   z$Relative module test needs depth > 1rk   z
sibling.pyz  Added sibling module:unclez  Added uncle package:Zcousinz  Added cousin package:z	nephew.pyz  Added nephew module:)	
ValueErrorranger`   rb   rc   r   r   ru   rg   )r2   base_dirr{   r|   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   sb  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st| t| tdkrqtd| t	  t||d}| |d | | |d |	 | d	| | d
| ~W | | n| | w tdkrtd d S d S )Nza\
from __future__ import absolute_import
from . import sibling
from ..uncle.cousin import nephew
ro   r   r   r   )r@   r   r   ZsiblingZnephewr   r   )r   r   r   r   ru   r   r-   assertInrR   r   r   r`   r   r   r   r   r   r   )r2   r|   r@   contentsrd   rU   rP   rQ   expected_namer}   Zd1Zd2r8   r8   r9   _check_relative_imports  sB   


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   ru   r   r2   r|   r8   r8   r9   test_run_module  s   z!RunModuleTestCase.test_run_modulec                 C   6   t ddD ]}tdkrtd| | j|ddd qd S Nr   r   r   Tri   r   r   r8   r8   r9   $test_run_module_in_namespace_package     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   ru   r   r   r8   r8   r9   test_run_package     z"RunModuleTestCase.test_run_packagec                 C   sx  |  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 sQw   Y  zt| W n |yv } z| dt| W Y d }~nd }~ww | d| zt|d  W n |y } z| dt| W Y d }~nd }~ww | d| W d    q*1 sw   Y  q*d S )NrN   r   r   	.__main__rk   r_   z raise {0}('{0} in __init__.py.')Zwtasciiencodingzfinding speczNothing raised; expected {}z
.submodule)r   replace
addCleanupr   r`   rb   rc   rX   AttributeError	TypeErrorr   r   ZsubTestformatrw   rx   r   ZassertNotInrY   )r2   r   rd   _rP   Zinit
exceptions	exceptionr    r{   r~   errr8   r8   r9    test_run_package_init_exceptions  s<   
z2RunModuleTestCase.test_run_package_init_exceptionsc              	   C   s~   |  dd\}}}}z.t| | td t| W d    n1 s$w   Y  W | | d S W | | d S | | w )NrN   r   found in sys\.modules)r   r   assertWarnsRegexRuntimeWarningr   r   )r2   rd   r   rP   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 s<w   Y  t| | td t| W d    d S 1 s[w   Y  d S )NrN   r   r   r   errorr   )r   r   r   r   r   r   r   r>   warningscatch_warningssimplefilterr   r   r   )r2   rd   r   rP   packager8   r8   r9    test_package_imported_no_warning  s   


"z2RunModuleTestCase.test_package_imported_no_warningc                 C   4   t ddD ]}tdkrtd| | j|dd qd S )Nr   r   r   T)rj   r   r   r8   r8   r9   %test_run_package_in_namespace_package     z7RunModuleTestCase.test_run_package_in_namespace_packagec                 C   r   )Nr   r   r   T)re   r   r   r8   r8   r9   test_run_namespace_package  r   z,RunModuleTestCase.test_run_namespace_packagec                 C   r   r   r   r   r8   r8   r9   /test_run_namespace_package_in_namespace_package  r   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   r   )Nr   r   r   Tr   r   r   r8   r8   r9   test_run_package_alter_sys	  r   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   ru   r   r   r8   r8   r9   test_explicit_relative_import  r   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 | | d S | | w )Nr   z*And now for something completely differentro   r   r   c                    s   t  | S rE   r   rG   rP   r@   r8   r9   rI   &  rJ   z2RunModuleTestCase.test_run_name.<locals>.create_ns)r   rF   r   rK   r'   rL   rR   ry   r   r   rA   r   )r2   r|   rd   rU   rQ   r4   rI   r8   r   r9   test_run_name  s"   


zRunModuleTestCase.test_run_namec                 C   sx  dd l }d}d}ddg}d|d g}t }t }td|D ]+}d	|g| }	||	 |D ]}
||	d	 |
  q.|D ]}
||	d	 |
  q<qd	|g| }	||	 ||	d
  | d|\}}}}| | j| td|d D ]	}| |d| qu|	|gD ]"}| 
||j | 
|jtjj |jr||j q||j q| t|d| | t|d| d S )Nr   r   rk   r   zuncle.cousinzuncle.cousin.nephewz.siblingr   ro   z.runpy_testrN   r   )pkgutilr1   r   rc   addr   r   r   r   walk_packagesZassertIsInstance
ModuleInfomodule_finderrR   rS   
FileFinderispkgr   r    r-   len)r2   r   Z	max_depth	base_nameZpackage_suffixesZmodule_suffixesZexpected_packagesZexpected_modulesr|   r}   r    rd   rU   rP   rQ   Z
moduleinfor8   r8   r9   test_pkgutil_walk_packages-  sB   



z,RunModuleTestCase.test_pkgutil_walk_packages)F)rh   rE   )r   rB   rC   r   rZ   r]   r^   rg   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   rW      sD    
()
(
rW   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_basenamer{   omit_suffixr8   r8   r9   _make_test_scriptT  s
   z!RunPathTestCase._make_test_scriptTc                    s   fdd}t  }	|d u r|}
n|}
|r%tj|
|}|j}|s$d |_nd  }}|	|||d||ddd | ||	 d  fdd}|r\|d u r\tj |}|sXd |_||	d<  |	d	<  	d
d |	d< | ||	 d S )Nc                    s
   t  | S rE   r   rG   )script_namer8   r9   rI   _  s   
z0RunPathTestCase._check_script.<locals>.create_nsrN   T)r   r   r   r   r   r   r   r   zprove.issue15230.is.fixedc                    s   t |  S rE   r   rG   r@   r   r8   r9   rI   |  rJ   r   r   ro   r   r   )
rK   r'   rR   ry   rz   r#   r,   rL   rA   r   )r2   r   r   Zexpected_fileZexpected_argv0rP   expect_speccheck_loaderrI   r4   Z	spec_namerQ   Z
mod_cachedr8   r   r9   _check_script[  sJ   
zRunPathTestCase._check_scriptc                 C   s   t |}| t|t| d S rE   )reescapeassertRaisesRegexrX   r   )r2   r   msgr8   r8   r9   _check_import_error  s   
z#RunPathTestCase._check_import_errorc                 C   sP   t  }d}| ||}| j|d||dd W d    d S 1 s!w   Y  d S Nscript
<run_path>Fr   r   r   r   r2   r   rP   r   r8   r8   r9   test_basic_script     
"z!RunPathTestCase.test_basic_scriptc                 C   sV   t  }d}t| ||}| j|d||dd W d    d S 1 s$w   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   sT   t  }d}| j||dd}| j|d||dd W d    d S 1 s#w   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   sh   t  '}d}| ||}tj|dd}t| | j|d||dd W d    d S 1 s-w   Y  d S )Nr   Tdoraiser   Fr   )r   r   
py_compilecompiler`   r   r   )r2   r   rP   r   compiled_namer8   r8   r9   test_script_compiled  s   

"z$RunPathTestCase.test_script_compiledc                 C   sP   t  }d}| ||}| j|d|||d W d    d S 1 s!w   Y  d S )Nr   r   rP   r   r   r8   r8   r9   test_directory  r  zRunPathTestCase.test_directoryc                 C   s   t  6}d}| ||}tj|dd}t| tjs1t|}| j	|d|||d W d    d S W d    d S 1 s<w   Y  d S )Nr   Tr  r   r  )
r   r   r	  r
  r`   r   r   r   r   r   )r2   r   rP   r   r  Z
legacy_pycr8   r8   r9   test_directory_compiled  s   

"z'RunPathTestCase.test_directory_compiledc                 C   sP   t  }d}| ||}d| }| || W d    d S 1 s!w   Y  d S )Nnot_main"can't find '__main__' module in %r)r   r   r   )r2   r   rP   r   r   r8   r8   r9   test_directory_error  s   "z$RunPathTestCase.test_directory_errorc              	   C   sb   t  $}d}| ||}t|d|\}}| j|d|||dd W d    d S 1 s*w   Y  d S )Nr   test_zipr   FrP   r   )r   r   r
   r   )r2   r   rP   r   zip_namefnamer8   r8   r9   test_zipfile  s   "zRunPathTestCase.test_zipfilec              	   C   sp   t  +}d}| ||}tj|dd}t|d|\}}| j|d|||dd W d    d S 1 s1w   Y  d S )Nr   Tr  r  r   Fr  )r   r   r	  r
  r
   r   )r2   r   rP   r   r  r  r  r8   r8   r9   test_zipfile_compiled  s   "z%RunPathTestCase.test_zipfile_compiledc                 C   s`   t  #}d}| ||}t|d|\}}d| }| || W d    d S 1 s)w   Y  d S )Nr  r  r  )r   r   r
   r   )r2   r   rP   r   r  r  r   r8   r8   r9   test_zipfile_error  s   "z"RunPathTestCase.test_zipfile_errorc           	   	   C   s   t  C}t  '}d}d| }| |||}t|d|\}}d}| t|t| W d    n1 s1w   Y  W d    d S W d    d S 1 sIw   Y  d S )Nr   z import runpy
runpy.run_path(%r)
r  zrecursion depth exceeded)r   r   r
   r   RecursionErrorr   )	r2   r   Z	dummy_dirrP   r{   r   r  r  r   r8   r8   r9   test_main_recursion_error  s   Pz)RunPathTestCase.test_main_recursion_errorc              	   C   s   t  8}tj|d}t|ddd}|d W d    n1 s"w   Y  t|}| |d d W d    d S 1 s>w   Y  d S )Nz	script.pyrn   latin1r   u%   
#coding:latin1
s = "non-ASCII: hé"
su   non-ASCII: hé)r   r`   rb   rc   rw   rx   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   s:    t  }t|V  W d    d S 1 sw   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    d S 1 s(w   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
assertTruer0  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   )r6  r   
executabler&  r\   r8   r8   r9   test_pymain_run_file  s   zTestExit.test_pymain_run_filec                 C   8   | 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)  r6  r   r7  )r2   r,  r   r8   r8   r9   %test_pymain_run_file_runpy_run_module     z.TestExit.test_pymain_run_file_runpy_run_modulec                 C   r9  )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%  r>  z6TestExit.test_pymain_run_file_runpy_run_module_as_mainc                 C      | j tjddg| jjd d S )N-cz%import runpy; runpy.run_module('ham')r:  r6  r   r7  r&  r!   r\   r8   r8   r9   "test_pymain_run_command_run_module2  s   

z+TestExit.test_pymain_run_command_run_modulec                 C   r@  )NrA  
import hamr:  rB  r\   r8   r8   r9   test_pymain_run_command8  s   z TestExit.test_pymain_run_commandc                 C   s   | j tjgd| jjd d S )NrD  )inputr;  rB  r\   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&  r6  r   r7  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SIGINTr4  staticmethod
contextlibcontextmanagerr%  r+  r6  r8  r=  r?  rC  rE  rG  rI  __classcell__r8   r8   r-  r9   r!    s$    r!  r   )0rN  importlib.machineryrR   importlib.utilZos.pathr`   r  r	  r   rK  r1  r   rs   r(  Zunittestr   Ztest.supportr   r   Ztest.support.import_helperr   r   r   Ztest.support.os_helperr   r   Ztest.support.script_helperr	   r
   r   r   r   r   r   rF   Zimplicit_namespacer=   dictrK   rL   r   ZTestCaserD   rW   r   r!  r   mainr8   r8   r8   r9   <module>   sd   	

O'    &M