}BFj3 .dZddlZddlmZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZd dlmZd dlmZddl m!Z!ddl"m#Z#m$Z$m%Z%m&Z&ej'dkrej(nej)Z*e*de+de,e+de,e+fdZ-de+de%e.e.ffdZ/de/_0de#e+fdZ1defdZ2d4de3de#e+fdZ4d5de+d e$e#e+d!e%e+d"fde%e+e+ffd#Z5 d6de+d%e+d&e+d e$e#e+d!e%e+d"ff d'Z6Gd(d)ej7Z8e Z9e:ej;d$Zd-Z?Gd.d/e>Z@e d0ZAd1ZBd7d2ZCd7d3ZDdS)8zWGeneric testing tools. Authors ------- - Fernando Perez N)Path)contextmanager)StringIO)PopenPIPE)patch)Config)get_output_error_code) list_strings) temp_pyfileTee) py3compat) decorators) skipdoctest) TracebackType)ListOptionalTupleTypewin32 startPathfilesreturnct|tsJtj|dfd|DS)aMake 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'] rcPg|]"}tj|#S)ospathjoin).0fbases CC:\PYTHON\_runtimes\venv\Lib\site-packages\IPython/testing/tools.py zfull_path..Es) 2 2 2aRW\\$q ! ! 2 2 2) isinstancelistrrsplit)rrr#s @r$ full_pathr*(sM6 eT " """ " 7== # #A &D 2 2 2 25 2 2 22r&txtctjd|tj}|r(t|d}d}||fStjd|tj}|r(d}t|d}||fStjd|tj}|rHt|d}t|d}||fSdS)aParse 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+)\)rrz^FAILED \(failures=(\d+)\)z(^FAILED \(errors=(\d+), failures=(\d+)\))rr)research MULTILINEintgroup)r+err_mnerrnfailfail_mboth_ms r$parse_test_outputr8Hs& I13 E EE 5;;q>>""e  Y4c2< H HF FLLOO$$e  YBC|%%F 6<<??##FLLOO$$e  4r&Fc gdS)zEReturn a valid default argv for creating testing instances of ipython)z--quickz--colors=nocolorz--no-term-titlez --no-bannerz --autocall=0rrr&r$ default_argvr:vs   r&ct}d|j_d|j_d|j_t jdd}t|j |j _ | d|j _ |S)z6Return a config object with good defaults for testing.nocolorFrztest_hist.sqliteF)suffixdeletei')r TerminalInteractiveShellcolors TerminalTerminalInteractiveShell term_titleautocalltempfileNamedTemporaryFilernameHistoryManager hist_fileclose db_cache_size)configr"s r$default_configrMsr XXF-6F#*9AF+6/0F#,#+=eLLLA&*16llF#GGIII*/F' Mr& as_stringcRtjddg}|rd|}|S)aW 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-mIPython )sys executabler )rN ipython_cmds r$get_ipython_cmdrUs1>43K,hh{++ r&rfnameoptionscommands.c&d}|g}t|z}tjt}t }tj||}||zd|gz}tj} d| d<| dd| D]*\} } t| tst| | +t|ttt| } | t#jd|pd \} }t#j| t#j|}} | rt)jd d | } | |fS) aUtility 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--ignorePYTHONWARNINGSPYCHARM_HOSTED)stdoutstderrstdinenv )inputz \x1b\[[^h]+h)r:rrdirname__file__rUr environcopypopitemsr'strprintrr communicaterencodedecoder.sub)rVrWrX__tracebackhide__cmdargstest_dirrT full_fnamefull_cmdr`kvpouterrs r$ipexecrzsk.nnw&Gwx((H!##Kh..JW$j'99H *//  C%CGG d### 1!S!!  !QKKK htD#FFFA}}9#3DIIh4G4G#H#H#PD}QQHC$$i&6s&;&;C /f_b#.. 8Or&rc expected_out expected_errc>d}t|||\}}|r|rwd|d|ksJnt d|d|d|d|ksJdS)a9Utility 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 Traz Running file z produced error: N)rzr strip splitlines ValueError)rVr{r|rWrXrprxrys r$ipexec_validaters,4eWh//HC  +  +99SYY[[335566$))""$$//11;;*#eeSS*++ + 99SYY[[++-- . .$))''))33      r&c6eZdZdZd dedefdZdZdZdZd S) TempFileMixinzcUtility class to create temporary Python/IPython files. Meant as a mixin class for test cases..pysrcextct||}t|dsg|_|j|||_dS)zMake a valid python temp file.tmpsN)r hasattrrappendrV)selfrrrVs r$mktmpzTempFileMixin.mktmpsKC%%tV$$ DI  r&cvt|dr&|jD] } tj|#YxYwdSdS)Nr)rrrunlink)rrVs r$tearDownzTempFileMixin.tearDownsc 4   Ie$$$$D    s04c|SNrrs r$ __enter__zTempFileMixin.__enter__&s r&c.|dSr)r)rexc_type exc_value tracebacks r$__exit__zTempFileMixin.__exit__)s r&N)r) __name__ __module__ __qualname____doc__rjrrrrrr&r$rr sr..3   r&rzEDid not find {0!r} in printed output (on {1}): ------- {2!s} ------- creZdZdZddededefdZdZd ee e d ee d ee fd Z d S) AssertPrintszContext manager for testing that code prints certain text. Examples -------- >>> with AssertPrints("abc", suppress=False): ... print("abcd") ... print("def") ... abcd def r]Tschannelsuppressc||_t|jttfr |jg|_||_||_dSr)rr'rj_re_typerr)rrrrs r$__init__zAssertPrints.__init__Cs> dfsHo . . fXDF   r&ctt|j|_t |_t |j|j|_tt|j|j r|jn|jdS)N)r) getattrrRr orig_stream MyStringIObufferr teesetattrrrs r$rzAssertPrints.__enter__Jsb"3 55 ll t{DL999T\$-#M4;;TXNNNNNr&etypevaluerc|d} | |jdS|jtt|j|j|j}|j D]}t|trD| |s.Jt|j|j|[||vs)Jt||j| |jdS#|jwxYwNTF)rrJflushrrRrrrgetvaluerr'rr/notprinted_msgformatpatternrrrrrpprintedrs r$rzAssertPrints.__exit__Ps+    HNN      HNN    Ct'7 8 8 8k**,,GV Y Ya**Y88G,,een.C.CAIt|]d.e.eee,e<<<)>)>q$,PW)X)X<<<< HNN     DHNN    sD C"D D;N)r]T) rrrrrjboolrrrr BaseExceptionrrrr&r$rr7s  !!#!!!!!!OOO htM':;H]D[hpq~hr&rz>Found {0!r} in printed output (on {1}): ------- {2!s} ------- ceZdZdZdZdS)AssertNotPrintszcContext manager for checking that certain output *isn't* produced. Counterpart of AssertPrintscd} |5|j |jdS|jtt|j|j|j}|j D]}t|trD| |r.Jt|j|j|[||vs)Jt||j| |jdS#|jwxYwr)rrJrrrRrrrrrr'rr/ printed_msgrrrs r$rzAssertNotPrints.__exit__msU       HNN      HNN    Ct'7 8 8 8k**,,GV 2 2a**2 xx00::1C1C 4<2:2:::0:G+++[-?-?4<.2.2++++ HNN     DHNN    sD9C"D99EN)rrrrrrr&r$rris-##r&rc#Kt|dd dVtj|dS#tj|wxYw)zGCreate an empty, named, temporary file for the duration of the context.wzutf-8)encodingN)openrJrr)rGs r$ make_tempfilersZ sW%%%++---  $ $s AAcNt|dfd }td|S)aTemporarily 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. rcch tS#t$r}td|d}~wwxYw)NzNo more inputs given)next StopIterationEOFError)prompteits r$ mock_inputzfake_input..mock_inputsC :88O : : :122 9 :s 1,1zbuiltins.inputrc)iterr)inputsrrs @r$ fake_inputrsA fB:::::: !: . ..r&ct|dgz}t|\}}}|dks J|d|vsJd|vsJd|vsJ||fS)z)test that `ipython [subcommand] -h` worksz-hr TracebackOptions --help-allrUr  subcommandcmdrxryrcs r$help_output_testrsy   z40 0C(--LCb 777C777 c ! ! ! !      3     8Or&ct|dgz}t|\}}}|dks J|d|vsJd|vsJd|vsJ||fS)z1test that `ipython [subcommand] --help-all` worksrrrrClassrrs r$help_all_output_testrsu   z<8 8C(--LCb 777C777 c ! ! ! !      c>>>> 8Or&r=)Nr)rcNrr)Errpathlibrr.rRrEunittest contextlibrior subprocessrr unittest.mockrtraitlets.config.loaderr IPython.utils.processr IPython.utils.textr IPython.utils.ior r IPython.utilsrrcrdecrtypesrtypingrrrrplatform skip_doctest null_deco doctest_decorjr(r*r1r8__test__r:rMrrUrzrTestCaserrtypecompilerrrrrrrrrrr&r$rs  %%%%%%""""""""******777777++++++--------######............ ,/<7+B+B{''  33T#Y3493333>'3'5c?''''V# d3i         td3i$77#7c 37E#s(O7[`adfiai[j7777tFHQS,,3,c,,%d3i0,AFsCx,,,,^H%D 4  3  ********X l4///(r&