+
    ^|i2                     *   R t ^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHt ^RIHt ^RIHt ]P@                  R8X  d   ]PB                  M]PD                  t#]#R R l4       t$R t%R]%n&        R t'R t(R%R lt)R&R lt*R'R lt+ ! R R]PX                  4      t-]t.]/! ]P`                  ! R4      4      t1Rt2 ! R R4      t3Rt4 ! R R ]34      t5]	R! 4       t6R" t7R(R# lt8R(R$ lt9R# ))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win32c                h    V ^8  d   QhR\         R\        \         ,          R\        \         ,          /# )   	startPathfilesreturn)strlist)formats   "7/usr/lib/python3/dist-packages/IPython/testing/tools.py__annotate__r   '   s)     3 3 3T#Y 349 3    c                    \        V\        4      '       g   Q h\        P                  P	                  V 4      ^ ,          pV Uu. uF"  p\        P                  P                  W#4      NK$  	  up# u upi )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']

)
isinstancer   ospathsplitjoin)r   r   basefs   &&  r   	full_pathr$   &   sS    6 eT""""77==#A&D+025aRWW\\$!5222s   (A.c                   \         P                  ! RV \         P                  4      pV'       d    \        VP	                  ^4      4      p^ pW#3# \         P                  ! RV \         P                  4      pV'       d    ^ p\        VP	                  ^4      4      pW#3# \         P                  ! RV \         P                  4      pV'       d8   \        VP	                  ^4      4      p\        VP	                  ^4      4      pW#3# R# )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+)\)z^FAILED \(failures=(\d+)\)z(^FAILED \(errors=(\d+), failures=(\d+)\))    r&   )research	MULTILINEintgroup)txterr_mnerrnfailfail_mboth_ms   &     r   parse_test_outputr2   F   s    & II13EE5;;q>"YY4c2<<HFFLLO$YYBC||%F6<<?#FLLO$ Kr   Fc                 
    . RO# )zEReturn a valid default argv for creating testing instances of ipython)z--quickz--colors=nocolorz--no-term-titlez--no-bannerz--autocall=0 r4   r   r   default_argvr5   t   s     r   c                 :   \        4       p RV P                  n        RV P                  n        ^ V P                  n        \        P                  ! RRR7      p\        VP                  4      V P                  n        VP                  4        RV P                  n        V # )z6Return a config object with good defaults for testing.nocolorFztest_hist.sqlite)suffixdeletei'  F)r   TerminalInteractiveShellcolors TerminalTerminalInteractiveShell
term_titleautocalltempfileNamedTemporaryFiler   nameHistoryManager	hist_fileclosedb_cache_size)configr#   s     r   default_configrH      sx    XF-6F##*9AF++6/0F##,##+=eLA&*166lF#GGI*/F'Mr   c                ^    \         P                  RR.pV '       d   RP                  V4      pV# )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_cmdrP      s+     >>43Khh{+r   c                &   RpVf   . p\        4       V,           p\        P                  P                  \        4      p\        4       p\        P                  P                  WP4      pWd,           RV.,           p\        P                  P                  4       p	RV	R&   V	P                  RR4       V	P                  4        F(  w  r\        V\        4      '       d   K  \        W4       K*  	  \        V\        \        \        V	R7      pTP!                  \"        P$                  ! RP                  V4      4      ;'       g    RR	7      w  r\"        P&                  ! V4      \"        P&                  ! V4      rV'       d   \(        P*                  ! R
RV4      pW3# )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 )r5   r   r   dirname__file__rP   r!   environcopypopitemsr   r   printr   r   communicater   encodedecoder'   sub)fnameoptionscommands__tracebackhide__cmdargstest_dirrO   
full_fnamefull_cmdrX   kvpouterrs   &&&            r   ipexecrt      s1   . nw&Gwwx(H!#Kh.J$j'99H
**//
C %C GGd#		 !S!!!K	 
 	htD#FA}}9#3#3DIIh4G#H#P#PD}QHC$i&6&6s&; ff_b#.8Or   r[   c                   Rp\        WV4      w  rgV'       d|   V'       da   RP                  VP                  4       P                  4       4      RP                  VP                  4       P                  4       4      8X  g   Q hM\	        RV : RV: 24      hRP                  VP                  4       P                  4       4      RP                  VP                  4       P                  4       4      8X  g   Q hR# )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
TrY   zRunning file z produced error: N)rt   r!   strip
splitlines
ValueError)rg   expected_outexpected_errrh   ri   rj   rr   rs   s   &&&&&   r   ipexec_validater{      s    4 eh/HC
 99SYY[3356$))""$//1;    #S* + + 99SYY[++-.$))'')3   r   c                   @   a  ] tR tRt o RtR	R ltR tR tR tRt	V t
R# )
TempFileMixini	  z_Utility class to create temporary Python/IPython files.

Meant as a mixin class for test cases.c                    \        W4      p\        V R4      '       g   . V n        V P                  P                  V4       W0n        R# )zMake a valid python temp file.tmpsN)r   hasattrr   appendrg   )selfsrcextrg   s   &&& r   mktmpTempFileMixin.mktmp  s7    C%tV$$DI		
r   c                    \        V R 4      '       d-   V P                   F  p \        P                  ! V4       K  	  R# R#     K'  ; i)r   N)r   r   r   unlink)r   rg   s   & r   tearDownTempFileMixin.tearDown  sA     4  IIe$	 # ! s   AAc                    V # Nr4   r   s   &r   	__enter__TempFileMixin.__enter__$  s    r   c                &    V P                  4        R # r   )r   )r   exc_type	exc_value	tracebacks   &&&&r   __exit__TempFileMixin.__exit__'  s    r   )rg   r   N)z.py)__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes____classdictcell____classdict__s   @r   r}   r}   	  s#     . r   r}   zEDid not find {0!r} in printed output (on {1}):
-------
{2!s}
-------
c                   :   a  ] tR tRt o RtRR ltR tR tRtV t	R# )	AssertPrintsi5  zContext manager for testing that code prints certain text.

Examples
--------
>>> with AssertPrints("abc", suppress=False):
...     print("abcd")
...     print("def")
...
abcd
def
c                    Wn         \        V P                   \        \        34      '       d   V P                   .V n         W n        W0n        R # r   )sr   r   _re_typechannelsuppress)r   r   r   r   s   &&&&r   __init__AssertPrints.__init__A  s3    dffsHo..ffXDF r   c                @   \        \        V P                  4      V n        \	        4       V n        \        V P
                  V P                  R 7      V n        \        \        V P                  V P                  '       d   V P
                  4       R# V P                  4       R# ))r   N)
getattrrL   r   orig_stream
MyStringIObufferr   teesetattrr   r   s   &r   r   AssertPrints.__enter__H  sY    "35 lt{{DLL9T\\$---4;;NTXXNr   c                   R p Ve    V P                   P                  4        R# V P                   P                  4        \        \        V P
                  V P                  4       V P                  P                  4       pV P                   F  p\        V\        4      '       dJ   VP                  V4      '       g1   Q \        P                  VP                  V P
                  V4      4       hKb  We9   d   Kj  Q \        P                  W`P
                  V4      4       h	   V P                   P                  4        R#   T P                   P                  4        i ; iTF)r   rE   flushr   rL   r   r   r   getvaluer   r   r   r(   notprinted_msgr   patternr   etypevaluer   rj   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   D8 BD8 :5D8 4'D8 8E)r   r   r   r   r   r   N)rU   T)
r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r   5  s     
!O r   r   z>Found {0!r} in printed output (on {1}):
-------
{2!s}
-------
c                   *   a  ] tR tRt o RtR tRtV tR# )AssertNotPrintsig  z_Context manager for checking that certain output *isn't* produced.

Counterpart of AssertPrintsc                   R p Ve8   V P                   P                  4         V P                   P                  4        R# V P                   P                  4        \        \        V P
                  V P                  4       V P                  P                  4       pV P                   F  p\        V\        4      '       dJ   VP                  V4      '       d1   Q \        P                  VP                  V P
                  V4      4       hKb  We9  d   Kj  Q \        P                  W`P
                  V4      4       h	   V P                   P                  4        R#   T P                   P                  4        i ; ir   )r   rE   r   r   rL   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 BE 5E 'E E.r4   N)r   r   r   r   r   r   r   r   r   s   @r   r   r   g  s     # r   r   c              #     "   \        V RRR7      P                  4         Rx  \        P                  ! V 4       R#   \        P                  ! T 4       i ; i5i)zGCreate an empty, named, temporary file for the duration of the context.wzutf-8)encodingN)openrE   r   r   )rB   s   &r   make_tempfiler     s:      	sW%++-
		$		$s   A< AAAc                B   a \        V 4      oRV3R llp\        RV4      # )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                 Z   <  \        S4      #   \         d   p\        R 4      ThRp?ii ; i)zNo more inputs givenN)nextStopIterationEOFError)prompteits   & r   
mock_inputfake_input.<locals>.mock_input  s/    	:8O 	:129	:s   
 *%*zbuiltins.inputr[   )iterr   )inputsr   r   s   & @r   
fake_inputr     s#     
fB: !:..r   c                    \        4       V R.,           p\        V4      w  r#pV^ 8X  g   Q V4       hRV9  g   Q hRV9   g   Q hRV9   g   Q hW#3# )z)test that `ipython [subcommand] -h` worksz-h	TracebackOptions
--help-allrP   r	   
subcommandcmdrr   rs   rcs   &    r   help_output_testr     sd    

z40
0C(-LCb7C7c!!!38Or   c                    \        4       V R.,           p\        V4      w  r#pV^ 8X  g   Q V4       hRV9  g   Q hRV9   g   Q hRV9   g   Q hW#3# )z1test that `ipython [subcommand] --help-all` worksr   r   r   Classr   r   s   &    r   help_all_output_testr     sb    

z<8
8C(-LCb7C7c!!!c>>8Or   r:   )Nr4   )r[   Nr4   r   ):r   r   pathlibr   r'   rL   r@   unittest
contextlibr   ior   
subprocessr   r   unittest.mockr   traitlets.config.loaderr   IPython.utils.processr	   IPython.utils.textr
   IPython.utils.ior   r   IPython.utilsr   r[   r   decr   platformskip_doctest	null_decodoctest_decor$   r2   __test__r5   rH   rP   rt   r{   TestCaser}   r   typecompiler   r   r   r   r   r   r   r   r   r4   r   r   <module>r      s   
  	 
   %  "  * 7 + - #  
 ,/<<7+B{''3 3>'V #  

$7t,^H%% D 


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