B
    \                 @   s   d 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 ddl	m
Z ddlmZ ddlmZ ddlmZ dd	lmZ ddlm
Z
 G d
d de
je
jejZdd Zedkree  dS )zTests for distutils.spawn.    N)mock)run_unittest
unix_shell)support)find_executable)_nt_quote_args)spawn)DistutilsExecErrorc               @   s6   e Zd Zdd Zeejdkddd Zdd Z	d	S )
SpawnTestCasec             C   sF   x@ddgddgfddgddgffD ]\}}t |}| || q"W d S )Nz
with spaceZnospacez"with space"Znochange)r   assertEqual)selfargsZwantedZres r   +lib/python3.7/distutils/tests/test_spawn.pytest_nt_quote_args   s    z SpawnTestCase.test_nt_quote_args)ntposixzRuns only under posix or ntc             C   s   |   }tjdkr2tj|d}| |dt  ntj|d}| |d t|d | 	t
t|g tjdkrtj|d}| |dt  ntj|d}| |d t|d t|g d S )	Nwin32zfoo.shz#!%s
exit 1zfoo.batzexit 1i  z#!%s
exit 0zexit 0)ZmkdtempsysplatformospathjoinZ
write_filer   chmodZassertRaisesr	   r   )r   ZtmpdirZexer   r   r   
test_spawn   s    

zSpawnTestCase.test_spawnc             C   s&  t  }t j}|d }tj||}t|d W d Q R X t|tj	 t
||d}| || tjdkrt
||d}| || t | t
|}| || W d Q R X d| }t
||d}| | t  <}td|$ |d t
|}| || W d Q R X W d Q R X W d Q R X d S )Nz.exewb)r   r   Z
dontexist_zdistutils.spawn.os.defpathPATH)test_supportZtemp_dirZTESTFNr   r   r   openr   statS_IXUSRr   r   r   r   Z
change_cwdZassertIsNoneZEnvironmentVarGuardr   Zpatchpop)r   Ztmp_dirZprogram_noeextZprogramfilenamervZdont_exist_programenvr   r   r   test_find_executable:   s.    




z"SpawnTestCase.test_find_executableN)
__name__
__module____qualname__r   unittestZ
skipUnlessr   namer   r%   r   r   r   r   r
      s   
r
   c               C   s
   t tS )N)r)   Z	makeSuiter
   r   r   r   r   
test_suitec   s    r+   __main__)__doc__r   r   r   r)   r   Ztest.supportr   r   Ztestr   r   Zdistutils.spawnr   r   r   Zdistutils.errorsr	   Zdistutils.testsZTempdirManagerZLoggingSilencerZTestCaser
   r+   r&   r   r   r   r   <module>   s$   Q