o ?Og @sF dZgdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZddlmZeddZiZdd Zed Zed Zed Zed ZedZedZeeBeBeBeBeBZedZedZedZedZedZeeBeBeBeBZ dZ!dZ"ddZ#dqddZ$ddZ%ddZ&drd!d"Z'd#d$Z(Gd%d&d&e Z)d'd(Z*d)d*Z+d+d,Z,Gd-d.d.ej-Z.d/d0Z/Gd1d2d2Z0Gd3d4d4Z1Gd5d6d6Z2Gd7d8d8Z3Gd9d:d:Z4Gd;d<d<Z5Gd=d>d>e6Z7Gd?d@d@e6Z8GdAdBdBe4Z9da:   DdsdEdFZ;dCdddddCdddDe2df dGdHZ< I dtdJdKZ=da>dLdMZ?GdNdOdOe j@ZAGdPdQdQeAZBGdRdSdSe jCZDdudTdUZEGdVdWdWeAZFdCdde2dfdXdYZGdZd[ZHd\d]ZId^d_ZJdvd`daZKdvdbdcZLdwdddeZMGdfdgdgZNeNdhdidjdkdldmZOdndoZPeQdpkre RePdSdS)xzreStructuredText en)!register_optionflagDONT_ACCEPT_TRUE_FOR_1DONT_ACCEPT_BLANKLINENORMALIZE_WHITESPACEELLIPSISSKIPIGNORE_EXCEPTION_DETAILCOMPARISON_FLAGS REPORT_UDIFF REPORT_CDIFF REPORT_NDIFFREPORT_ONLY_FIRST_FAILUREREPORTING_FLAGS FAIL_FASTExampleDocTest DocTestParser DocTestFinder DocTestRunner OutputCheckerDocTestFailureUnexpectedException DebugRunnertestmodtestfilerun_docstring_examples DocTestSuite DocFileSuiteset_unittest_reportflagsscript_from_examples testsource debug_srcdebugN)StringIOIncrementalNewlineDecoder) namedtuple TestResultszfailed attemptedcCst|dtt>S)N)OPTIONFLAGS_BY_NAME setdefaultlennamer-./opt/alt/python310/lib64/python3.10/doctest.pyrsrrrrrrrr r r r rz z...cCs: d}tjD]}||d}|tt|ur||jO}q|S)Nr") __future__Zall_feature_namesgetgetattrZ compiler_flag)globsflagsZfnameZfeaturer-r-r._extract_future_flagss   r4cCsT t|r|St|trt|ttdgS|dur&tjt |j dSt d)N*__name__z"Expected a module, string, or None) inspectismodule isinstancestr __import__globalslocalssysmodules _getframe f_globals TypeError)moduleZdepthr-r-r._normalize_modules  rEcCstdd|dSNT)r$decode)datar-r-r._newline_convertsrIcCs|r;t|d}t||}t|dd}dur&z|jj}Wn ty%Ynwt|dr;||}||}t ||fSt ||d}| |fWdS1sRwYdS)N __loader__get_data)encoding) rE_module_relative_pathr1__spec__loaderAttributeErrorhasattrrLrGrIopenread)filenamepackagemodule_relativerMrPZ file_contentsfr-r-r._load_testfiles          $rYcCs td|d|S)Nz (?m)^(?!$) )resub)sindentr-r-r._indentsr`cCs, t}|\}}}tj||||d|S)N)file)r# tracebackprint_exceptiongetvalue)exc_infoZexcoutexc_typeZexc_valZexc_tbr-r-r._exception_tracebacks  rgc@seZdZddZdddZdS) _SpoofOutcCs$t|}|r|ds|d7}|SN )r#rdendswith)selfresultr-r-r.rds z_SpoofOut.getvalueNcCs||t|dSN)seekr#truncate)rlsizer-r-r.rp s z_SpoofOut.truncatern)r7 __module__ __qualname__rdrpr-r-r-r.rhs rhcCs t|vr ||kS|t}dt|}}|d}|r*||r(t|}|d=ndS|d}|rA||r?|t|8}|d=ndS||krGdS|D]}||||}|dkrYdS|t|7}qIdS)Nr"FT)ELLIPSIS_MARKERsplitr* startswithrkfind)wantgotZwsZstartposendposwr-r-r._ellipsis_matchs2    r}cCs |}|r d|SdS)Nz# #)rstrip)liner-r-r. _comment_line@s rcCshdt|}}|d}|dkr|}|dd|}|dkr|}|dd|}|dkr.|d}|||S)Nr"rj:.r')r*rxrfind)msgstartendir-r-r._strip_exception_detailsHs  rc@s0eZdZ ddZd ddZddZdd ZdS) _OutputRedirectingPdbcCs(||_d|_tjj||ddd|_dS)NFT)stdoutnosigintr')_OutputRedirectingPdb__out$_OutputRedirectingPdb__debugger_usedpdbPdb__init__Z use_rawinput)rloutr-r-r.rhs z_OutputRedirectingPdb.__init__NcCs*d|_|dur tj}tj||dSrF)rr?rAf_backrr set_trace)rlframer-r-r.rps z_OutputRedirectingPdb.set_tracecCs|jr tj|dSdSrn)rrr set_continuerlr-r-r.rvsz"_OutputRedirectingPdb.set_continuecGs4tj}|jt_ztjj|g|RW|t_S|t_wrn)r?rrrrtrace_dispatch)rlargs save_stdoutr-r-r.r|s z$_OutputRedirectingPdb.trace_dispatchrn)r7rrrsrrrrr-r-r-r.rbs   rcCst|s td||drtdtjj|d}t |dr,tj|j d}nF|j dkrOt t jdkrKt jddkrKtjt jdd}n'tj}n#t |drk|jD]}tj||}tj|rj|SqWtd |j tj||S) NzExpected a module: %r/z1Module-relative files may not have absolute paths__file__r"__main____path__zBCan't resolve paths relative to the module %r (it has no __file__))r8r9rCrw ValueErrorospathjoinrvrRrr7r*r?argvcurdirrexists)rDZ test_pathZbasedirZ directoryfullpathr-r-r.rNs*        rNc@s,eZdZ  d ddZddZddZdS) rNr"cCsv|ds |d7}|r|ds|d7}|dur!|ds!|d7}||_||_||_||_|dur3i}||_||_dSri)rksourcerylinenor_optionsexc_msg)rlrryrrr_rr-r-r.rs   zExample.__init__cC\t|t|ur tS|j|jko-|j|jko-|j|jko-|j|jko-|j|jko-|j|jkSrn)typeNotImplementedrryrr_rrrlotherr-r-r.__eq__      zExample.__eq__cCst|j|j|j|j|jfSrn)hashrryrr_rrr-r-r.__hash__szExample.__hash__)Nr"r"N)r7rrrsrrrr-r-r-r.rs"  rc@s6eZdZ ddZddZddZddZd d Zd S) rcCs. ||_||_||_||_||_||_dSrn)examples docstringcopyr2r,rUr)rlrr2r,rUrrr-r-r.rs  zDocTest.__init__cCsRt|jdkr d}nt|jdkrd}ndt|j}d|jj|j|j|j|fS)Nr"z no examplesr'z 1 examplez %d examplesz<%s %s from %s:%s (%s)>)r*r __class__r7r,rUr)rlrr-r-r.__repr__szDocTest.__repr__cCrrn)rrrrr2r,rUrrr-r-r.r*rzDocTest.__eq__cCt|j|j|j|jfSrn)rrr,rUrrr-r-r.r5szDocTest.__hash__cCs:t|tstS|j|j|jt|f|j|j|jt|fkSrn)r:rrr,rUridrr-r-r.__lt__9s zDocTest.__lt__N)r7rrrsrrrrrr-r-r-r.rs  rc@seZdZ edejejBZedejejBejBZ edj Z dddZ ddZ dd d Zd d Zed ejZddZedejZddZddZddZdS)ra # Source consists of a PS1 line followed by zero or more PS2 lines. (?P (?:^(?P [ ]*) >>> .*) # PS1 line (?:\n [ ]* \.\.\. .*)*) # PS2 lines \n? # Want consists of any non-blank lines that do not start with PS1. (?P (?:(?![ ]*$) # Not a blank line (?![ ]*>>>) # Not a line starting with PS1 .+$\n? # But any other line )*) a # Grab the traceback header. Different versions of Python have # said different things on the first traceback line. ^(?P Traceback\ \( (?: most\ recent\ call\ last | innermost\ last ) \) : ) \s* $ # toss trailing whitespace on the header. (?P .*?) # don't blink: absorb stuff until... ^ (?P \w+ .*) # a line *starts* with alphanum. z ^[ ]*(#.*)?$c s |}||dkrdfdd|dD}g}d\}}|j|D]M}||||||d||7}| |||\}}} } | |se|t || | |t | d|d||d||7}|}q)|||d|S)Nr"rjcg|]}|dqSrnr-.0lZ min_indentr-r. z'DocTestParser.parse..r"r"r_)rr_r) expandtabs _min_indentrrv _EXAMPLE_REfinditerappendrcount_parse_example_IS_BLANK_OR_COMMENTrr*groupr) rlstringr,outputZcharnormrrryrr-rr.parsets,     zDocTestParser.parsecCs t||||||||Srn)r get_examples)rlrr2r,rUrr-r-r. get_doctestszDocTestParser.get_doctestcCs dd|||DS)NcSsg|] }t|tr|qSr-)r:r)rxr-r-r.rs z.DocTestParser.get_examples..)r)rlrr,r-r-r.rs zDocTestParser.get_examplesc s  t|d|dd}||||||dddd||dfdd|D}|d }|d}t|dkrOtd |d rO|d =||d||t|dfd d|D}|j|}|rw|d }nd}| |||} || ||fS)Nr_rrjr'r[rcsg|] }|ddqS)rZNr-)rZslr_r-r.rsz0DocTestParser._parse_example..ryz *$rtcrrnr-)rZwlrr-r.rrr) r*rrv_check_prompt_blank _check_prefixrr\match _EXCEPTION_RE _find_options) rlrr,r source_linesrry want_linesrrr-rr.rs(        zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c Cs i}|j|D];}|ddd}|D]+}|ddvs(|ddtvr3td|d||ft|dd}|ddk||<qq |rU||rUtd|||f|S) Nr',r[r"z+-z7line %r of the doctest for %s has an invalid option: %r+zSline %r of the doctest for %s has an option directive on a line with no example: %r)_OPTION_DIRECTIVE_RErrreplacervr(rr) rlrr,rrrZoption_stringsoptionflagr-r-r.rs$  zDocTestParser._find_optionsz ^([ ]*)(?=\S)cCs0 dd|j|D}t|dkrt|SdS)NcSg|]}t|qSr-)r*)rr_r-r-r.r z-DocTestParser._min_indent..r") _INDENT_REfindallr*min)rlr^indentsr-r-r.r s  zDocTestParser._min_indentc Cs` t|D](\}}t||dkr-||ddkr-td||d||||d|fqdS)NrZrJr[z8line %r of the docstring for %s lacks blank after %s: %rr') enumerater*r)rllinesr_r,rrrr-r-r.rs  z!DocTestParser._check_prompt_blankcCs@ t|D]\}}|r||std||d||fqdS)NzGline %r of the docstring for %s has inconsistent leading whitespace: %rr')rrwr)rlrprefixr,rrrr-r-r.rszDocTestParser._check_prefixN)r)r7rrrsr\compile MULTILINEVERBOSErDOTALLrrrrrrrrrrrrrr-r-r-r.rDs*    ' 3 rc@sTeZdZ deddfddZdddZdd Zd d Zd d ZddZ ddZ dS)rFTcCs ||_||_||_||_dSrn)_parser_verbose_recurse_exclude_empty)rlverboseparserrecurse exclude_emptyr-r-r.r8s  zDocTestFinder.__init__Nc CsJ |durt|dd}|durtdt|f|durd}n |dur(t|}zt|}Wn ty:d}Yn2w|sPt|}|d|dddksPd}|durWd}n|durct ||j }nt |}|sld}|dur}|durwi}n |j }n| }|dur| |d|vrd|d<g}| ||||||i||S)Nr7zJDocTestFinder.find: name must be given when obj.__name__ doesn't exist: %rFr"z<]>r)r1rrr8 getmoduleZ getsourcefilerCZgetfile linecachegetlines__dict__rupdate_findsort) rlobjr,rDr2 extraglobsrartestsr-r-r.rxNsN#       zDocTestFinder.findcCs |durdSt|dur|t|uSt|r |j|juSt|r?t|dr/|jj}n t|dr8|j}ndS|j |kSt |rJ|j |jkSt|drU|j |jkSt |t r\dSt d)NT __objclass__rrz"object must be a class or function)r8r isfunctionr __globals__ZismethoddescriptorrRrrrr7isclassr:propertyr)rlrDobjectZobj_modr-r-r. _from_modules*            zDocTestFinder._from_modulecCs2 |}zt|}Wn tyYnwt|Srn)r8Zunwrapr isroutine)rlrZ maybe_routiner-r-r. _is_routines  zDocTestFinder._is_routinec Cs |jr td|t||vrdSd|t|<||||||}|dur*||t|r]|jr]|j D]%\} } d|| f} | | sKt | r\| || r\| || | ||||q7t|r|jrt|di D]@\} } t| tstdt| ft| st | st| st| tstdt| fd|| f} | || | ||||qmt |r|jr|j D]8\} } t| ttfr| j} t| st | st| tr| || rd|| f} | || | ||||qdSdSdS)NzFinding tests in %sr'z%s.%s__test__z5DocTestFinder.find: __test__ keys must be strings: %rz`DocTestFinder.find: __test__ values must be strings, functions, methods, classes, or modules: %rz%s.__test__.%s)rprintr _get_testrr8r9rritemsr rr rr1r:r;rrr  staticmethod classmethod__func__r) rlrrr,rDrr2seentestZvalnamevalr-r-r.rsj          zDocTestFinder._findc Cs t|tr |}n$z|jdurd}n |j}t|tst|}Wn ttfy,d}Ynw|||}|jr:|s:dS|durAd}nt|ddpI|j}|dddkrX|dd}|j |||||S)Nrr.pycrt) r:r;__doc__rCrQ _find_linenorr1r7rr) rlrr,rDr2rrrrUr-r-r.rs0       zDocTestFinder._get_testcCs6 d}t|dd}t|r|durd}t|r@|dur@|dur#dStdt|dd}t|D] \}}||r?|}nq2t|rH|j }t |rVt|ddrV|j }t |r^|j }t|rf|j}t|rst|ddd}|dur|dur|dStd}t|t|D] }|||r|SqdS) Nrr"z^\s*class\s*%s\br7-co_firstlinenor'z(^|.*:)\s*\w*("|\'))r1r8r9rr\rrrZismethodrr__code__Z istracebacktb_frameZisframef_codeZiscoderanger*)rlrrrrZpatrrr-r-r.r>s@     zDocTestFinder._find_linenoNNNN) r7rrrsrrrxr r rrrr-r-r-r.r/s f = &rc@seZdZ dZdddZddZdd Zd d Zd d ZddZ ddZ ddZ e dZdddZd ddZdddZddZdS)!rzF**********************************************************************Nr"cCsP |pt|_|durdtjv}||_||_||_d|_d|_i|_ t |_ dS)N-vr") r_checkerr?rr optionflagsoriginal_optionflagstriesfailures_name2ftrh_fakeout)rlcheckerrr$r-r-r.rs   zDocTestRunner.__init__cCsP |jr&|jr|dt|jdt|jdS|dt|jddSdS)NzTrying: z Expecting: zExpecting nothing )rryr`r)rlrrexampler-r-r. report_starts  zDocTestRunner.report_startcCs |jr |ddSdS)Nzok )rrlrrr+rzr-r-r.report_successs zDocTestRunner.report_successcCs( |||||j|||jdSrn)_failure_headerr#output_differencer$r-r-r-r.report_failures  zDocTestRunner.report_failurecCs& ||||dtt|dS)NzException raised: )r/r`rgrlrrr+rer-r-r.report_unexpected_exceptions    z)DocTestRunner.report_unexpected_exceptioncCs|jg}|jr)|jdur|jdur|j|jd}nd}|d|j||jfn |d|jd|jf|d|j}|t|d|S)Nr'?zFile "%s", line %s, in %szLine %s, in %szFailed example:rj)DIVIDERrUrrr,rr`r)rlrr+rrrr-r-r.r/s   zDocTestRunner._failure_headerc Csj d}}|j}td\}}} |jj} t|jD] \} } |jt@o%|dk} ||_| jrH| jD]\}}|r?|j|O_q1|j|M_q1|jt @rNq|d7}| s[| ||| d|j | f}zt t | j|d|d|j|jd}Wntyt}|jY|j}|jd|}|dur| | j||jr|}n9tj|ddd}| s|t|7}| jdur| }n| | j||jr|}n|jt@r| t| jt||jr|}||ur| s|||| |n)||ur| s| ||| ||d7}n|| ur| s|!||| ||d7}|r%|jt"@r%nq||_|#|||t$||S) Nr"rJr'zZsingleTr5rt)%r$r r# check_outputrrr rrrr,r,execrrr2debuggerrKeyboardInterruptr?rer)rdrpryrbformat_exception_onlyrgrrrr.r1r3r_DocTestRunner__record_outcomer&)rlr compileflagsrr'r&r%SUCCESSFAILUREZBOOMZcheck examplenumr+quietZ optionflagrrUZ exceptionrzZoutcomerr-r-r.Z__run s                  zDocTestRunner.__runcCsN |j|jd\}}||||f|j|j<|j|7_|j|7_dS)Nr)r(r0r,r'r&)rlrrXtf2t2r-r-r.Z__record_outcomes zDocTestRunner.__record_outcomez..+)\[(?P\d+)\]>$cCsR|j|}|r#|d|jjkr#|jjt|d}|jjddS| ||S)Nr,r?Tkeepends) %_DocTestRunner__LINECACHE_FILENAME_RErrrr,rintr splitlinessave_linecache_getlines)rlrUmodule_globalsrr+r-r-r.Z__patched_linecache_getliness  z*DocTestRunner.__patched_linecache_getlinesTc s@ ||_|dur t|j}tj|dur,jdus!dkr%j}nfdd}|jt_t }t j }t |_ |j |j j t _ tj|_|jt_tj}tjt_z)||||Wt_|t _ t||jt_|t_|r~|jddl}d|_SSt_|t _ t||jt_|t_|r|jddl}d|_w)Nutf-8cs t|d}|dS)Nbackslashreplace)r;encodewrite)r^rMrr-r.rszDocTestRunner.run..outr")rr4r2r?rrMlowerrNr)gettracerrrr8resetrrrI*_DocTestRunner__patched_linecache_getlines displayhook__displayhook___DocTestRunner__runsettraceclearbuiltins_) rlrr<r clear_globsZ save_traceZsave_set_traceZsave_displayhookrYr-rOr.runsR        zDocTestRunner.runc Cs |dur|j}g}g}g}d}}|jD]+}|\}\} } || 7}|| 7}| dkr1||q| dkr=||| fq||q|rx|r\tt|d||D]} td| qT|rxtt|d||D] \} } td| | fqk|rt|jtt|d||D]\} \} } td| | | fq|rt|dt|jd t||d |d |rtd |d n|rtdt||S)Nr"zitems had no tests:z zitems passed all tests:z %3d tests in %szitems had failures:z %3d of %3d in %sztests inzitems.z passed andzfailed.z***Test Failed***z failures.z Test passed.) rr(rrrr*rr5r&) rlrZnotestsZpassedZfailedZtotaltZtotalfrr,rXrAthingrr-r-r. summarizesR        zDocTestRunner.summarizecCsR|j}|jD]\}\}}||vr ||\}}||}||}||f||<qdSrn)r(r)rlrdr,rXrArBrCr-r-r.merge!s zDocTestRunner.merge)NNr"rnNNT)r7rrrsr5rr,r.r1r3r/rVr;r\rrFrSr\r^r`r-r-r-r.rvs 9 $ }   I 9rc@s.eZdZ ddZddZddZddZd S) rcCs t|dddS)NASCIIrL)r;rM)rlr^r-r-r._toAscii6szOutputChecker._toAsciicCs ||}||}||krdS|t@s%||fdkrdS||fdkr%dS|t@sBtdttd|}tdd|}||krBdS|t@rZd| }d| }||krZdS|t @ret ||redSdS) NT)zTrue z1 )zFalse z0 z (?m)^%s\s*?$rz(?m)^[^\S\n]+$r[F) rcrrr\r]escapeBLANKLINE_MARKERrrrvrr}rlryrzr$r-r-r.r6<s4     zOutputChecker.check_outputcCs<|ttBtB@s dS|t@rdS|ddko|ddkS)NFTrjr5)r r r rrfr-r-r._do_a_fancy_diff{s zOutputChecker._do_a_fancy_diffc Cs  |j}|t@stdt|}||||rp|jdd}|jdd}|t@r9tj ||dd}t |dd}d}n,|t @rPtj ||dd}t |dd}d}n|t @retjtjd} t | ||}d }d |td |S|r~|r~d t|t|fS|rd t|S|rdt|SdS)Nz(?m)^[ ]*(?= )TrDr5)nz#unified diff with -expected +actualz-context diff with expected followed by actual)Zcharjunkzndiff with -expected +actualzDifferences (%s): rzExpected: %sGot: %szExpected: %sGot nothing zExpected nothing Got: %szExpected nothing Got nothing )ryrr\r]rergrHr difflibZ unified_difflistr Z context_diffr ZDifferZIS_CHARACTER_JUNKZcomparer`r) rlr+rzr$ryrZ got_linesZdiffkindZenginer-r-r.r0s6    zOutputChecker.output_differenceN)r7rrrsrcr6rgr0r-r-r-r.r.s ? rc@eZdZ ddZddZdS)rcC||_||_||_dSrn)rr+rz)rlrr+rzr-r-r.r zDocTestFailure.__init__cC t|jSrnr;rrr-r-r.__str__ zDocTestFailure.__str__Nr7rrrsrrqr-r-r-r.r rc@rl)rcCrmrn)rr+re)rlrr+rer-r-r.rrnzUnexpectedException.__init__cCrornrprr-r-r.rqrrzUnexpectedException.__str__Nrsr-r-r-r.rrtrc@s(eZdZ d ddZddZddZdS) rNTcCs$t||||d}|r|j|S)NF)rr\r2rX)rlrr<rr[rr-r-r.r\As zDebugRunner.runcC t|||rn)rr2r-r-r.r3G z'DebugRunner.report_unexpected_exceptioncCrvrn)rr-r-r-r.r1JrwzDebugRunner.report_failurera)r7rrrsr\r3r1r-r-r-r.rs  Z rTFc Cs |dur tjd}t|std|f|dur|j}t|d} |r,t||d} nt ||d} | j ||||dD]} | | q;|rI| t durP| a nt | t| j| jS)Nrztestmod: module required; %r)rrr$r2r)r?r@r0r8r9rCr7rrrrxr\r^masterr`r&r'r&) rr,r2rreportr$rraise_on_errorrfinderrunnerrr-r-r.rVs&B      rc Cs |r |s tdt|||| pd\} }|durtj|}|dur%i}n|}|dur2||d|vr:d|d<| rCt||d} nt||d} | | |||d}| ||r]| t durd| a nt | t| j| jS)N8Package may only be specified for module-relative paths.rKr7rrxr")rrYrrbasenamerrrrrr\r^rzr`r&r'r&)rUrWr,rVr2rr{r$rr|rrMtextr~rr-r-r.rs4N     rNoNamec CsB t|dd}t||d}|j|||dD] }|j||dqdS)NF)rrrx)r2)r<)rrrxr\) rXr2rr,r<r$r}r~rr-r-r.r9s   rcCs$ |t@|kr td|t}|a|S)NzOnly reporting flags allowed)r r_unittest_reportflags)r3oldr-r-r.rVs   rc@speZdZ  dddZddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ e jZddZdS) DocTestCaser"NcCs:tj|||_||_|j|_||_||_ ||_ dSrn) unittestTestCaser_dt_optionflags _dt_checkerr2r _dt_globs_dt_test _dt_setUp _dt_tearDown)rlrr$setUptearDownr*r-r-r.r|s   zDocTestCase.__init__cCs"|j}|jdur||dSdSrn)rrrlrr-r-r.rs zDocTestCase.setUpcCs6|j}|jdur |||j|j|jdSrn)rrr2rXrrrr-r-r.rs    zDocTestCase.tearDowncCs|j}tj}t}|j}|t@s|tO}t||jdd}zd|_ |j ||j dd\}}W|t_n|t_w|r@| | |dS)NFr$r*rzF----------------------------------------------------------------------)rr[)rr?rr#rr rrrr5r\rNZfailureExceptionformat_failurerd)rlrrnewr$r~r'r&r-r-r.runTests$ zDocTestCase.runTestcCsP|j}|jdur d}nd|j}d|jddd}d|j|j|||fS)Nzunknown line numberz%srrtz:Failed doctest test for %s File "%s", line %s, in %s %s)rrrr,rvrU)rlerrrrZlnamer-r-r.rs  zDocTestCase.format_failurecCs8 |t|j|jdd}|j|jdd|dS)NFr)r[)rrrrr\rr)rlr~r-r-r.r!sA zDocTestCase.debugcC|jjSrnrr,rr-r-r.r zDocTestCase.idcCsPt|t|ur tS|j|jko'|j|jko'|j|jko'|j|jko'|j|jkSrn)rrrrrrrrr-r-r.r s     zDocTestCase.__eq__cCrrn)rrrrrrr-r-r.r szDocTestCase.__hash__cCs,|jjd}d|dd|ddfS)Nrz%s (%s)rt)rr,rvr)rlr,r-r-r.r szDocTestCase.__repr__cCs d|jjS)Nz Doctest: rrr-r-r.shortDescription rwzDocTestCase.shortDescription)r"NNN)r7rrrsrrrrrr!rrrrr rqrr-r-r-r.rzs    H  rc@s0eZdZddZddZddZddZeZd S) SkipDocTestCasecCs||_t|ddSrn)rDrr)rlrDr-r-r.r szSkipDocTestCase.__init__cCs|ddS)Nz-DocTestSuite will not work with -O2 and above)ZskipTestrr-r-r.r" szSkipDocTestCase.setUpcCdSrnr-rr-r-r. test_skip% zSkipDocTestCase.test_skipcCs d|jjS)NzSkipping tests from %s)rDr7rr-r-r.r( rwz SkipDocTestCase.shortDescriptionN)r7rrrsrrrrrqr-r-r-r.r s rc@seZdZddZdS) _DocTestSuitecCrrnr-)rlindexr-r-r._removeTestAtIndex0 rz _DocTestSuite._removeTestAtIndexN)r7rrrsrr-r-r-r.r. s rc Ks |durt}t|}|j|||d}|s(tjjdkr(t}|t||S| t}|D],}t |j dkr;q1|j sR|j }|dddkrO|dd}||_ |t|fi|q1|S)Nryr5r"rrrt)rrErxr?r3optimizeraddTestrrr*rrUrr) rDr2rZ test_finderrrsuiterrUr-r-r.r4 s*# rc@s$eZdZddZddZddZdS) DocFileCasecCsd|jjdS)NrZr)rrr,rvrr-r-r.rv szDocFileCase.idcCrrn)rrUrr-r-r.ry rzDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s File "%s", line 0 %s)rr,rU)rlrr-r-r.r| szDocFileCase.format_failureN)r7rrrsrrrr-r-r-r.rt s rc Ksz|duri}n|}|r|stdt||||pd\}}d|vr&||d<tj|}|||||d} t| fi|S)NrrKrr")rrrYrrrrr) rrWrVr2rrMrdocr,rr-r-r. DocFileTest s rcOsJ t}|ddrt|d|d<|D] }|t|fi|q|S)NrWTrV)rr0rErr)pathskwrrr-r-r.r s7 rcCs g}t|D]<}t|tr5||jdd|j}|r4|d|dd|dddD7}q |dd|dddD7}q |rZ|ddkrZ||rZ|ddksN|ro|ddkro|d|ro|ddksbd |dS) Nrtz # Expected:cSsg|]}d|qS)z## r-rr-r-r.r' rz(script_from_examples..rjcSrr-)rrr-r-r.r* s r~r") rrr:rrrryrvpopr)r^rZpieceryr-r-r.r s(9     rcsL t|}t|}fdd|D}|std|d}t|j}|S)Ncsg|] }|jkr|qSr-r+)rrAr+r-r.r? sztestsource..znot found in testsr")rErrxrrr)rDr,rrtestsrcr-r+r.r6 s   rcCs t|}t|||dSrn)r debug_script)srcpmr2rr-r-r.r F sr cCs ddl}|r |}ni}|r>> x = 1; y = 2 >>> x + y, x * y (3, 2) a In 2.2, boolean expressions displayed 0 or 1. By default, we still accept them. This can be disabled by passing DONT_ACCEPT_TRUE_FOR_1 to the new optionflags argument. >>> 4 == 4 1 >>> 4 == 4 True >>> 4 > 4 0 >>> 4 > 4 False z Blank lines can be marked with : >>> print('foo\n\nbar\n') foo bar z If the ellipsis flag is used, then '...' can be used to elide substrings in the desired output: >>> print(list(range(1000))) #doctest: +ELLIPSIS [0, 1, 2, ..., 999] a If the whitespace normalization flag is used, then differences in whitespace are ignored. >>> print(list(range(30))) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] )rrzbool-int equivalencez blank linesZellipsiszwhitespace normalizationc Cs"ddl}|jdd}|jdddddd |jd d d tgd d|jddddd|jdddd|}|j}|j}d}|jD]}|t|O}qA|j rQ|t O}|D];}| drt j |\}}tj d|t|dd} tj d=t| ||d\} } n t|d||d\} } | rdSqSdS)Nr"zdoctest runner) descriptionr"z --verbose store_trueFz'print very verbose output for all tests)actiondefaulthelpz-oz--optionrzqspecify a doctest option flag to apply to the test run; may be specified more than once to apply multiple options)rchoicesrrz-fz --fail-fastzystop running tests after first failure (this is a shorthand for -o FAIL_FAST, and is in addition to any other -o options))rrrarz file containing the tests to run)nargsrz.pyrx)rWrr$r')argparseArgumentParser add_argumentr(keys parse_argsrarrZ fail_fastrrkrrrvr?insertr<rr) rrrZ testfilesrrrrUdirnamerr'rZr-r-r._test sJ       rr)r5)rZ) NNNNTr"NFF)FrNr"r!)FN)F)SZ __docformat____all__r/rir8rrrr\r?rbrior#r$ collectionsr%r&r(rrrrrrrrr r r r rr rerur4rErIrYr`rgrhr}rrrrrNrrrrrr ExceptionrrrrzrrrrrrrrZ TestSuiterrrrrrrr rr!rr rr7exitr-r-r-r.s'-     1%.DKlI;n h { $$ @  IR   , 3 -