a
    zeT                     @   s   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
 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 )    N)run_unittest
unix_shell)support)find_executable)spawn)DistutilsExecErrorc                   @   s6   e Zd Zeejdv ddd Zdd Zdd Z	d	S )
SpawnTestCase)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)mkdtempsysplatformospathjoinZ
write_filer   chmodassertRaisesr   r   )selfZtmpdirZexe r   0/usr/lib/python3.9/distutils/tests/test_spawn.py
test_spawn   s    

zSpawnTestCase.test_spawnc                 C   s  t  }t j}|d }tj||}t|d W d    n1 sH0    Y  t|tj	 t
||d}| || tjdkrt
||d}| || t |$ t
|}| || W d    n1 s0    Y  d| }t
||d}| | t  }d|d< tjjd|d	d
 tjd|b t
|}| | t |$ t
|}| || W d    n1 st0    Y  W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t  }tj|d< tjjddd	d
 tjddb t
|}| | t |$ t
|}| || W d    n1 s^0    Y  W d    n1 s~0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t  }|dd  tjjdtd	dT tjd|$ t
|}| || W d    n1 s.0    Y  W d    n1 sN0    Y  tjjd|d	d
T tjdd$ t
|}| || W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nz.exewb)r   r   Z
dontexist_ PATHzdistutils.spawn.os.confstrT)Zreturn_valuecreatezdistutils.spawn.os.defpath)Zside_effectr   )test_supportZtemp_dirZTESTFNr   r   r   openr   statS_IXUSRr   ZassertEqualr   r   Z
change_cwdZassertIsNoneZEnvironmentVarGuardunittestZmockZpatchpathseppop
ValueError)r   Ztmp_dirZprogram_noeextZprogramfilenamervZdont_exist_programenvr   r   r   test_find_executable.   s~    
*





Lz"SpawnTestCase.test_find_executablec                 C   sJ   |  t}tdg W d    n1 s*0    Y  | dt|j d S )Nzdoes-not-existzcommand 'does-not-exist' failed)r   r   r   ZassertInstr	exception)r   ctxr   r   r   test_spawn_missing_exe   s    (z$SpawnTestCase.test_spawn_missing_exeN)
__name__
__module____qualname__r    Z
skipUnlessr   namer   r'   r+   r   r   r   r   r      s   
Qr   c                   C   s
   t tS )N)r    Z	makeSuiter   r   r   r   r   
test_suite   s    r0   __main__)r   r   r   Zunittest.mockr    Ztest.supportr   r   testr   r   Zdistutils.spawnr   r   Zdistutils.errorsr   Zdistutils.testsZTempdirManagerZLoggingSilencerZTestCaser   r0   r,   r   r   r   r   <module>   s    w