
    f              
       Z   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j0                  j3                  ej4                        Zej8                  d        Zej<                  d	        Zd
 Z ej8                  ejB                  jE                  dddgfdddgfddgfdddgfg      d               Z#ej<                  ejB                  jE                  dddgfdddgfddgfdddgfg      d               Z$ G d dejJ                        Z&y)z
Tests for platutils.py
    N)interrupt_main)find_cmdFindCmdError	arg_splitsystem	getoutputgetoutputerrorget_output_error_code)capture_output)
decorators)toolsc                  @    t        d      } | j                  d      sJ y)z*Make sure we can find the full path to ls.lsN)r   endswithpaths    [/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/utils/tests/test_process.pytest_find_cmd_lsr   '   s     D>D==    c                  f    t        d      } | j                         j                  d      sJ |        y)zTry to find pythonw on Windows.pythonwzpythonw.exeN)r   lowerr   r   s    r   test_find_cmd_pythonwr   .   s-     ID::<  /55/r   c                  B    t        j                  t        t        d       y)z?Make sure that FindCmdError is raised if we can't find the cmd.asdfasdfN)pytestraisesr   r    r   r   test_find_cmd_failr   5   s    
MM,*5r   zargstr, argvhizhello therehellothereu   hǎllozsomething "with quotes"	somethingz"with quotes"c                 $    t        |       |k(  sJ yz?Ensure that argument lines are correctly split like in a shell.Nr   argstrargvs     r   test_arg_splitr*   :   s     V$$$r   zargstr,argvzwith quotesc                 $    t        |       |k(  sJ yr%   r&   r'   s     r   test_arg_split_win32r,   L   s     V$$$r   c                   f    e Zd Zd Zd Zd Zd Zd Zd Zd Z	e
j                  d        Zd	 Zd
 Zy)SubProcessTestCasec                 L    g d}| j                  dj                  |             y)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)mktmpjoin)selfliness     r   setUpzSubProcessTestCase.setUp\   s     '
 	

499U#$r   c                 f    t        t         d| j                   d      }| j                  |d       y )N ""r   )r   pythonfnameassertEqualr3   statuss     r   test_systemzSubProcessTestCase.test_systeme   s-    6("TZZL23#r   c                 L    t        dt        z        }| j                  |d       y )Nz%s -c "import sys"r   )r   r9   r;   r<   s     r   test_system_quotesz%SubProcessTestCase.test_system_quotesi   s"    ,v56#r   c                    t        j                         t        j                         k7  rt        j                  d      t        j
                  t
        j                  t
        j                         d }t        j                  |      j                          t        j                         }	  |       }t        j                         }| j                  ||z
  dk  d||z
  z         S # t        $ r Y ?w xY w)z8
        Interrupt a subprocess after a second.
        z*Can't run this test if not in main thread.c                  B    t        j                  d       t                y )Ng      ?)timesleepr   r   r   r   	interruptz7SubProcessTestCase.assert_interrupts.<locals>.interrupty   s    JJsOr   )target   zProcess didn't die quickly: %s)	threadingmain_threadcurrent_threadr   skipsignalSIGINTdefault_int_handlerThreadstartrC   KeyboardInterrupt
assertTrue)r3   commandrE   rP   resultends         r   assert_interruptsz$SubProcessTestCase.assert_interruptsm   s       "i&>&>&@@++JKK
 	fmmV%?%?@	
 		*002			YF iik%K!O=uM	
  ! 		s   -C( (	C43C4c                 X    d }| j                  |      }| j                  |dd|        y)zr
        When interrupted in the way ipykernel interrupts IPython, the
        subprocess is interrupted.
        c                  &    t        dt        z        S )Nz"%s -c "import time; time.sleep(5)")r   r9   r   r   r   rS   z9SubProcessTestCase.test_system_interrupt.<locals>.command   s    >GHHr   r   z(The process wasn't interrupted. Status: N)rV   assertNotEqual)r3   rS   r=   s      r   test_system_interruptz(SubProcessTestCase.test_system_interrupt   s7    
	I ''0AA&J	
r   c                     t        t         d| j                   d      }	 | j                  |d       y # t        $ r | j                  |d       Y y w xY w)Nr7   r8   zon stderron stdoutzon stdouton stderr)r   r9   r:   r;   AssertionErrorr3   outs     r   test_getoutputz!SubProcessTestCase.test_getoutput   sS    6("TZZL23	8S"67 	8S"67	8s   4 AAc                 h    t        dt        z        }| j                  |j                         d       y )Nz%s -c "print (1)"1r   r9   r;   stripr]   s     r   test_getoutput_quotedz(SubProcessTestCase.test_getoutput_quoted   s(    +f45c*r   c                     t        dt        z        }| j                  |j                         d       t        dt        z        }| j                  |j                         d       y )Nz%s -c 'print (1)'ra   z%s -c 'print ("1")'rb   r]   s     r   test_getoutput_quoted2z)SubProcessTestCase.test_getoutput_quoted2   sN    +f45c*/&89c*r   c                     t        t         d| j                   d      \  }}| j                  |d       | j                  |d       y )Nr7   r8   	on stdout	on stderr)r	   r9   r:   r;   )r3   r^   errs      r   test_getoutput_errorz'SubProcessTestCase.test_getoutput_error   sA    !VHBtzzl!"<=Sk*k*r   c                 R   dt         z  }t        |      \  }}}| j                  |d       | j                  |d       | j                  |d       t        t          d| j                   d      \  }}}| j                  |d       | j                  |d       | j                  |d       y )	Nz%s -c "import sys; sys.exit(1)"    r7   r8   rh   ri   r   )r9   r
   r;   r:   )r3   
quiet_exitr^   rj   codes        r   test_get_output_error_codez-SubProcessTestCase.test_get_output_error_code   s    6?
.z:S$b!b!q!.&DJJ<q/IJS$k*k*q!r   N)__name__
__module____qualname__r5   r>   r@   rV   rZ   r_   rd   dec
skip_win32rf   rk   rq   r   r   r   r.   r.   [   sG    %$$<
8+
 	^^+ ++
	"r   r.   )'__doc__sysrL   osrC   _threadr   rH   r   IPython.utils.processr   r   r   r   r   r	   r
   IPython.utils.capturer   IPython.testingr   ru   r   ttr   basename
executabler9   rv   r   skip_if_not_win32r   r   markparametrizer*   r,   TempFileMixinr.   r   r   r   <module>r      sj     	  "  : : : 1 - '			#..	)   6 66
 	v	'*+ 
~&	"[/$BC% %
 	v	'*+	~&	"[-$@A	% %
_")) _"r   