
    ^h              
       Z   S r SSKrSSKrSSKrSSKrSSKJr  SSKrSSKrSSK	J
r
JrJrJrJrJrJr  SSKJr  SSKJr  SSKJr  \R0                  R3                  \R4                  5      r\R8                  S 5       r\R<                  S	 5       rS
 r \R8                  \RB                  RE                  SSS/4SSS/4SS/4SSS/4/5      S 5       5       r#\R<                  \RB                  RE                  SSS/4SSS/4SS/4SSS/4/5      S 5       5       r$ " S S\RJ                  5      r&g)z
Tests for platutils.py
    N)interrupt_main)find_cmdFindCmdError	arg_splitsystem	getoutputgetoutputerrorget_output_error_code)capture_output)
decorators)toolsc                  J    [        S5      n U R                  S5      (       d   eg)z*Make sure we can find the full path to ls.lsN)r   endswithpaths    Z/home/james-whalen/.local/lib/python3.13/site-packages/IPython/utils/tests/test_process.pytest_find_cmd_lsr   '   s"     D>D==    c                  p    [        S5      n U R                  5       R                  S5      (       d   U 5       eg)zTry to find pythonw on Windows.pythonwzpythonw.exeN)r   lowerr   r   s    r   test_find_cmd_pythonwr   .   s0     ID::<  //55/r   c                  D    [         R                  " [        [        S5        g)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                 &    [        U 5      U:X  d   eg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                 &    [        U 5      U:X  d   egr%   r&   r'   s     r   test_arg_split_win32r,   L   s     V$$$r   c                   n    \ rS rSrS rS rS rS rS rS r	S r
\R                  S	 5       rS
 rS rSrg)SubProcessTestCase[   c                 L    / SQnU R                  SR                  U5      5        g)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   setUpSubProcessTestCase.setUp\   s     '
 	

499U#$r   c                 f    [        [         SU R                   S35      nU R                  US5        g )N ""r   )r   pythonfnameassertEqualr4   statuss     r   test_systemSubProcessTestCase.test_systeme   s-    6("TZZL23#r   c                 L    [        S[        -  5      nU R                  US5        g )Nz%s -c "import sys"r   )r   r;   r=   r>   s     r   test_system_quotes%SubProcessTestCase.test_system_quotesi   s"    ,v56#r   c                    [         R                  " 5       [         R                  " 5       :w  a  [        R                  " S5      e[
        R
                  " [
        R                  [
        R                  5        S n[         R                  " US9R                  5         [        R                  " 5       n U" 5       n[        R                  " 5       nU R                  XS-
  S:  SXS-
  -  5        W$ ! [         a     N?f = f)z(
Interrupt a subprocess after a second.
z*Can't run this test if not in main thread.c                  D    [         R                  " S5        [        5         g )Ng      ?)timesleepr   r   r   r   	interrupt7SubProcessTestCase.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startrG   KeyboardInterrupt
assertTrue)r4   commandrI   rU   resultends         r   assert_interrupts$SubProcessTestCase.assert_interruptsm   s       "i&>&>&@@++JKK
 	fmmV%?%?@	
 		*002			YF iikK!O=M	
  ! 		s   1C+ +
C87C8c                 X    S nU R                  U5      nU R                  USSU 35        g)zZ
When interrupted in the way ipykernel interrupts IPython, the
subprocess is interrupted.
c                  &    [        S[        -  5      $ )Nz"%s -c "import time; time.sleep(5)")r   r;   r   r   r   rX   9SubProcessTestCase.test_system_interrupt.<locals>.command   s    >GHHr   r   z(The process wasn't interrupted. Status: N)r[   assertNotEqual)r4   rX   r?   s      r   test_system_interrupt(SubProcessTestCase.test_system_interrupt   s7    
	I ''0AA&J	
r   c                     [        [         SU R                   S35      n U R                  US5        g ! [         a    U R                  US5         g f = f)Nr9   r:   zon stderron stdoutzon stdouton stderr)r   r;   r<   r=   AssertionErrorr4   outs     r   test_getoutput!SubProcessTestCase.test_getoutput   sS    6("TZZL23	8S"67 	8S"67	8s   4 AAc                 h    [        S[        -  5      nU R                  UR                  5       S5        g )Nz%s -c "print (1)"1r   r;   r=   stripre   s     r   test_getoutput_quoted(SubProcessTestCase.test_getoutput_quoted   s(    +f45c*r   c                     [        S[        -  5      nU R                  UR                  5       S5        [        S[        -  5      nU R                  UR                  5       S5        g )Nz%s -c 'print (1)'rj   z%s -c 'print ("1")'rk   re   s     r   test_getoutput_quoted2)SubProcessTestCase.test_getoutput_quoted2   sN    +f45c*/&89c*r   c                     [        [         SU R                   S35      u  pU R                  US5        U R                  US5        g )Nr9   r:   	on stdout	on stderr)r	   r;   r<   r=   )r4   rf   errs      r   test_getoutput_error'SubProcessTestCase.test_getoutput_error   s?    !VHBtzzl!"<=k*k*r   c                 N   S[         -  n[        U5      u  p#nU R                  US5        U R                  US5        U R                  US5        [        [          SU R                   S35      u  p#nU R                  US5        U R                  US5        U R                  US5        g )	Nz%s -c "import sys; sys.exit(1)"    r9   r:   rs   rt   r   )r;   r
   r=   r<   )r4   
quiet_exitrf   ru   codes        r   test_get_output_error_code-SubProcessTestCase.test_get_output_error_code   s    6?
.z:$b!b!q!.&DJJ<q/IJ$k*k*q!r   r   N)__name__
__module____qualname____firstlineno__r6   r@   rC   r[   ra   rg   rm   dec
skip_win32rp   rv   r}   __static_attributes__r   r   r   r.   r.   [   sG    %$$<
8+
 	^^+ ++
	"r   r.   )'__doc__sysrQ   osrG   _threadr   rM   r   IPython.utils.processr   r   r   r   r   r	   r
   IPython.utils.capturer   IPython.testingr   r   r   ttr   basename
executabler;   r   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   