
    <h2                     @   S r SSKrSSKJ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
Jr  SSKJrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJr  SSKJr  \R@                  S:X  a  \RB                  O\RD                  r#\#S\$S\%\$   S\%\$   4S j5       r&S r'S\'l(        S r)S r*S)S jr+S*S jr,  S+S jr- " S S\R\                  5      r/\r0\1" \Rd                  " S5      5      r3Sr4 " S  S!5      r5S"r6 " S# S$\55      r7\	S% 5       r8S& r9S,S' jr:S,S( jr;g)-zWGeneric testing tools.

Authors
-------
- Fernando Perez <Fernando.Perez@berkeley.edu>
    N)Path)contextmanager)StringIO)PopenPIPE)patch)Config)get_output_error_code)list_strings)temp_pyfileTee)	py3compat   )
decorators)skipdoctestwin32	startPathfilesreturnc                     [        U[        5      (       d   e[        R                  R	                  U 5      S   nU Vs/ s H"  n[        R                  R                  X#5      PM$     sn$ s  snf )a  Make full paths for all the listed files, based on startPath.

Only the base part of startPath is kept, since this routine is typically
used with a script's ``__file__`` variable as startPath. The base of startPath
is then prepended to all the listed files, forming the output list.

Parameters
----------
startPath : string
  Initial path to use as the base for the results.  This path is split
  using os.path.split() and only its first component is kept.

files : list
  One or more files.

Examples
--------

>>> full_path('/foo/bar.py',['a.txt','b.txt'])
['/foo/a.txt', '/foo/b.txt']

>>> full_path('/foo',['a.txt','b.txt'])
['/a.txt', '/b.txt']

r   )
isinstancelistospathsplitjoin)r   r   basefs       hC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\IPython/testing/tools.py	full_pathr    &   sS    6 eT""""77==#A&D+025aRWW\\$!5222s   )A*c                    [         R                  " SU [         R                  5      nU(       a  [        UR	                  S5      5      nSnX#4$ [         R                  " SU [         R                  5      nU(       a  Sn[        UR	                  S5      5      nX#4$ [         R                  " SU [         R                  5      nU(       a7  [        UR	                  S5      5      n[        UR	                  S5      5      nX#4$ g)aK  Parse the output of a test run and return errors, failures.

Parameters
----------
txt : str
  Text output of a test run, assumed to contain a line of one of the
  following forms::

    'FAILED (errors=1)'
    'FAILED (failures=1)'
    'FAILED (errors=1, failures=1)'

Returns
-------
nerr, nfail
  number of errors and failures.
z^FAILED \(errors=(\d+)\)r   r   z^FAILED \(failures=(\d+)\)z(^FAILED \(errors=(\d+), failures=(\d+)\)   )r   r   )research	MULTILINEintgroup)txterr_mnerrnfailfail_mboth_ms         r   parse_test_outputr.   F   s    & II13EE5;;q>"YY4c2<<HFFLLO$YYBC||%F6<<?#FLLO$     Fc                  
    / SQ$ )zEReturn a valid default argv for creating testing instances of ipython)z--quickz--colors=nocolorz--no-term-titlez--no-bannerz--autocall=0 r1   r/   r   default_argvr2   t   s     r/   c                  4   [        5       n SU R                  l        SU R                  l        SU R                  l        [        R                  " SSS9n[        UR                  5      U R                  l        UR                  5         SU R                  l        U $ )z6Return a config object with good defaults for testing.nocolorFr   ztest_hist.sqliteF)suffixdeletei'  )r	   TerminalInteractiveShellcolors TerminalTerminalInteractiveShell
term_titleautocalltempfileNamedTemporaryFiler   nameHistoryManager	hist_fileclosedb_cache_size)configr   s     r   default_configrE      sx    XF-6F##*9AF++6/0F##,##+=eLA&*166lF#GGI*/F'Mr/   c                 \    [         R                  SS/nU (       a  SR                  U5      nU$ )a7  
Return appropriate IPython command line name. By default, this will return
a list that can be used with subprocess.Popen, for example, but passing
`as_string=True` allows for returning the IPython command as a string.

Parameters
----------
as_string: bool
    Flag to allow to return the command as a string.
z-mIPython )sys
executabler   )	as_stringipython_cmds     r   get_ipython_cmdrM      s+     >>43Khh{+r/   c                    SnUc  / n[        5       U-   n[        R                  R                  [        5      n[        5       n[        R                  R                  XP5      nXd-   SU/-   n[        R                  R                  5       n	SU	S'   U	R                  SS5        U	R                  5        H'  u  p[        U[        5      (       a  M  [        X5        M)     [        U[        [        [        U	S9nUR!                  ["        R$                  " SR                  U5      5      =(       d    SS	9u  p["        R&                  " U5      ["        R&                  " U5      pU(       a  [(        R*                  " S
SU5      nX4$ )a  Utility to call 'ipython filename'.

Starts IPython with a minimal and safe configuration to make startup as fast
as possible.

Note that this starts IPython in a subprocess!

Parameters
----------
fname : str, Path
  Name of file to be executed (should have .py or .ipy extension).

options : optional, list
  Extra command-line flags to be passed to IPython.

commands : optional, list
  Commands to send in on stdin

Returns
-------
``(stdout, stderr)`` of ipython subprocess.
TNz--ignorePYTHONWARNINGSPYCHARM_HOSTED)stdoutstderrstdinenv
)inputz\x1b\[[^h]+h )r2   r   r   dirname__file__rM   r   environcopypopitemsr   strprintr   r   communicater   encodedecoder#   sub)fnameoptionscommands__tracebackhide__cmdargstest_dirrL   
full_fnamefull_cmdrU   kvpouterrs                  r   ipexecrr      s.   . nw&Gwwx(H!#Kh.J$j'99H
**//
C %C GGd#		 !S!!!K	 
 	htD#FA}}9#3#3DIIh4G#H#PD}QHC$i&6&6s&; ff_b#.8Or/   rX   c                    Sn[        XU5      u  pgU(       ay  U(       a_  SR                  UR                  5       R                  5       5      SR                  UR                  5       R                  5       5      :X  d   eO[	        SU < SU< 35      eSR                  UR                  5       R                  5       5      SR                  UR                  5       R                  5       5      :X  d   eg)a  Utility to call 'ipython filename' and validate output/error.

This function raises an AssertionError if the validation fails.

Note that this starts IPython in a subprocess!

Parameters
----------
fname : str, Path
  Name of the file to be executed (should have .py or .ipy extension).

expected_out : str
  Expected stdout of the process.

expected_err : optional, str
  Expected stderr of the process.

options : optional, list
  Extra command-line flags to be passed to IPython.

Returns
-------
None
TrV   zRunning file z produced error: N)rr   r   strip
splitlines
ValueError)re   expected_outexpected_errrf   rg   rh   rp   rq   s           r   ipexec_validatery      s    4 eh/HC
 99SYY[3356$))""$//1;    #S* + + 99SYY[++-.$))'')3   r/   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
TempFileMixini	  z_Utility class to create temporary Python/IPython files.

Meant as a mixin class for test cases.c                     [        X5      n[        U S5      (       d  / U l        U R                  R                  U5        X0l        g)zMake a valid python temp file.tmpsN)r   hasattrr}   appendre   )selfsrcextre   s       r   mktmpTempFileMixin.mktmp  s7    C%tV$$DI		
r/   c                     [        U S5      (       a+  U R                   H  n [        R                  " U5        M     g g !    M%  = f)Nr}   )r~   r}   r   unlink)r   re   s     r   tearDownTempFileMixin.tearDown  sA     4  IIe$	 # ! s	   >Ac                     U $ Nr1   r   s    r   	__enter__TempFileMixin.__enter__$  s    r/   c                 $    U R                  5         g r   )r   )r   exc_type	exc_value	tracebacks       r   __exit__TempFileMixin.__exit__'  s    r/   )re   r}   N)z.py)
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__r1   r/   r   r{   r{   	  s    .r/   r{   zEDid not find {0!r} in printed output (on {1}):
-------
{2!s}
-------
c                   .    \ rS rSrSrSS jrS rS rSrg)	AssertPrintsi5  zContext manager for testing that code prints certain text.

Examples
--------
>>> with AssertPrints("abc", suppress=False):
...     print("abcd")
...     print("def")
...
abcd
def
c                     Xl         [        U R                   [        [        45      (       a  U R                   /U l         X l        X0l        g r   )sr   r_   _re_typechannelsuppress)r   r   r   r   s       r   __init__AssertPrints.__init__A  s3    dffsHo..ffXDF r/   c                 4   [        [        U R                  5      U l        [	        5       U l        [        U R
                  U R                  S9U l        [        [        U R                  U R                  (       a  U R
                  5        g U R                  5        g )N)r   )
getattrrI   r   orig_stream
MyStringIObufferr   teesetattrr   r   s    r   r   AssertPrints.__enter__H  sW    "35 lt{{DLL9T\\$--4;;NTXXNr/   c                    Sn Ub   U R                   R                  5         gU R                   R                  5         [        [        U R
                  U R                  5        U R                  R                  5       nU R                   H  n[        U[        5      (       aH  UR                  U5      (       d0   [        R                  UR                  U R
                  U5      5       eM`  Xe;   a  Mg   [        R                  X`R
                  U5      5       e    U R                   R                  5         g! U R                   R                  5         f = fNTF)r   rB   flushr   rI   r   r   r   getvaluer   r   r   r$   notprinted_msgformatpatternr   etypevaluer   rh   printedr   s          r   r   AssertPrints.__exit__N  s     	  HHNN HHNNCt'7'78kk**,GVVa**88G,,en.C.CAIIt||]d.ee,<X)>)>q,,PW)XX<	 
 HHNNDHHNNs   D2 CD2 /'D2 2E)r   r   r   r   r   r   N)rR   T)	r   r   r   r   r   r   r   r   r   r1   r/   r   r   r   5  s    
!Or/   r   z>Found {0!r} in printed output (on {1}):
-------
{2!s}
-------
c                       \ rS rSrSrS rSrg)AssertNotPrintsig  z_Context manager for checking that certain output *isn't* produced.

Counterpart of AssertPrintsc                    Sn Ub6  U R                   R                  5          U R                   R                  5         gU R                   R                  5         [        [        U R
                  U R                  5        U R                  R                  5       nU R                   H  n[        U[        5      (       aH  UR                  U5      (       a0   [        R                  UR                  U R
                  U5      5       eM`  Xe;  a  Mg   [        R                  X`R
                  U5      5       e    U R                   R                  5         g! U R                   R                  5         f = fr   )r   rB   r   r   rI   r   r   r   r   r   r   r   r$   printed_msgr   r   r   s          r   r   AssertNotPrints.__exit__k  s    	   HHNN HHNNCt'7'78kk**,GVVa** xx00 :1C1C		4<<2: :00 + 2[-?-?<<.2 2+  HHNNDHHNNs   E CE 	'E E(r1   N)r   r   r   r   r   r   r   r1   r/   r   r   r   g  s    #r/   r   c              #      #    [        U SSS9R                  5          Sv   [        R                  " U 5        g! [        R                  " U 5        f = f7f)zGCreate an empty, named, temporary file for the duration of the context.wzutf-8)encodingN)openrB   r   r   )r?   s    r   make_tempfiler     s:      	sW%++-
		$		$s   A8 AAAc                 B   ^ [        U 5      mSU4S jjn[        SU5      $ )zTemporarily replace the input() function to return the given values

Use as a context manager:

with fake_input(['result1', 'result2']):
    ...

Values are returned in order. If input() is called again after the last value
was used, EOFError is raised.
c                 X   >  [        T5      $ ! [         a  n[        S5      UeS nAff = f)NzNo more inputs given)nextStopIterationEOFError)prompteits     r   
mock_inputfake_input.<locals>.mock_input  s/    	:8O 	:129	:s   
 
)$)zbuiltins.inputrX   )iterr   )inputsr   r   s     @r   
fake_inputr     s#     
fB: !:..r/   c                     [        5       U S/-   n[        U5      u  p#nUS:X  d   U5       eSU;  d   eSU;   d   eSU;   d   eX#4$ )z)test that `ipython [subcommand] -h` worksz-hr   	TracebackOptions
--help-allrM   r
   
subcommandcmdrp   rq   rcs        r   help_output_testr     sd    

z40
0C(-LCb7C7c!!!38Or/   c                     [        5       U S/-   n[        U5      u  p#nUS:X  d   U5       eSU;  d   eSU;   d   eSU;   d   eX#4$ )z1test that `ipython [subcommand] --help-all` worksr   r   r   r   Classr   r   s        r   help_all_output_testr     sb    

z<8
8C(-LCb7C7c!!!c>>8Or/   r5   )Nr1   )rX   Nr1   r   )<r   r   pathlibr   r#   rI   r=   unittest
contextlibr   ior   
subprocessr   r   unittest.mockr   traitlets.config.loaderr	   IPython.utils.processr
   IPython.utils.textr   IPython.utils.ior   r   IPython.utilsr   rX   r   decr   platformskip_doctest	null_decodoctest_decor_   r   r    r.   __test__r2   rE   rM   rr   ry   TestCaser{   r   typecompiler   r   r   r   r   r   r   r   r   r1   r/   r   <module>r      s4   
  	 
   %  "  * 7 + - #  
 ,/<<7+B{''3 3T#Y 349 3 3>'V #  

$7t 79+-,^H%% D 


3 * *Xl 4  /(r/   