B Z !@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 m Z d"d%lmZed&d'ZiZd(dZedZedZedZedZedZedZeeBeBeBeBeBZed Zed Zed Zed ZedZeeBeBeBeBZd)Z d*Z!d+d,Z"drd.d/Z#d0d1Z$d2d3Z%dsd5d6Z&d7d8Z'Gd9d:d:e Z(d;d<Z)d=d>Z*d?d@Z+GdAdBdBej,Z-dCdDZ.GdEddZ/GdFddZ0GdGddZ1GdHddZ2GdIddZ3GdJddZ4GdKdde5Z6GdLdde5Z7GdMdde3Z8d#a9dtdPdZ:dNd#d#d#d#dNd"d#dOe1d#f dQdZ;dudSdZGdUdVdVe j?Z@GdWdXdXe@ZAGdYdZdZe jBZCdvd[dZDGd\d]d]e@ZEdNd#d#e1d#fd^d_ZFd`dZGdadZHdbdZIdwdcd ZJdxdddeZKdydfd!ZLGdgdhdhZMeMdidjdkdldmdnZNdodpZOePdqkrle QeOd#S)zzreStructuredText 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 attemptedcCst|dtt>S)N)OPTIONFLAGS_BY_NAME setdefaultlen)namer+*/opt/alt/python37/lib/python3.7/doctest.pyrsz z...cCs<d}x2tjD](}||d}|tt|kr ||jO}q W|S)Nr") __future__Zall_feature_namesgetgetattrZ compiler_flag)globsflagsZfnameZfeaturer+r+r,_extract_future_flagss   r2cCsVt|r|St|tr,t|ttdgS|dkrJtjt |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  rDcCsxdD]}||d}qW|S)N)z   )replace)datanewliner+r+r,_newline_converts rJc Csz|rVt|d}t||}t|dddk rVt|jdrV|j|}||}t||fSt||d}| |fSQRXdS)N __loader__get_data)encoding) rD_module_relative_pathr/hasattrrLrMdecoderJopenread)filenamepackagemodule_relativerNZ file_contentsfr+r+r,_load_testfiles      rXcCstd|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 rfc@seZdZddZdddZdS) _SpoofOutcCs$t|}|r |ds |d7}|S)NrF)r#rcendswith)selfresultr+r+r,rcs z_SpoofOut.getvalueNcCs||t|dS)N)seekr#truncate)risizer+r+r,rl s z_SpoofOut.truncate)N)r5 __module__ __qualname__rcrlr+r+r+r,rgs rgcCst|kr||kS|t}dt|}}|d}|rR||rNt|}|d=ndS|d}|r||r||t|8}|d=ndS||krdSx2|D]*}||||}|dkrdS|t|7}qWdS)Nr"FT)ELLIPSIS_MARKERsplitr) startswithrhfind)wantgotZwsstartposendposwr+r+r,_ellipsis_matchs0     rzcCs|}|rd|SdSdS)Nz# #)rstrip)liner+r+r, _comment_line?sr~cCshdt|}}|d}|dkr$|}|dd|}|dkr>|}|dd|}|dkr\|d}|||S)Nr"rF:.r&)r)rtrfind)msgstartendir+r+r,_strip_exception_detailsGs  rc@s.eZdZddZd ddZddZdd ZdS) _OutputRedirectingPdbcCs(||_d|_tjj||ddd|_dS)NFT)stdoutnosigintr&)_OutputRedirectingPdb__out$_OutputRedirectingPdb__debugger_usedpdbPdb__init__Z use_rawinput)rioutr+r+r,rgsz_OutputRedirectingPdb.__init__NcCs*d|_|dkrtj}tj||dS)NT)rr=r?f_backrr set_trace)riframer+r+r,ros z_OutputRedirectingPdb.set_tracecCs|jrtj|dS)N)rrr set_continue)rir+r+r,rusz"_OutputRedirectingPdb.set_continuecGs.tj}|jt_ztjj|f|S|t_XdS)N)r=rrrrtrace_dispatch)riargs save_stdoutr+r+r,r{s z$_OutputRedirectingPdb.trace_dispatch)N)r5rnrorrrrr+r+r+r,ras rcCst|std||dr(tdtjj|d}t |drXtj|j d}n|j dkrt t jdkrt jddkrtjt jdd}qtj}nFt |drx,|jD]"}tj||}tj|r|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__))r6r7rArs ValueErrorospathjoinrrrPrr5r)r=argvcurdirrexists)rBZ test_pathZbasedirZ directoryZfullpathr+r+r,rOs&         rOc@s&eZdZd ddZddZddZdS) rNr"cCsv|ds|d7}|r(|ds(|d7}|dk rB|dsB|d7}||_||_||_||_|dkrfi}||_||_dS)NrF)rhsourcerulinenor^optionsexc_msg)rirrurrr^rr+r+r,rs zExample.__init__cCs\t|t|k rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkS)N)typeNotImplementedrrurr^rr)riotherr+r+r,__eq__s     zExample.__eq__cCst|j|j|j|j|jfS)N)hashrrurr^r)rir+r+r,__hash__szExample.__hash__)Nr"r"N)r5rnrorrrr+r+r+r,rs#  c@s4eZdZddZddZddZddZd d Zd S) rcCs,||_||_||_||_||_||_dS)N)examples docstringcopyr0r*rTr)rirr0r*rTrrr+r+r,rs  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*rTr)rirr+r+r,__repr__szDocTest.__repr__cCs\t|t|k rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkS)N)rrrrr0r*rTr)rirr+r+r,r)s     zDocTest.__eq__cCst|j|j|j|jfS)N)rrr*rTr)rir+r+r,r4szDocTest.__hash__cCs:t|tstS|j|j|jt|f|j|j|jt|fkS)N)r8rrr*rTrid)rirr+r+r,__lt__8s zDocTest.__lt__N)r5rnrorrrrrr+r+r+r,rs   c@seZdZedejejBZedejejBejBZ 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|}||dkr8dfdd|dD}g}d\}}x|j|D]}||||||d||7}| |||\}}} } | |s|t || | |t | d|d||d||7}|}qRW|||d|S)Nr"rFcsg|]}|dqS)Nr+).0l) min_indentr+r, sz'DocTestParser.parse..)r"r"r^)rr^r) expandtabs _min_indentrrr _EXAMPLE_REfinditerappendrcount_parse_example_IS_BLANK_OR_COMMENTrr)groupr) ristringr*outputZcharnormrrrurr+)rr,parsess&     zDocTestParser.parsecCst||||||||S)N)r get_examples)rirr0r*rTrr+r+r, get_doctests zDocTestParser.get_doctestcCsdd|||DS)NcSsg|]}t|tr|qSr+)r8r)rxr+r+r,rsz.DocTestParser.get_examples..)r)rirr*r+r+r,rs zDocTestParser.get_examplesc s t|d|dd}||||||dddd||dfdd|D}|d }|d}t|dkrtd |d r|d =||d||t|dfd d|D}|j|}|r|d }nd}| |||} || ||fS)Nr^rrFr&rZrcsg|]}|ddqS)rYNr+)rsl)r^r+r,rsz0DocTestParser._parse_example..ruz *$rpcsg|]}|dqS)Nr+)rZwl)r^r+r,rsr) r)rrr_check_prompt_blank _check_prefixrr[match _EXCEPTION_RE _find_options) rirr*r source_linesrru want_linesrrr+)r^r,rs$      zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c Csi}x|j|D]z}|ddd}x^|D]V}|ddksR|ddtkrhtd|d||ft|dd}|ddk||<q2WqW|r||rtd|||f|S) Nr&,rZr"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_RErrrGrrr'rr) rirr*rrroption_stringsoptionflagr+r+r,rs  zDocTestParser._find_optionsz ^([ ]*)(?=\S)cCs2dd|j|D}t|dkr*t|SdSdS)NcSsg|] }t|qSr+)r))rr^r+r+r,r sz-DocTestParser._min_indent..r") _INDENT_REfindallr)min)rir]indentsr+r+r,rs zDocTestParser._min_indentc Csbx\t|D]P\}}t||dkr ||ddkr td||d||||d|fq WdS)NrYrKrZz8line %r of the docstring for %s lacks blank after %s: %rr&) enumerater)r)rilinesr^r*rrr}r+r+r,rs   z!DocTestParser._check_prompt_blankcCsBxr)r/rrr6 getmoduleZ getsourcefilerAZgetfile linecachegetlines__dict__rupdate_findsort) riobjr*rBr0 extraglobsr`rtestsr+r+r,rtMsJ$         zDocTestFinder.findcCs|dkr dSt|dk r(|t|kSt|r>|j|jkSt|r|t|dr\|jj}nt|drn|j}ndS|j |kSt |r|j |jkSt|dr|j |jkSt |t rdSt ddS)NT __objclass__rnz"object must be a class or function)r6r isfunctionr __globals__ZismethoddescriptorrPrrnr5isclassr8propertyr)rirBobjectZobj_modr+r+r, _from_modules(            zDocTestFinder._from_modulec Cs*|jrtd|t||kr"dSd|t|<||||||}|dk rR||t|r|jrx^|j D]P\} } d|| f} t t | st | rn| || rn||| | ||||qnWt|rv|jrvxt|di D]\} } t| tstdt| ft | sPt | sPt| sPt| tsPtdt| fd|| f} ||| | ||||qWt |r&|jr&x|j D]\} } t| trt|| } t| trt|| j} t | st | st| tr| || rd|| f} ||| | ||||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) rirrr*rBrr0seentestZvalnamevalr+r+r,rsP                 zDocTestFinder._findc Cst|tr|}nJy,|jdkr"d}n|j}t|ts:t|}Wnttfk rXd}YnX|||}|jrt|stdS|dkrd}n.t|ddp|j}|dddkr|dd}|j |||||S)Nrrz.pycrp) r8r9__doc__rAAttributeError _find_linenorr/r5rr) rirr*rBr0rrrrTr+r+r,rs(         zDocTestFinder._get_testcCsd}t|rd}t|rd|dkr(dStdt|dd}x$t|D]\}}||rH|}PqHWt|rt|j }t |r|j }t |r|j }t|r|j}t|rt|ddd}|dk r |dkr|dStd}x(t|t|D]}|||r|SqWdS)Nr"z^\s*class\s*%s\br5-co_firstlinenor&z(^|.*:)\s*\w*("|\'))r6r7rr[rr/rrZismethodrr__code__Z istracebacktb_frameZisframef_codeZiscoderanger))rirrrZpatrr}r+r+r,r 4s<          zDocTestFinder._find_lineno)NNNN) r5rnrorrrtrrrr r+r+r+r,r.s  f?&c@seZdZdZdddZddZdd Zd d Zd d ZddZ ddZ ddZ e dZdddZd ddZd!ddZddZdS)"rzF**********************************************************************Nr"cCsN|pt|_|dkrdtjk}||_||_||_d|_d|_i|_ t |_ dS)Nz-vr") r_checkerr=rr optionflagsoriginal_optionflagstriesfailures_name2ftrg_fakeout)richeckerrrr+r+r,rs  zDocTestRunner.__init__cCsH|jrD|jr.|dt|jdt|jn|dt|jddS)NzTrying: z Expecting: zExpecting nothing )rrur_r)rirrexampler+r+r, report_starts  zDocTestRunner.report_startcCs|jr|ddS)Nzok )r)rirrrrvr+r+r,report_successszDocTestRunner.report_successcCs&|||||j|||jdS)N)_failure_headerroutput_differencer)rirrrrvr+r+r,report_failures zDocTestRunner.report_failurecCs$||||dtt|dS)NzException raised: )rr_rf)rirrrrdr+r+r,report_unexpected_exceptionsz)DocTestRunner.report_unexpected_exceptioncCs|jg}|jrR|jdk r4|jdk r4|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:rF)DIVIDERrTrrr*rr_r)rirrrrrr+r+r,rs zDocTestRunner._failure_headerc Csd}}|j}td\}}} |jj} xFt|jD]6\} } |jt@oL|dk} ||_| jrx:| jD],\}}|r|j|O_qf|j|M_qfW|jt @rq2|d7}| s| ||| d|j | f}y,t t | j|d|d|j|jd}Wn4tk rYnt}|jYnX|j}|jd|}|dkrh| | j||jr|}n|tj|ddd}| s|t|7}| jdkr| }nB| | j||jr|}n*|jt@r| t| jt||jr|}||kr| sZ|||| |nT||kr0| s&| ||| ||d7}n*|| krZ| sP|!||| ||d7}n|r2|jt"@r2Pq2W||_|#|||t$||S)Nr"rKr&zZsingler3rp)%rrr check_outputrrr rrrrr*execrrr0debuggerrKeyboardInterruptr=rdrrcrlruraformat_exception_onlyrfrrrrrrr_DocTestRunner__record_outcomer%)rir compileflagsrrrrSUCCESSFAILUREZBOOMZcheck examplenumrquietZ optionflagrrTZ exceptionrvZoutcomerr+r+r,Z__runs                   zDocTestRunner.__runcCsL|j|jd\}}||||f|j|j<|j|7_|j|7_dS)N)r"r")rr.r*rr)rirrWtf2t2r+r+r,Z__record_outcome|szDocTestRunner.__record_outcomez..+)\[(?P\d+)\]>$cCsV|j|}|rF|d|jjkrF|jjt|d}|jjddS| ||SdS)Nr*r*T)keepends) %_DocTestRunner__LINECACHE_FILENAME_RErrrr*rintr splitlinessave_linecache_getlines)rirTmodule_globalsrrr+r+r,Z__patched_linecache_getliness  z*DocTestRunner.__patched_linecache_getlinesTc s||_|dkrt|j}tj|dkrVjdks@dkrHj}nfdd}|jt_t }t j }t |_ |j |j j t _ tj|_|jt_tj}tjt_z||||St_|t _ t||jt_|t_|r|jddl}d|_XdS)Nzutf-8cs t|d}|dS)Nbackslashreplace)r9encodewrite)r])rNrr+r,rszDocTestRunner.run..outr")rr2r0r=rrNlowerr7rgettracerrrr#resetrrr3*_DocTestRunner__patched_linecache_getlines displayhook__displayhook___DocTestRunner__runsettraceclearbuiltins_) rirr'r clear_globsZ save_traceZsave_set_traceZsave_displayhookrAr+)rNrr,runs<      zDocTestRunner.runc Cs|dkr|j}g}g}g}d}}xd|jD]V}|\}\} } || 7}|| 7}| dkrb||q.| dkrz||| fq.||q.W|r|rtt|d|x|D]} td| qW|rtt|d|x |D]\} } td| | fqW|rJt|jtt|d|x(|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)rr r%) rirZnotestsZpassedZfailedZtotaltZtotalfrr*rWr,thingrr+r+r, summarizesP     zDocTestRunner.summarizecCsV|j}xJ|jD]<\}\}}||krB||\}}||}||}||f||<qWdS)N)rr)rirdr*rWr,r-r.r+r+r,merges zDocTestRunner.merge)NNr")N)NNT)N)r5rnror rrrrrrr>r&r[rr0r;rDrFrHr+r+r+r,rhs: $ }   I 9c@s,eZdZddZddZddZddZd S) rcCst|dddS)NASCIIr5)r9r6)rir]r+r+r,_toAscii(szOutputChecker._toAsciicCs||}||}||kr dS|t@sH||fdkr8dS||fdkrHdS|t@stdttd|}tdd|}||krdS|t@rd| }d| }||krdS|t @rt ||rdSdS) NT)zTrue z1 )zFalse z0 z (?m)^%s\s*?$rz(?m)^[^\S\n]+$rZF) rJrrr[r\escapeBLANKLINE_MARKERrrrrrrz)rirurvrr+r+r,r!.s0     zOutputChecker.check_outputcCs<|ttBtB@sdS|t@r dS|ddko:|ddkS)NFTrFr3)r r r r)rirurvrr+r+r,_do_a_fancy_diffms zOutputChecker._do_a_fancy_diffc Cs(|j}|t@stdt|}||||r|jdd}|jdd}|t@rptj ||dd}t |dd}d}nZ|t @rtj ||dd}t |dd}d}n,|t @rtjtjd} t | ||}d }nd |td |S|r|rd t|t|fS|rd t|S|r dt|SdSdS)Nz(?m)^[ ]*(?= )T)r/r3)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 )rurr[r\rLrMr2r difflibZ unified_difflistr Z context_diffr ZDifferZIS_CHARACTER_JUNKZcomparer_r) rirrvrrurZ got_linesZdiffkindZenginer+r+r,rs4    zOutputChecker.output_differenceN)r5rnrorJr!rMrr+r+r+r,r s?c@seZdZddZddZdS)rcCs||_||_||_dS)N)rrrv)rirrrvr+r+r,rszDocTestFailure.__init__cCs t|jS)N)r9r)rir+r+r,__str__szDocTestFailure.__str__N)r5rnrorrRr+r+r+r,rs c@seZdZddZddZdS)rcCs||_||_||_dS)N)rrrd)rirrrdr+r+r,rszUnexpectedException.__init__cCs t|jS)N)r9r)rir+r+r,rRszUnexpectedException.__str__N)r5rnrorrRr+r+r+r,rs c@s&eZdZd ddZddZddZdS) rNTcCs$t||||d}|r |j|S)NF)rrDr0r@)rirr'rrCrr+r+r,rD3s zDebugRunner.runcCst|||dS)N)r)rirrrrdr+r+r,r9sz'DebugRunner.report_unexpected_exceptioncCst|||dS)N)r)rirrrrvr+r+r,r<szDebugRunner.report_failure)NNT)r5rnrorDrrr+r+r+r,rs[ TFc Cs|dkrtjd}t|s,td|f|dkr:|j}t|d} |rVt||d} n t ||d} x$| j ||||dD]} | | qvW|r| t dkr| a n t | t| j| jS)Nrztestmod: module required; %r)r)rr)r0r)r=r>r.r6r7rAr5rrrrtrDrFmasterrHr%rr) rr*r0rreportrrraise_on_errorrfinderrunnerrr+r+r,rHs$E     c Cs|r|stdt|||| pd\} }|dkr:tj|}|dkrHi}n|}|dk rb||d|krrd|d<| rt||d} n t||d} | | |||d}| ||r| t dkr| a n t | t| j| jS)Nz8Package may only be specified for module-relative paths.zutf-8r5r)rrr")rrXrrbasenamerrrrrrDrFrTrHr%rr)rTrVr*rUr0rrUrrrVrrNtextrXrr+r+r,rs0R     NoNamec CsDt|dd}t||d}x&|j|||dD]}|j||dq*WdS)NF)rr)rr)r0)r')rrrtrD) rWr0rr*r'rrWrXrr+r+r,r+s  cCs"|t@|krtd|t}|a|S)NzOnly reporting flags allowed)r r_unittest_reportflags)r1oldr+r+r,rHs   c@sjeZdZdddZddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ e Z ddZdS) DocTestCaser"NcCs.tj|||_||_||_||_||_dS)N)unittestTestCaser_dt_optionflags _dt_checker_dt_test _dt_setUp _dt_tearDown)rirrsetUptearDownrr+r+r,rns  zDocTestCase.__init__cCs|j}|jdk r||dS)N)rcrd)rirr+r+r,rfxs zDocTestCase.setUpcCs(|j}|jdk r|||jdS)N)rcrer0r@)rirr+r+r,rg~s  zDocTestCase.tearDowncCs~|j}tj}t}|j}|t@s(|tO}t||jdd}z d|_ |j ||j dd\}}Wd|t_X|rz| | |dS)NF)rrrzF----------------------------------------------------------------------)rrC)rcr=rr#rar r\rrbr rDr7ZfailureExceptionformat_failurerc)rirr]newrrXrrr+r+r,runTests zDocTestCase.runTestcCsP|j}|jdkrd}n d|j}d|jddd}d|j|j|||fS)Nzunknown line numberz%srrpz:Failed doctest test for %s File "%s", line %s, in %s %s)rcrrr*rrrT)rierrrrZlnamer+r+r,rhs  zDocTestCase.format_failurecCs6|t|j|jdd}|j|jdd|dS)NF)rrr)rC)rfrrarbrDrcrg)rirXr+r+r,r!s B zDocTestCase.debugcCs|jjS)N)rcr*)rir+r+r,rszDocTestCase.idcCsPt|t|k rtS|j|jkoN|j|jkoN|j|jkoN|j|jkoN|j|jkS)N)rrrcrardrerb)rirr+r+r,rs    zDocTestCase.__eq__cCst|j|j|j|jfS)N)rrardrerb)rir+r+r,rszDocTestCase.__hash__cCs,|jjd}d|dd|ddfS)Nrz%s (%s)rp)rcr*rrr)rir*r+r+r,r szDocTestCase.__repr__cCs d|jjS)Nz Doctest: )rcr*)rir+r+r,shortDescription szDocTestCase.shortDescription)r"NNN)r5rnrorrfrgrjrhr!rrrrrRrlr+r+r+r,r^ls  H r^c@s0eZdZddZddZddZddZeZd S) SkipDocTestCasecCs||_t|ddS)N)rBr^r)rirBr+r+r,r szSkipDocTestCase.__init__cCs|ddS)Nz-DocTestSuite will not work with -O2 and above)ZskipTest)rir+r+r,rf szSkipDocTestCase.setUpcCsdS)Nr+)rir+r+r, test_skip szSkipDocTestCase.test_skipcCs d|jjS)NzSkipping tests from %s)rBr5)rir+r+r,rl sz SkipDocTestCase.shortDescriptionN)r5rnrorrfrnrlrRr+r+r+r,rm s rmc@seZdZddZdS) _DocTestSuitecCsdS)Nr+)riindexr+r+r,_removeTestAtIndex sz _DocTestSuite._removeTestAtIndexN)r5rnrorqr+r+r+r,ro sroc Ks|dkrt}t|}|j|||d}|sNtjjdkrNt}|t||S| t}x\|D]T}t |j dkrvqb|j s|j }|dddkr|dd}||_ |t|f|qbW|S)N)r0rr3r"rz.pycrp)rrDrtr=r1optimizeroaddTestrmrr)rrTrr^) rBr0rZ test_finderrrsuiterrTr+r+r,r# s(%  c@s(eZdZddZddZeZddZdS) DocFileCasecCsd|jjdS)NrBr)rrcr*rr)rir+r+r,re szDocFileCase.idcCs|jjS)N)rcrT)rir+r+r,rh szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s File "%s", line 0 %s)rcr*rT)rirkr+r+r,rhl szDocFileCase.format_failureN)r5rnrorrrRrhr+r+r+r,ruc sruc Ksv|dkri}n|}|r&|s&tdt||||p4d\}}d|krL||d<tj|}|||||d} t| f|S)Nz8Package may only be specified for module-relative paths.zutf-8rr")rrrXrrrYrru) rrVrUr0rrNrdocr*rr+r+r, DocFileTestq s rwcOsHt}|ddr$t|d|d<x|D]}|t|f|q*W|S)NrVTrU)ror.rDrsrw)pathskwrtrr+r+r,r s 8  cCsg}xt|D]x}t|trj||jdd|j}|r|d|dd|dddD7}q|dd|dddD7}qWx|r|ddkr|qWx|r|ddkr|dqWd |dS) Nrpz # Expected:cSsg|] }d|qS)z## r+)rrr+r+r,r sz(script_from_examples..rFcSsg|] }t|qSr+)r~)rrr+r+r,r sr{r") rrr8rrrrurrpopr)r]rZpiecerur+r+r,r s:  " csJt|}t|}fdd|D}|s4td|d}t|j}|S)Ncsg|]}|jkr|qSr+)r*)rr,)r*r+r,r/ sztestsource..znot found in testsr")rDrrtrrr)rBr*rrtestsrcr+)r*r,r& s   cCst|}t|||dS)N)r debug_script)srcpmr0r{r+r+r,r 6 scCsddl}|r|}ni}|rvyt|||Wqttd|jdd}||dtdYqXn|jdd d|||dS)Nr"r&T)rr3zexec(%r)) rrr"rr=rdrr:Z interactionrD)r}r~r0rpr+r+r,r|; s  r|cCs$t|}t||}t|||jdS)N)rDrr|r)rBr*r~r{r+r+r,r!O s c@s$eZdZddZddZddZdS) _TestClasscCs ||_dS)N)r)rirr+r+r,rk sz_TestClass.__init__cCs|jd|_|S)Nr3)r)rir+r+r,squareu s z_TestClass.squarecCs|jS)N)r)rir+r+r,r. sz_TestClass.getN)r5rnrorrr.r+r+r+r,r] 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*ddl}|jdd}|jdddddd |jd d d tgd d|jddddd|jdddd|}|j}|j}d}x|jD]}|t|O}qW|j r|t O}x~|D]v}| drt j |\}}tj d|t|dd} tj d=t| ||d\} } nt|d||d\} } | rdSqWdS)Nr"zdoctest 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)nargsrz.py)rr)rVrrr&)argparseArgumentParser add_argumentr'keys parse_argsr`rrZ fail_fastrrhrrrrr=insertr:rr) rrrZ testfilesrrrrTdirnamerrrBr+r+r,_test s>       rr)r3)rY) NNNNTr"NFF)Fr[Nr")NNNN)FN)FN)F)RZ __docformat____all__r-rOr6rrrr[r=rar_ior# collectionsr$r%r'rrrrrrrrr r r r rr rLrqr2rDrJrXr_rfrgrzr~rrrrOrrrrrr ExceptionrrrrTrrrr\rr`r^rmZ TestSuiterorrurwrrrr r|r!rrrr5exitr+r+r+r,0s      1%.DKl<;n f x $! @ IR   ,  -