Format: application/x-python-code
⬇ Download File (5.8 KB)
   1  o
   2  
   3  ��h��
   4  @sPdZddlZddlZddlZddlZddlmZddlZddlZddl	m
   5  Z
   6  mZmZm
   7  Z
   8  mZmZmZddlmZddlmZddlmZej�ej�Zejdd	��Zejd
   9  d��Zdd
  10  �Z ejej!�"dddgfdddgfddgfdddgfg�dd���Z#ejej!�"dddgfdddgfddgfdddgfg�dd���Z$Gdd�dej%�Z&dS)z
  11  Tests for platutils.py
  12  �N)�interrupt_main)�find_cmd�FindCmdError�	arg_split�system�	getoutput�getoutputerror�get_output_error_code)�capture_output)�
  13  decorators)�toolscCstd�}|�d�sJ�dS)z*Make sure we can find the full path to ls.ZlsN)r�endswith��path�r�Vc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/tests/test_process.py�test_find_cmd_ls'srcCs"td�}|���d�sJ|��dS)zTry to find pythonw on Windows.�pythonwzpythonw.exeN)r�lowerr
  14  rrrr�test_find_cmd_pythonw.srcCst�ttd�dS)z?Make sure that FindCmdError is raised if we can't find the cmd.ZasdfasdfN)�pytestZraisesrrrrrr�test_find_cmd_fail5srzargstr, argv�hizhello thereZhelloZthereuhǎllozsomething "with quotes"Z	somethingz
  15  "with quotes"cC�t|�|ksJ�dS�z?Ensure that argument lines are correctly split like in a shell.N�r�Zargstr�argvrrr�test_arg_split:srzargstr,argvzwith quotescCrrrrrrr�test_arg_split_win32Lsrc@sbeZdZdd�Zdd�Zdd�Zdd�Zd	d
  16  �Zdd�Zd
  17  d�Z	e
  18  jdd��Zdd�Z
  19  dd�ZdS)�SubProcessTestCasecCsgd�}|�d�|��dS)zMake a valid python temp file.)z
  20  import sysz+print('on stdout', end='', file=sys.stdout)z+print('on stderr', end='', file=sys.stderr)zsys.stdout.flush()zsys.stderr.flush()�
  21  N)Zmktmp�join)�self�linesrrr�setUp\szSubProcessTestCase.setUpcCs&tt�d|j�d��}|�|d�dS)N� "�"r)r�python�fname�assertEqual�r#�statusrrr�test_systemeszSubProcessTestCase.test_systemcCstdt�}|�|d�dS)Nz%s -c "import sys"r)rr(r*r+rrr�test_system_quotesisz%SubProcessTestCase.test_system_quotescCs�t��t��kr
  22  t�d��t�tjtj�dd�}tj|d��	�t
  23  �
  24  �}z|�}Wn	ty3Ynwt
  25  �
  26  �}|�||dkd||�|S)z8
  27          Interrupt a subprocess after a second.
  28          z*Can't run this test if not in main thread.cSst�d�t�dS)Ng�?)�time�sleeprrrrr�	interruptys
  29  
  30  z7SubProcessTestCase.assert_interrupts.<locals>.interrupt)�target�zProcess didn't die quickly: %s)
  31  �	threading�main_thread�current_threadr�skip�signal�SIGINT�default_int_handler�Thread�startr/�KeyboardInterrupt�
  32  assertTrue)r#�commandr1r<�result�endrrr�assert_interruptsms 
  33  
  34  ��z$SubProcessTestCase.assert_interruptscCs*dd�}|�|�}|�|dd|���dS)zr
  35          When interrupted in the way ipykernel interrupts IPython, the
  36          subprocess is interrupted.
  37          cSstdt�S)Nz"%s -c "import time; time.sleep(5)")rr(rrrrr?�sz9SubProcessTestCase.test_system_interrupt.<locals>.commandrz(The process wasn't interrupted. Status: N)rBZassertNotEqual)r#r?r,rrr�test_system_interrupt�s
  38  
  39  �z(SubProcessTestCase.test_system_interruptcCsJtt�d|j�d��}z	|�|d�WdSty$|�|d�YdSw)Nr&r'zon stderron stdoutzon stdouton stderr)rr(r)r*�AssertionError�r#�outrrr�test_getoutput�s�z!SubProcessTestCase.test_getoutputcCs tdt�}|�|��d�dS)Nz%s -c "print (1)"�1�rr(r*�striprErrr�test_getoutput_quoted�sz(SubProcessTestCase.test_getoutput_quotedcCs<tdt�}|�|��d�tdt�}|�|��d�dS)Nz%s -c 'print (1)'rHz%s -c 'print ("1")'rIrErrr�test_getoutput_quoted2�sz)SubProcessTestCase.test_getoutput_quoted2cCs6tt�d|j�d��\}}|�|d�|�|d�dS)Nr&r'�	on stdout�	on stderr)rr(r)r*)r#rF�errrrr�test_getoutput_error�sz'SubProcessTestCase.test_getoutput_errorcCs~dt}t|�\}}}|�|d�|�|d�|�|d�tt�d|j�d��\}}}|�|d�|�|d�|�|d�dS)	Nz%s -c "import sys; sys.exit(1)"��r&r'rMrNr)r(r	r*r))r#Z
  40  quiet_exitrFrO�coderrr�test_get_output_error_code�sz-SubProcessTestCase.test_get_output_error_codeN)�__name__�
  41  __module__�__qualname__r%r-r.rBrCrGrK�dec�
  42  skip_win32rLrPrTrrrrr [s	
  43  
  44  r )'�__doc__�sysr8�osr/�_threadrr4rZIPython.utils.processrrrrrrr	ZIPython.utils.capturer
  45  ZIPython.testingrrXr�ttr�basename�
  46  executabler(rYrZskip_if_not_win32rr�markZparametrizerrZ
  47  TempFileMixinr rrrr�<module>sN$
  48  
  49  
  50  
  51  ��
  52  
  53  ��