a
    ø£Beö  ã                
   @   sP  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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 ddlmZ ddlmZ ej ej¡Zejdd	„ ƒZejd
d„ ƒZdd„ Z ejej! "dddgfdddgfddgfdddgfg¡dd„ ƒƒZ#ejej! "dddgfdddgfddgfdddgfg¡dd„ ƒƒZ$G dd„ dej%ƒZ&dS )z
Tests for platutils.py
é    N)Úinterrupt_main)Úfind_cmdÚFindCmdErrorÚ	arg_splitÚsystemÚ	getoutputÚgetoutputerrorÚget_output_error_code)Úcapture_output)Ú
decorators)Útoolsc                  C   s   t dƒ} |  d¡sJ ‚dS )z*Make sure we can find the full path to ls.ZlsN)r   Úendswith©Úpath© r   úc/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/IPython/utils/tests/test_process.pyÚtest_find_cmd_ls'   s    r   c                  C   s"   t dƒ} |  ¡  d¡sJ | ƒ‚dS )zTry to find pythonw on Windows.Úpythonwzpythonw.exeN)r   Úlowerr   r   r   r   r   Útest_find_cmd_pythonw.   s    r   c                   C   s   t  ttd¡ dS )z?Make sure that FindCmdError is raised if we can't find the cmd.ZasdfasdfN)ÚpytestZraisesr   r   r   r   r   r   Útest_find_cmd_fail5   s    r   zargstr, argvÚhizhello thereZhelloZthereu   hÇŽllozsomething "with quotes"Z	somethingz"with quotes"c                 C   s   t | ƒ|ksJ ‚dS ©z?Ensure that argument lines are correctly split like in a shell.N©r   ©ZargstrÚargvr   r   r   Útest_arg_split:   s    r   zargstr,argvzwith quotesc                 C   s   t | ƒ|ksJ ‚dS r   r   r   r   r   r   Útest_arg_split_win32L   s    r   c                   @   sb   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	e
jdd„ ƒZdd„ Zdd„ ZdS )ÚSubProcessTestCasec                 C   s   g d¢}|   d |¡¡ dS )zMake a valid python temp file.)z
import sysz+print('on stdout', end='', file=sys.stdout)z+print('on stderr', end='', file=sys.stderr)zsys.stdout.flush()zsys.stderr.flush()Ú
N)ZmktmpÚjoin)ÚselfÚlinesr   r   r   ÚsetUp\   s    zSubProcessTestCase.setUpc                 C   s&   t t› d| j› d�ƒ}|  |d¡ d S )Nú "ú"r   )r   ÚpythonÚfnameÚassertEqual©r"   Ústatusr   r   r   Útest_systeme   s    zSubProcessTestCase.test_systemc                 C   s   t dt ƒ}|  |d¡ d S )Nz%s -c "import sys"r   )r   r'   r)   r*   r   r   r   Útest_system_quotesi   s    z%SubProcessTestCase.test_system_quotesc                 C   s�   t  ¡ t  ¡ krt d¡‚t tjtj¡ dd„ }t j|d� 	¡  t
 
¡ }z
|ƒ }W n tyf   Y n0 t
 
¡ }|  || dk d||  ¡ |S )z8
        Interrupt a subprocess after a second.
        z*Can't run this test if not in main thread.c                   S   s   t  d¡ tƒ  d S )Ng      à?)ÚtimeÚsleepr   r   r   r   r   Ú	interrupty   s    
z7SubProcessTestCase.assert_interrupts.<locals>.interrupt)Útargeté   zProcess didn't die quickly: %s)Ú	threadingÚmain_threadÚcurrent_threadr   ÚskipÚsignalÚSIGINTÚdefault_int_handlerÚThreadÚstartr.   ÚKeyboardInterruptÚ
assertTrue)r"   Úcommandr0   r;   ÚresultÚendr   r   r   Úassert_interruptsm   s    

ÿz$SubProcessTestCase.assert_interruptsc                 C   s*   dd„ }|   |¡}|  |dd|› �¡ dS )zr
        When interrupted in the way ipykernel interrupts IPython, the
        subprocess is interrupted.
        c                   S   s   t dt ƒS )Nz"%s -c "import time; time.sleep(5)")r   r'   r   r   r   r   r>   �   s    z9SubProcessTestCase.test_system_interrupt.<locals>.commandr   z(The process wasn't interrupted. Status: N)rA   ZassertNotEqual)r"   r>   r+   r   r   r   Útest_system_interrupt‹   s
    
ÿz(SubProcessTestCase.test_system_interruptc                 C   sJ   t t› d| j› d�ƒ}z|  |d¡ W n tyD   |  |d¡ Y n0 d S )Nr%   r&   zon stderron stdoutzon stdouton stderr)r   r'   r(   r)   ÚAssertionError©r"   Úoutr   r   r   Útest_getoutput˜   s
    z!SubProcessTestCase.test_getoutputc                 C   s    t dt ƒ}|  | ¡ d¡ d S )Nz%s -c "print (1)"Ú1©r   r'   r)   ÚstriprD   r   r   r   Útest_getoutput_quoted    s    z(SubProcessTestCase.test_getoutput_quotedc                 C   s<   t dt ƒ}|  | ¡ d¡ t dt ƒ}|  | ¡ d¡ d S )Nz%s -c 'print (1)'rG   z%s -c 'print ("1")'rH   rD   r   r   r   Útest_getoutput_quoted2¥   s    z)SubProcessTestCase.test_getoutput_quoted2c                 C   s6   t t› d| j› d�ƒ\}}|  |d¡ |  |d¡ d S )Nr%   r&   ú	on stdoutú	on stderr)r   r'   r(   r)   )r"   rE   Úerrr   r   r   Útest_getoutput_error¬   s    z'SubProcessTestCase.test_getoutput_errorc                 C   s~   dt  }t|ƒ\}}}|  |d¡ |  |d¡ |  |d¡ tt › d| j› d�ƒ\}}}|  |d¡ |  |d¡ |  |d¡ d S )	Nz%s -c "import sys; sys.exit(1)"Ú é   r%   r&   rL   rM   r   )r'   r	   r)   r(   )r"   Z
quiet_exitrE   rN   Úcoder   r   r   Útest_get_output_error_code±   s    z-SubProcessTestCase.test_get_output_error_codeN)Ú__name__Ú
__module__Ú__qualname__r$   r,   r-   rA   rB   rF   rJ   ÚdecÚ
skip_win32rK   rO   rS   r   r   r   r   r   [   s   	
r   )'Ú__doc__Úsysr7   Úosr.   Ú_threadr   r3   r   ZIPython.utils.processr   r   r   r   r   r   r	   ZIPython.utils.capturer
   ZIPython.testingr   rW   r   Úttr   ÚbasenameÚ
executabler'   rX   r   Zskip_if_not_win32r   r   ÚmarkZparametrizer   r   ZTempFileMixinr   r   r   r   r   Ú<module>   sL   $



ùþ

üþ	