o
    JAf6                     @   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rSee  dS dS )    N)run_unittest
unix_shell)	os_helper)find_executable)spawn)DistutilsExecError)supportc                   @   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rtj|d}| |dt  ntj|d}| |d t|d | 	t
t|g tjdkrIt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   1/usr/lib/python3.10/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 s$w   Y  t|tj	 t
||d}| || tjdkrMt
||d}| || t | t
|}| || W d    n1 sgw   Y  d| }t
||d}| | t  d}d|d< tjjd|d	d
G tjd|0 t
|}| | t | t
|}| || W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  t  h}tj|d< tjjddd	d
I tjdd1 t
|}| | t | t
|}| || W d    n	1 s+w   Y  W d    n	1 s;w   Y  W d    n	1 sKw   Y  W d    n	1 s[w   Y  t  }|dd  tjjdtd	d* tjd| t
|}| || W d    n	1 sw   Y  W d    n	1 sw   Y  tjjd|d	d
* tjdd t
|}| || W d    n	1 sw   Y  W d    n	1 sw   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   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   )r   Z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   



 


 
 	  =$z"SpawnTestCase.test_find_executablec                 C   sJ   |  t}tdg W d    n1 sw   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   r   Zdistutils.spawnr   r   Zdistutils.errorsr   Zdistutils.testsr   ZTempdirManagerZLoggingSilencerZTestCaser	   r0   r,   r   r   r   r   <module>   s&    w