3 2aǗ!@spdZddddddddd d d d d ddddddddddddddddddd d!g!Zd"d#lZd"d#lZd"d#lZd"d#lZd"d#lZd"d#lZd"d#lZd"d#l Z d"d#l Z d"d#l Z d"d#l Z d"d$l mZd"d%lmZed&d'ZiZd(dZedZedZedZedZedZedZeeBeBeBeBeBZed Zed Zed Zed ZedZeeBeBeBeBZ d)Z!d*Z"d+d,Z#dpd.d/Z$d0d1Z%dqd3d4Z&d5d6Z'Gd7d8d8eZ(d9d:Z)d;d<Z*d=d>Z+Gd?d@d@ej,Z-dAdBZ.GdCddZ/GdDddZ0GdEddZ1GdFddZ2GdGddZ3GdHddZ4GdIdde5Z6GdJdde5Z7GdKdde3Z8d#a9drdNdZ:dLd#d#d#d#dLd"d#dMe1d#f dOdZ;dsdQdZGdSdTdTe j?Z@GdUdVdVe@ZAGdWdXdXe jBZCdtdYdZDGdZd[d[e@ZEdLd#d#e1d#fd\d]ZFd^dZGd_dZHd`dZIdudad ZJdvdbdcZKdwddd!ZLGdedfdfZMeMdgdhdidjdkdlZNdmdnZOePdokrle jQeOd#S)xzreStructuredText enregister_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)StringIO) namedtuple TestResultszfailed attemptedcCstj|dtt>S)N)OPTIONFLAGS_BY_NAME setdefaultlen)namer+,/opt/alt/python36/lib64/python3.6/doctest.pyrsz z...cCs<d}x2tjD](}|j|d}|tt|kr ||jO}q W|S)Nr") __future__Zall_feature_namesgetgetattrZ compiler_flag)globsflagsZfnameZfeaturer+r+r,_extract_future_flagss   r2cCsVtj|r|St|tr,t|ttdgS|dkrJtjtj |j dSt ddS)N*__name__z"Expected a module, string, or None) inspectismodule isinstancestr __import__globalslocalssysmodules _getframe f_globals TypeError)moduledepthr+r+r,_normalize_modules  rDc Cs|r\t|d}t||}t|dddk r\t|jdr\|jj|}|j|}|jtj d|fSt ||d}|j |fSQRXdS)N __loader__get_data )encoding) rD_module_relative_pathr/hasattrrFrGdecodereplaceoslinesepopenread)filenamepackagemodule_relativerIZ file_contentsfr+r+r,_load_testfiles     rVcCstjd|d|S)Nz (?m)^(?!$) )resub)sindentr+r+r,_indentsr]cCs*t}|\}}}tj||||d|jS)N)file)r# tracebackprint_exceptiongetvalue)exc_infoZexcoutexc_typeZexc_valZexc_tbr+r+r,_exception_tracebacks rdc@seZdZddZdddZdS) _SpoofOutcCs&tj|}|r"|jd r"|d7}|S)NrH)r#raendswith)selfresultr+r+r,ras z_SpoofOut.getvalueNcCs|j|tj|dS)N)seekr#truncate)rgsizer+r+r,rjs z_SpoofOut.truncate)N)r5 __module__ __qualname__rarjr+r+r+r,res recCst|kr||kS|jt}dt|}}|d}|rR|j|rNt|}|d=ndS|d}|r|j|r||t|8}|d=ndS||krdSx2|D]*}|j|||}|dkrdS|t|7}qWdS)Nr"Fr&Trn)ELLIPSIS_MARKERsplitr) startswithrffind)wantgotZwsstartposendposwr+r+r,_ellipsis_matchs0     rxcCs|j}|rd|SdSdS)Nz# #)rstrip)liner+r+r, _comment_line9sr|cCshdt|}}|jd}|dkr$|}|jdd|}|dkr>|}|jdd|}|dkr\|d}|||S)Nr"rH:.r&)r)rrrfind)msgstartendir+r+r,_strip_exception_detailsAs  rc@s.eZdZddZd ddZddZdd ZdS) _OutputRedirectingPdbcCs(||_d|_tjj||ddd|_dS)NFT)stdoutnosigintr&)_OutputRedirectingPdb__out$_OutputRedirectingPdb__debugger_usedpdbPdb__init__Z use_rawinput)rgoutr+r+r,rasz_OutputRedirectingPdb.__init__NcCs*d|_|dkrtjj}tjj||dS)NT)rr=r?f_backrr set_trace)rgframer+r+r,ris z_OutputRedirectingPdb.set_tracecCs|jrtjj|dS)N)rrr set_continue)rgr+r+r,rosz"_OutputRedirectingPdb.set_continuec Gs.tj}|jt_ztjj|f|S|t_XdS)N)r=rrrrtrace_dispatch)rgargs save_stdoutr+r+r,rus z$_OutputRedirectingPdb.trace_dispatch)N)r5rlrmrrrrr+r+r+r,r[s rcCstj|std||jdr(tdtjj|jd}t |drXtjj|j d}n|j dkrt t jdkrt jddkrtjjt jdd}qtj}nFt |drx,|jD]"}tjj||}tjj|r|SqWtd |j tjj||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__))r6r7rArq ValueErrorrNpathjoinrprKrr5r)r=argvcurdirrexists)rBZ test_pathZbasedirZ directoryZfullpathr+r+r,rJs&         rJc@s&eZdZd ddZddZddZdS) rNr"cCsz|jds|d7}|r*|jd r*|d7}|dk rF|jd rF|d7}||_||_||_||_|dkrji}||_||_dS)NrH)rfsourcerslinenor\optionsexc_msg)rgrrsrrr\rr+r+r,rs zExample.__init__cCs\t|t|k rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkS)N)typeNotImplementedrrsrr\rr)rgotherr+r+r,__eq__s     zExample.__eq__cCst|j|j|j|j|jfS)N)hashrrsrr\r)rgr+r+r,__hash__szExample.__hash__)Nr"r"N)r5rlrmrrrr+r+r+r,rs#  c@s4eZdZddZddZddZddZd d Zd S) rcCs,||_||_|j|_||_||_||_dS)N)examples docstringcopyr0r*rRr)rgrr0r*rRrrr+r+r,r s  zDocTest.__init__cCsRt|jdkrd}n"t|jdkr(d}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__r5r*rRr)rgrr+r+r,__repr__szDocTest.__repr__cCs\t|t|k rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkS)N)rrrrr0r*rRr)rgrr+r+r,r#s     zDocTest.__eq__cCst|j|j|j|jfS)N)rrr*rRr)rgr+r+r,r.szDocTest.__hash__cCs:t|tstS|j|j|jt|f|j|j|jt|fkS)N)r8rrr*rRrid)rgrr+r+r,__lt__2s zDocTest.__lt__N)r5rlrmrrrrrr+r+r+r,rs   c@seZdZejdejejBZejdejejBejBZ ejdj Z dddZ ddZ dd d Zd d Zejd ejZddZejdejZddZddZddZdS)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|j}|j|dkr8djfdd|jdD}g}d\}}x|jj|D]}|j|||j||jd||j7}|j |||\}}} } |j |s|jt || | |t |j d|d||jd|j|j7}|j}qRW|j||d|S)Nr"rHcsg|]}|dqS)Nr+).0l) min_indentr+r, ysz'DocTestParser.parse..r\)rr\r)r"r") expandtabs _min_indentrrp _EXAMPLE_REfinditerappendrcount_parse_example_IS_BLANK_OR_COMMENTrr)groupr) rgstringr*outputZcharnormrrrsrr+)rr,parsems&     zDocTestParser.parsecCst|j|||||||S)N)r get_examples)rgrr0r*rRrr+r+r, get_doctests zDocTestParser.get_doctestcCsdd|j||DS)NcSsg|]}t|tr|qSr+)r8r)rxr+r+r,rsz.DocTestParser.get_examples..)r)rgrr*r+r+r,rs zDocTestParser.get_examplesc s t|jd|jdjd}|j||||j|dddd||djfdd|D}|jd }|jd}t|dkrtjd |d r|d=|j|d||t|djfd d|D}|jj|}|r|jd }nd}|j |||} || ||fS)Nr\rrHr&rXr~csg|]}|ddqS)rWNr+)rsl)r\r+r,rsz0DocTestParser._parse_example..rsz *$csg|]}|dqS)Nr+)rZwl)r\r+r,rsrrnrn) r)rrp_check_prompt_blank _check_prefixrrYmatch _EXCEPTION_RE _find_options) rgrr*r source_linesrrs want_linesrrr+)r\r,rs$      zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c Csi}x|jj|D]z}|jdjddj}x^|D]V}|ddksR|ddtkrhtd|d||ft|dd}|ddk||<q2WqW|r|j|rtd|||f|S) Nr&,rXr"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_RErrrMrpr'rr) rgrr*rrroption_stringsoptionflagr+r+r,rs  zDocTestParser._find_optionsz ^([ ]*)(?=\S)cCs2dd|jj|D}t|dkr*t|SdSdS)NcSsg|] }t|qSr+)r))rr\r+r+r,rsz-DocTestParser._min_indent..r") _INDENT_REfindallr)min)rgr[indentsr+r+r,rs zDocTestParser._min_indentc Csbx\t|D]P\}}t||dkr ||ddkr td||d||||d|fq WdS)NrWrErXz8line %r of the docstring for %s lacks blank after %s: %rr&) enumerater)r)rglinesr\r*rrr{r+r+r,r s   z!DocTestParser._check_prompt_blankcCsDx>t|D]2\}}|r |j| r td||d||fq WdS)NzGline %r of the docstring for %s has inconsistent leading whitespace: %rr&)rrqr)rgrprefixr*rrr{r+r+r,rszDocTestParser._check_prefixN)r)r)r5rlrmrYcompile MULTILINEVERBOSErDOTALLrrrrrrrrrrrrrr+r+r+r,r=s       ' 3c@sJeZdZdeddfddZdddZdd Zd d Zd d ZddZ dS)rFTcCs||_||_||_||_dS)N)_parser_verbose_recurse_exclude_empty)rgverboseparserrecurse exclude_emptyr+r+r,r1szDocTestFinder.__init__Nc CsP|dkr.t|dd}|dkr.tdt|f|dkrr)r/rrr6 getmoduleZ getsourcefilerAZgetfile linecachegetlines__dict__rupdate_findsort) rgobjr*rBr0 extraglobsr^rtestsr+r+r,rrGsJ$          zDocTestFinder.findcCs|dkr dStj|dk r(|tj|kStj|r>|j|jkStj|r|t|dr\|jj}nt|drn|j}ndS|j |kStj |r|j |jkSt|dr|j |jkSt |t rdSt ddS)NT __objclass__rlz"object must be a class or function)r6r isfunctionr __globals__ZismethoddescriptorrKrrlr5isclassr8propertyr)rgrBobjectZobj_modr+r+r, _from_modules(            zDocTestFinder._from_modulec Cs(|jrtd|t||kr"dSd|t|<|j|||||}|dk rR|j|tj|r|jrx^|jj D]P\} } d|| f} tj tj | stj | rn|j || rn|j|| | ||||qnWtj|o|jrtxt|dij D]\} } t| ts tdt| ftj | p8tj | p8tj| p8t| tsNtdt| fd|| f} |j|| | ||||qWtj |r$|jr$x|jj D]\} } t| trt|| } t| trt|| j} tj | stj | st| tr|j || rd|| f} |j|| | ||||qWdS)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_testrr6r7rritemsZ isroutineZunwraprrrr/r8r9rr staticmethod classmethod__func__r) rgrrr*rBrr0seentestZvalnamevalr+r+r,rsP                 zDocTestFinder._findc Cst|tr|}nJy,|jdkr"d}n|j}t|ts:t|}Wnttfk rXd}YnX|j||}|jrv| rvdS|dkrd}n*t|d|j}|dddkr|dd}|j j |||||S)NrrrWz.pycr&rn) r8r9__doc__rAAttributeError _find_linenorr/r5rr) rgrr*rBr0rrrrRr+r+r,rs(         zDocTestFinder._get_testcCsd}tj|rd}tj|rd|dkr(dStjdt|dd}x$t|D]\}}|j|rH|}PqHWtj|rt|j }tj |r|j }tj |r|j }tj|r|j}tj|rt|ddd}|dk r |dkr|dStjd}x(t|t|D]}|j||r|SqWdS)Nr"z^\s*class\s*%s\br5-co_firstlinenor&z(^|.*:)\s*\w*("|\'))r6r7rrYrr/rrZismethodrr__code__Z istracebacktb_frameZisframef_codeZiscoderanger))rgrrrZpatrr{r+r+r,r-s<          zDocTestFinder._find_lineno)NNNN) r5rlrmrrrrrrrrr+r+r+r,r(s  f?%c@seZdZddZdddZddZd d Zd d Zd dZddZ ddZ ddZ e j dZd ddZd!ddZd"ddZddZdS)#rr4FNr"cCsN|pt|_|dkrdtjk}||_||_||_d|_d|_i|_ t |_ dS)Nz-vr") r_checkerr=rr optionflagsoriginal_optionflagstriesfailures_name2ftre_fakeout)rgcheckerrrr+r+r,rs  zDocTestRunner.__init__cCsH|jrD|jr.|dt|jdt|jn|dt|jddS)NzTrying: z Expecting: zExpecting nothing )rrsr]r)rgrrexampler+r+r, report_starts  zDocTestRunner.report_startcCs|jr|ddS)Nzok )r)rgrrrrtr+r+r,report_successszDocTestRunner.report_successcCs&||j|||jj|||jdS)N)_failure_headerroutput_differencer)rgrrrrtr+r+r,report_failures zDocTestRunner.report_failurecCs$||j||dtt|dS)NzException raised: )rr]rd)rgrrrrbr+r+r,report_unexpected_exceptionsz)DocTestRunner.report_unexpected_exceptioncCs|jg}|jrR|jdk r4|jdk r4|j|jd}nd}|jd|j||jfn|jd|jd|jf|jd|j}|jt|dj|S)Nr&?zFile "%s", line %s, in %szLine %s, in %szFailed example:rH)DIVIDERrRrrr*rr]r)rgrrrrrr+r+r,rs zDocTestRunner._failure_headercCsd}}|j}td\}}} |jj} xFt|jD]6\} } |jt@oL|dk} ||_| jrx:| jjD],\}}|r|j|O_qf|j|M_qfW|jt @rq2|d7}| s|j ||| d|j | f}y,t t | j|d|d|j|jjd}Wn4tk rYntj}|jjYnX|jj}|jjd|}|dkrh| | j||jr|}n|tj|ddd}| s|t|7}| jdkr| }nB| | j||jr|}n*|jt@r| t| jt||jr|}||kr| sZ|j||| |nT||kr0| s&|j ||| ||d7}n*|| krZ| sP|j!||| ||d7}n|r2|jt"@r2Pq2W||_|j#|||t$||S)Nr"rEr&zZsingler3rn)%rr r check_outputrrr rrrrr*execrrr0debuggerrKeyboardInterruptr=rbrrarjrsr_format_exception_onlyrdrrrrrrr_DocTestRunner__record_outcomer%)rgr compileflagsrrrrSUCCESSFAILUREZBOOMZcheck examplenumrquietZ optionflagrrRZ exceptionrtZoutcomerr+r+r,Z__runs                   zDocTestRunner.__runcCsL|jj|jd\}}||||f|j|j<|j|7_|j|7_dS)Nr")r"r")rr.r*rr)rgrrUtf2t2r+r+r,Z__record_outcomeuszDocTestRunner.__record_outcomez..+)\[(?P\d+)\]>$cCsV|jj|}|rF|jd|jjkrF|jjt|jd}|jjddS|j ||SdS)Nr*r(T)keepends) %_DocTestRunner__LINECACHE_FILENAME_RErrrr*rintr splitlinessave_linecache_getlines)rgrRmodule_globalsrrr+r+r,Z__patched_linecache_getliness  z*DocTestRunner.__patched_linecache_getlinesTc s||_|dkrt|j}tj|dkrVjdks@jdkrHj}nfdd}|jt_tj }t j }t |_ |j j|j j t _ tj|_|jt_tj}tjt_z|j|||St_|t _ tj||jt_|t_|r|jjddl}d|_XdS)Nzutf-8cs t|jd}j|dS)Nbackslashreplace)r9encodewrite)r[)rIrr+r,rszDocTestRunner.run..outr")rr2r0r=rrIlowerr5rgettracerrrr!resetrrr1*_DocTestRunner__patched_linecache_getlines displayhook__displayhook___DocTestRunner__runsettraceclearbuiltins_) rgrr%r clear_globsZ save_traceZsave_set_traceZsave_displayhookr?r+)rIrr,runs<      zDocTestRunner.runc Cs|dkr|j}g}g}g}d}}xd|jjD]V}|\}\} } || 7}|| 7}| dkrb|j|q.| dkrz|j|| fq.|j|q.W|r|rtt|d|jx|D]} td| qW|rtt|d|jx |D]\} } td| | fqW|rJt|jtt|d|jx(|D] \} \} } td| | | fq&W|rvt|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.) rrrrrr)rrr%) rgrZnotestsZpassedZfailedZtotaltZtotalfrr*rUr*thingrr+r+r, summarizesP     zDocTestRunner.summarizecCsV|j}xJ|jjD]<\}\}}||krB||\}}||}||}||f||<qWdS)N)rr)rgrdr*rUr*r+r,r+r+r,merge s zDocTestRunner.merge)NNr")N)NNT)N)r5rlrmrrrrrrrr<r$rYrr.r9rBrDrFr+r+r+r,ras: $ }   I 9c@s,eZdZddZddZddZddZd S) rcCst|jdddS)NASCIIr3)r9r4)rgr[r+r+r,_toAscii!szOutputChecker._toAsciicCs|j|}|j|}||kr dS|t@sH||fd kr8dS||fd krHdS|t@stjdtjtd|}tjdd|}||krdS|t@rd j|j }d j|j }||krdS|t @rt ||rdSd S) NTTrue 1 False 0 z (?m)^%s\s*?$rz (?m)^\s*?$rXF)rIrJ)rKrL) rHrrrYrZescapeBLANKLINE_MARKERrrrprrx)rgrsrtrr+r+r,r's0     zOutputChecker.check_outputcCs<|ttBtB@sdS|t@r dS|jddko:|jddkS)NFTrHr3)r r r r)rgrsrtrr+r+r,_do_a_fancy_difffs zOutputChecker._do_a_fancy_diffc Cs8|j}|t@stjdt|}|j|||r|jdd}|jdd}|t@rptj ||dd}t |dd}d}nZ|t @rtj ||dd}t |dd}d}n,|t @rtjtjd} t | j||}d }nd d |D}d |td j|S|o|r dt|t|fS|rdt|S|r0dt|SdSdS)Nz(?m)^[ ]*(?= )T)r-r3)nz#unified diff with -expected +actualz-context diff with expected followed by actual)Zcharjunkzndiff with -expected +actualcSsg|]}|jdqS)rH)rz)rr{r+r+r,rsz3OutputChecker.output_difference..zDifferences (%s): rzExpected: %sGot: %szExpected: %sGot nothing zExpected nothing Got: %szExpected nothing Got nothing )rsrrYrZrNrOr0r difflibZ unified_difflistr Z context_diffr ZDifferZIS_CHARACTER_JUNKZcomparer]r) rgrrtrrsrZ got_linesZdiffkindZenginer+r+r,r}s6     zOutputChecker.output_differenceN)r5rlrmrHrrOrr+r+r+r,rs?c@seZdZddZddZdS)rcCs||_||_||_dS)N)rrrt)rgrrrtr+r+r,rszDocTestFailure.__init__cCs t|jS)N)r9r)rgr+r+r,__str__szDocTestFailure.__str__N)r5rlrmrrTr+r+r+r,rs c@seZdZddZddZdS)rcCs||_||_||_dS)N)rrrb)rgrrrbr+r+r,rszUnexpectedException.__init__cCs t|jS)N)r9r)rgr+r+r,rTszUnexpectedException.__str__N)r5rlrmrrTr+r+r+r,rs c@s&eZdZd ddZddZddZdS) rNTcCs$tj||||d}|r |jj|S)NF)rrBr0r>)rgrr%rrArr+r+r,rB.s zDebugRunner.runcCst|||dS)N)r)rgrrrrbr+r+r,r4sz'DebugRunner.report_unexpected_exceptioncCst|||dS)N)r)rgrrrrtr+r+r,r7szDebugRunner.report_failure)NNT)r5rlrmrBrrr+r+r+r,rs[ TFc Cs|dkrtjjd}tj|s,td|f|dkr:|j}t|d} |rVt||d} n t ||d} x$| j ||||dD]} | j | qvW|r| j t dkr| a n t j| t| j| jS)Nrztestmod: module required; %r)r)rr)r0r)r=r>r.r6r7rAr5rrrrrrBrDmasterrFr%rr) rr*r0rreportrrraise_on_errorrfinderrunnerrr+r+r,rCs$E     c Cs|r| rtdt|||| p d\} }|dkr)rgrr+r+r,riys  zDocTestCase.tearDownc Cs|j}tj}t}|j}|t@s(|tO}t||jdd}z$dd|_ |j ||j dd\}}Wd|t_X|r~|j |j |jdS)NF)rrrrr )rrA)rer=rr#rcr r^rrdrrBr5ZfailureExceptionformat_failurera)rgrr_newrrZrrr+r+r,runTests  zDocTestCase.runTestcCsP|j}|jdkrd}n d|j}dj|jjddd}d|j|j|||fS)Nzunknown line numberz%sr~r&z:Failed doctest test for %s File "%s", line %s, in %s %srn)rerrr*rprR)rgerrrrZlnamer+r+r,rjs  zDocTestCase.format_failurecCs6|jt|j|jdd}|j|jdd|jdS)NF)rrr)rA)rhrrcrdrBreri)rgrZr+r+r,r!s B zDocTestCase.debugcCs|jjS)N)rer*)rgr+r+r,rszDocTestCase.idcCsPt|t|k rtS|j|jkoN|j|jkoN|j|jkoN|j|jkoN|j|jkS)N)rrrercrfrgrd)rgrr+r+r,rs    zDocTestCase.__eq__cCst|j|j|j|jfS)N)rrcrfrgrd)rgr+r+r,rszDocTestCase.__hash__cCs,|jjjd}d|ddj|ddfS)Nr~z%s (%s)r&rnrn)rer*rpr)rgr*r+r+r,rszDocTestCase.__repr__cCs d|jjS)Nz Doctest: )rer*)rgr+r+r,shortDescription szDocTestCase.shortDescription)r"NNN)r5rlrmrrhrirlrjr!rrrrrTrnr+r+r+r,r`gs  H r`c@s0eZdZddZddZddZddZeZd S) SkipDocTestCasecCs||_tj|ddS)N)rBr`r)rgrBr+r+r,r szSkipDocTestCase.__init__cCs|jddS)Nz-DocTestSuite will not work with -O2 and above)ZskipTest)rgr+r+r,rh szSkipDocTestCase.setUpcCsdS)Nr+)rgr+r+r, test_skip szSkipDocTestCase.test_skipcCs d|jjS)NzSkipping tests from %s)rBr5)rgr+r+r,rn sz SkipDocTestCase.shortDescriptionN)r5rlrmrrhrprnrTr+r+r+r,ro s roc@seZdZddZdS) _DocTestSuitecCsdS)Nr+)rgindexr+r+r,_removeTestAtIndex sz _DocTestSuite._removeTestAtIndexN)r5rlrmrsr+r+r+r,rq srqc Ks|dkrt}t|}|j|||d}| rPtjjdkrPt}|jt||S|j t}x\|D]T}t |j dkrxqd|j s|j }|dddkr|dd}||_ |jt|f|qdW|S) N)r0rr3r"rWz.pycr&rrn)rrDrrr=r1optimizerqaddTestrorr)rrRrr`) rBr0rZ test_finderrrsuiterrRr+r+r,r s(%  c@s(eZdZddZddZeZddZdS) DocFileCasecCsdj|jjjdS)Nr@r~)rrer*rp)rgr+r+r,r` szDocFileCase.idcCs|jjS)N)rerR)rgr+r+r,rc szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s File "%s", line 0 %s)rer*rR)rgrmr+r+r,rjg szDocFileCase.format_failureN)r5rlrmrrrTrjr+r+r+r,rw^ srwc Ksx|dkri}n|j}|r(| r(tdt||||p6d\}}d|krN||d<tjj|}|j||||d} t| f|S)Nz8Package may only be specified for module-relative paths.zutf-8rr")rrrVrNrr[rrw) rrTrSr0rrIrdocr*rr+r+r, DocFileTestl s  rycOsHt}|jddr$t|jd|d<x|D]}|jt|f|q*W|S)NrTTrS)rqr.rDrury)pathskwrvrr+r+r,r s 8  cCsg}xtj|D]x}t|trj|j|jdd |j}|r|jd|dd|jddd D7}q|dd|jddd D7}qWx|r|d dkr|jqWx|r|ddkr|jdqWdj |dS) Nr&z # Expected:cSsg|] }d|qS)z## r+)rrr+r+r,r sz(script_from_examples..rHcSsg|] }t|qSr+)r|)rrr+r+r,r sryr"rnrnrnrn) rrr8rrrrsrppopr)r[rZpiecersr+r+r,r s:  " csJt|}tj|}fdd|D}|s4td|d}t|j}|S)Ncsg|]}|jkr|qSr+)r*)rr*)r*r+r,r* sztestsource..znot found in testsr")rDrrrrrr)rBr*rrtestsrcr+)r*r,r! s   cCst|}t|||dS)N)r debug_script)srcpmr0r}r+r+r,r 1 sc Csddl}|r|j}ni}|rvyt|||Wqttjd|jdd}|j|jdtjdYqXn|jddj d|||dS)Nr"r&T)rr3zexec(%r)) rrr rr=rbrr8Z interactionrB)rrr0rpr+r+r,r~6 s  r~cCs$t|}t||}t|||jdS)N)rDrr~r)rBr*rr}r+r+r,r!J s c@s$eZdZddZddZddZdS) _TestClasscCs ||_dS)N)r)rgrr+r+r,rf sz_TestClass.__init__cCs|jd|_|S)Nr3)r)rgr+r+r,squarep s z_TestClass.squarecCs|jS)N)r)rgr+r+r,r.z sz_TestClass.getN)r5rlrmrrr.r+r+r+r,rX s  rz Example of a string object, searched as-is. >>> 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 tjdd}|jdddddd|jd d d tjgd d |jddddd|jdddd|j}|j}|j}d}x|jD]}|t|O}q|W|j r|t O}x||D]t}|j drt j j|\}}tj jd|t|dd}tj d=t|||d\} } nt|d||d\} } | rdSqWdS)Nzdoctest runner) descriptionz-vz --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))rrr^rz file containing the tests to run)nargsrr"z.pyrE)rr)rTrrr&)argparseArgumentParser add_argumentr'keys parse_argsr^rrZ fail_fastrrfrNrrpr=insertr:rr) rrZ testfilesrrrrRdirnamerrr@r+r+r,_test s<       rr)r3)rW) NNNNTr"NFF)Fr]Nr")NNNN)FN)FN)F)RZ __docformat____all__r-rrQr6rrNrrYr=r_raior# collectionsr$r%r'rrrrrrrrr r r r rr rNror2rDrVr]rdrerxr|rrrrJrrrrrr ExceptionrrrrVrrrr^rrbr`roZ TestSuiterqrrwryrrrr r~r!rrrr5exitr+r+r+r,0s      1%.DKl;;n f x $! @ IR   ,  +