ž §’f’c @sūdZdZdddddddd d d d d ddddddddddddddddddd d!g Zd"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(d„ZedƒZedƒZedƒZedƒZedƒZedƒZeeBeBeBeBeBZed ƒZed ƒZed ƒZed ƒZeeBeBeBZd)Z d*Z!d+d,„Z"d-d.d/„Z#d0d1„Z$d2d3d4„Z%d5d6„Z&Gd7d8„d8eƒZ'd9d:„Z(d;d<„Z)d=d>„Z*Gd?d@„d@ej+ƒZ,dAdB„Z-GdCd„dƒZ.GdDd„dƒZ/GdEd„dƒZ0GdFd„dƒZ1GdGd„dƒZ2GdHd„dƒZ3GdId„de4ƒZ5GdJd„de4ƒZ6GdKd„de2ƒZ7e8a9e8e8e8e8e:d"e8e;e;dLd„ Z<e:e8e8e8e8e:d"e8e;e0ƒe8dMd„ Z=e;dNe8d"dOd„Z>d"a?dPd„Z@GdQdR„dRe jAƒZBGdSdT„dTeBƒZCe8e8e8e8dUd„ZDGdVdW„dWeBƒZEe:e8e8e0ƒe8dXdY„ZFdZd„ZGd[d„ZHd\d„ZIe;e8d]d „ZJe;e8d^d_„ZKe;d`d!„ZLGdadb„dbƒZMieMdb6dcdd6dedf6dgdh6didj6dkdl6ZNdmdn„ZOePdokr÷e jQeOƒƒnd#S(puÅModule doctest -- a framework for running examples in docstrings. In simplest use, end each module M to be tested with: def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test() Then running the module as a script will cause the examples in the docstrings to get executed and verified: python M.py This won't display anything unless an example fails, in which case the failing example(s) and the cause(s) of the failure(s) are printed to stdout (why not stderr? because stderr is a lame hack <0.2 wink>), and the final line of output is "Test failed.". Run it with the -v switch instead: python M.py -v and a detailed report of all examples tried is printed to stdout, along with assorted summaries at the end. You can force verbose mode by passing "verbose=True" to testmod, or prohibit it by passing "verbose=False". In either of those cases, sys.argv is not examined by testmod. There are a variety of other ways to run doctests, including integration with the unittest framework, and support for running non-Python text files containing doctests. There are also many ways to override parts of doctest's default behaviors. See the Library Reference Manual for details. ureStructuredText enuregister_optionflaguDONT_ACCEPT_TRUE_FOR_1uDONT_ACCEPT_BLANKLINEuNORMALIZE_WHITESPACEuELLIPSISuSKIPuIGNORE_EXCEPTION_DETAILuCOMPARISON_FLAGSu REPORT_UDIFFu REPORT_CDIFFu REPORT_NDIFFuREPORT_ONLY_FIRST_FAILUREuREPORTING_FLAGSuExampleuDocTestu DocTestParseru DocTestFinderu DocTestRunneru OutputCheckeruDocTestFailureuUnexpectedExceptionu DebugRunnerutestmodutestfileurun_docstring_examplesu DocTestSuiteu DocFileSuiteuset_unittest_reportflagsuscript_from_examplesu testsourceu debug_srcudebugiN(uStringIO(u namedtupleu TestResultsufailed attemptedcCstj|dttƒ>ƒS(Ni(uOPTIONFLAGS_BY_NAMEu setdefaultulen(uname((u,/opt/alt/python33/lib64/python3.3/doctest.pyuregister_optionflagƒsu u...cCsUd}xHtjD]=}|j|dƒ}|tt|ƒkr||jO}qqW|S(u… Return the compiler-flags associated with the future features that have been imported into the given namespace (globs). iN(u __future__uall_feature_namesugetuNoneugetattru compiler_flag(uglobsuflagsufnameufeature((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_extract_future_flags“s u_extract_future_flagsicCsutj|ƒr|St|tƒr>t|tƒtƒdgƒS|dkretj tj |ƒj dSt dƒ‚dS(u‡ Return the module specified by `module`. In particular: - If `module` is a module, then return module. - If `module` is a string, then import and return the module with that name. - If `module` is None, then return the calling module. The calling module is assumed to be the module of the stack frame at the given depth in the call stack. u*u__name__u"Expected a module, string, or NoneN( uinspectuismoduleu isinstanceustru __import__uglobalsulocalsuNoneusysumodulesu _getframeu f_globalsu TypeError(umoduleudepth((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_normalize_moduleĄs  u_normalize_modulec Cs“|r…t|dƒ}t||ƒ}t|dƒr…t|jdƒr‚|jj|ƒ}|j|ƒ}|jtjdƒ|fSq…nt |d|ƒ}|j ƒ|fSWdQXdS(Niu __loader__uget_datau uencoding( u_normalize_moduleu_module_relative_pathuhasattru __loader__uget_dataudecodeureplaceuosulinesepuopenuread(ufilenameupackageumodule_relativeuencodingu file_contentsuf((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_load_testfileÓsu_load_testfileicCstjd|d|ƒS(u~ Add the given number of space characters to the beginning of every non-blank line in `s`, and return the result. u (?m)^(?!$)u (ureusub(usuindent((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_indentįsu_indentcCs;tƒ}|\}}}tj|||d|ƒ|jƒS(uz Return a string containing a traceback message for the given exc_info tuple (as returned by sys.exc_info()). ufile(uStringIOu tracebackuprint_exceptionugetvalue(uexc_infouexcoutuexc_typeuexc_valuexc_tb((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_exception_tracebackés u_exception_tracebackcBs/|EeZdZdd„Zddd„ZdS(u _SpoofOutcCs6tj|ƒ}|r2|jdƒ r2|d7}n|S(Nu (uStringIOugetvalueuendswith(uselfuresult((u,/opt/alt/python33/lib64/python3.3/doctest.pyugetvalueös u_SpoofOut.getvaluecCs|j|ƒtj|ƒdS(N(useekuStringIOutruncate(uselfusize((u,/opt/alt/python33/lib64/python3.3/doctest.pyutruncate’s u_SpoofOut.truncateN(u__name__u __module__u __qualname__ugetvalueuNoneutruncate(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _SpoofOutõs u _SpoofOutcCs&t|kr||kS|jtƒ}t|ƒdks=t‚dt|ƒ}}|d}|rŒ|j|ƒr…t|ƒ}|d=qŒdSn|d}|rĢ|j|ƒrÅ|t|ƒ8}|d=qĢdSn||krÜdSxC|D];}|j|||ƒ}|dkrdS|t|ƒ7}qćWdS(u_ Essentially the only subtle case: >>> _ellipsis_match('aa...aa', 'aaa') False iiiFi’’’’i’’’’T( uELLIPSIS_MARKERusplitulenuAssertionErroru startswithuFalseuendswithufinduTrue(uwantugotuwsustartposuendposuw((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_ellipsis_matchs2          u_ellipsis_matchcCs"|jƒ}|rd|SdSdS(u)Return a commented form of the given lineu# u#N(urstrip(uline((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _comment_line5s u _comment_linecCsdt|ƒ}}|jdƒ}|dkr7|}n|jdd|ƒ}|dkra|}n|jdd|ƒ}|dkr|d}n|||…S(Niu u:u.i(ulenufindurfind(umsgustartuendui((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_strip_exception_details=s       u_strip_exception_detailscBsM|EeZdZdZdd„Zd dd„Zdd„Zdd „Zd S( u_OutputRedirectingPdbuĄ A specialized version of the python debugger that redirects stdout to a given stream when interacting with the user. Stdout is *not* redirected when traced code is executed. cCs;||_d|_tjj|d|ddƒd|_dS(NustdoutunosigintiFT(u_OutputRedirectingPdb__outuFalseu$_OutputRedirectingPdb__debugger_usedupdbuPdbu__init__uTrueu use_rawinput(uselfuout((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__]s  u_OutputRedirectingPdb.__init__cCs>d|_|dkr'tjƒj}ntjj||ƒdS(NT( uTrueu$_OutputRedirectingPdb__debugger_useduNoneusysu _getframeuf_backupdbuPdbu set_trace(uselfuframe((u,/opt/alt/python33/lib64/python3.3/doctest.pyu set_tracees  u_OutputRedirectingPdb.set_tracecCs |jrtjj|ƒndS(N(u$_OutputRedirectingPdb__debugger_usedupdbuPdbu set_continue(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu set_continueks u"_OutputRedirectingPdb.set_continuec Gs=tj}|jt_ztjj||ŒSWd|t_XdS(N(usysustdoutu_OutputRedirectingPdb__outupdbuPdbutrace_dispatch(uselfuargsu save_stdout((u,/opt/alt/python33/lib64/python3.3/doctest.pyutrace_dispatchqs   u$_OutputRedirectingPdb.trace_dispatchN( u__name__u __module__u __qualname__u__doc__u__init__uNoneu set_traceu set_continueutrace_dispatch(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_OutputRedirectingPdbWs   u_OutputRedirectingPdbcCsžtj|ƒs"td|ƒ‚n|jdƒr@tdƒ‚nt|dƒrktjj|j ƒd}nw|j dkrĪt t j ƒdkrĀt j ddkrĀtjjt j dƒd}qātj}ntd|d ƒ‚tjj||jdƒŒS( NuExpected a module: %ru/u1Module-relative files may not have absolute pathsu__file__iu__main__uu+Can't resolve paths relative to the module u (it has no __file__)(uinspectuismoduleu TypeErroru startswithu ValueErroruhasattruosupathusplitu__file__u__name__ulenusysuargvucurdirujoin(umoduleupathubasedir((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_module_relative_path|s(  u_module_relative_pathcBsV|EeZdZdZd ddd dd„Zdd„Zdd„Zd d „Zd S( uExampleun A single doctest example, consisting of source code and expected output. `Example` defines the following attributes: - source: A single Python statement, always ending with a newline. The constructor adds a newline if needed. - want: The expected output from running the source code (either from stdout, or a traceback in case of exception). `want` ends with a newline unless it's empty, in which case it's an empty string. The constructor adds a newline if needed. - exc_msg: The exception message generated by the example, if the example is expected to generate an exception; or `None` if it is not expected to generate an exception. This exception message is compared against the return value of `traceback.format_exception_only()`. `exc_msg` ends with a newline unless it's `None`. The constructor adds a newline if needed. - lineno: The line number within the DocTest string containing this Example where the Example begins. This line number is zero-based, with respect to the beginning of the DocTest. - indent: The example's indentation in the DocTest string. I.e., the number of space characters that precede the example's first prompt. - options: A dictionary mapping from option flags to True or False, which is used to override default options for this example. Any option flags not contained in this dictionary are left at their default value (as specified by the DocTestRunner's optionflags). By default, no options are set. icCs·|jdƒs|d7}n|r?|jdƒ r?|d7}n|dk rh|jdƒ rh|d7}n||_||_||_||_|dkr”i}n||_||_dS(Nu (uendswithuNoneusourceuwantulinenouindentuoptionsuexc_msg(uselfusourceuwantuexc_msgulinenouindentuoptions((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__Ćs         uExample.__init__cCs†t|ƒt|ƒk rtS|j|jko…|j|jko…|j|jko…|j|jko…|j|jko…|j|jkS(N(utypeuNotImplementedusourceuwantulinenouindentuoptionsuexc_msg(uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__eq__ÕsuExample.__eq__cCs ||k S(N((uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__ne__ąsuExample.__ne__cCs(t|j|j|j|j|jfƒS(N(uhashusourceuwantulinenouindentuexc_msg(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__hash__ćsuExample.__hash__N( u__name__u __module__u __qualname__u__doc__uNoneu__init__u__eq__u__ne__u__hash__(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyuExample s "  cBsb|EeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS(uDocTestue A collection of doctest examples that should be run in a single namespace. Each `DocTest` defines the following attributes: - examples: the list of examples. - globs: The namespace (aka globals) that the examples should be run in. - name: A name identifying the DocTest (typically, the name of the object whose docstring this DocTest was extracted from). - filename: The name of the file that this DocTest was extracted from, or `None` if the filename is unknown. - lineno: The line number within filename where this DocTest begins, or `None` if the line number is unavailable. This line number is zero-based, with respect to the beginning of the file. - docstring: The string that the examples were extracted from, or `None` if the string is unavailable. cCs\t|tƒ stdƒ‚||_||_|jƒ|_||_||_||_ dS(uŒ Create a new DocTest containing the given examples. The DocTest's globals are initialized with a copy of `globs`. u8DocTest no longer accepts str; use DocTestParser insteadN( u isinstanceustruAssertionErroruexamplesu docstringucopyuglobsunameufilenameulineno(uselfuexamplesuglobsunameufilenameulinenou docstring((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__’s     uDocTest.__init__cCslt|jƒdkrd}n1t|jƒdkr<d}ndt|jƒ}d|j|j|j|fS(Niu no examplesiu 1 exampleu %d examplesu(ulenuexamplesunameufilenameulineno(uselfuexamples((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__repr__ s  uDocTest.__repr__cCs†t|ƒt|ƒk rtS|j|jko…|j|jko…|j|jko…|j|jko…|j|jko…|j|jkS(N(utypeuNotImplementeduexamplesu docstringuglobsunameufilenameulineno(uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__eq__suDocTest.__eq__cCs ||k S(N((uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__ne__"suDocTest.__ne__cCs"t|j|j|j|jfƒS(N(uhashu docstringunameufilenameulineno(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__hash__%suDocTest.__hash__cCsSt|tƒstS|j|j|jt|ƒf|j|j|jt|ƒfkS(N(u isinstanceuDocTestuNotImplementedunameufilenameulinenouid(uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__lt__)suDocTest.__lt__N( u__name__u __module__u __qualname__u__doc__u__init__u__repr__u__eq__u__ne__u__hash__u__lt__(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyuDocTestēs   cBsū|EeZdZdZejdejejBƒZejdejejBej BƒZ ejdƒj Z ddd„Z dd „Zdd d „Zd d „ZejdejƒZdd„ZejdejƒZdd„Zdd„Zdd„ZdS(u DocTestParseruD A class used to parse strings containing doctest examples. uś # 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 )*) uß # 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. u ^[ ]*(#.*)?$uc s}|jƒ}|j|ƒ‰ˆdkrUdj‡fdd†|jdƒDƒƒ}ng}d \}}xų|jj|ƒD]ä}|j|||jƒ…ƒ||jd||jƒƒ7}|j |||ƒ\}}} } |j |ƒs-|jt || | d|dˆt |j dƒƒd|ƒƒn||jd|jƒ|jƒƒ7}|jƒ}qzW|j||d…ƒ|S( u= Divide the given string into examples and intervening text, and return them as a list of alternating Examples and strings. Line numbers for the Examples are 0-based. The optional argument `name` is a name identifying this string, and is only used for error messages. iu cs g|]}|ˆd…‘qS(N((u.0ul(u min_indent(u,/opt/alt/python33/lib64/python3.3/doctest.pyu ps u'DocTestParser.parse..ulinenouindentuoptionsN(ii(u expandtabsu _min_indentujoinusplitu _EXAMPLE_REufinditeruappendustartucountu_parse_exampleu_IS_BLANK_OR_COMMENTuExampleulenugroupuend( uselfustringunameuoutputucharnoulinenoumusourceuoptionsuwantuexc_msg((u min_indentu,/opt/alt/python33/lib64/python3.3/doctest.pyuparseds&  . ! %uDocTestParser.parsecCs%t|j||ƒ|||||ƒS(u" Extract all doctest examples from the given string, and collect them into a `DocTest` object. `globs`, `name`, `filename`, and `lineno` are attributes for the new `DocTest` object. See the documentation for `DocTest` for more information. (uDocTestu get_examples(uselfustringuglobsunameufilenameulineno((u,/opt/alt/python33/lib64/python3.3/doctest.pyu get_doctest‹s uDocTestParser.get_doctestcCsdd„|j||ƒDƒS(uŃ Extract all doctest examples from the given string, and return them as a list of `Example` objects. Line numbers are 0-based, because it's most common in doctests that nothing interesting appears on the same line as opening triple-quote, and so the first interesting line is called "line 1" then. The optional argument `name` is a name identifying this string, and is only used for error messages. cSs%g|]}t|tƒr|‘qS((u isinstanceuExample(u.0ux((u,/opt/alt/python33/lib64/python3.3/doctest.pyu ¢s u.DocTestParser.get_examples..(uparse(uselfustringuname((u,/opt/alt/python33/lib64/python3.3/doctest.pyu get_examples—s uDocTestParser.get_examplesc sxt|jdƒƒ‰|jdƒjdƒ}|j|ˆ||ƒ|j|dd…dˆd||ƒdj‡fdd †|Dƒƒ}|jd ƒ}|jdƒ}t|ƒdkrŻtjd |dƒrŻ|d=n|j|dˆ||t|ƒƒdj‡fd d †|Dƒƒ}|jj|ƒ}|rM|jd ƒ}nd}|j |||ƒ} || ||fS(u¼ Given a regular expression match from `_EXAMPLE_RE` (`m`), return a pair `(source, want)`, where `source` is the matched example's source code (with prompts and indentation stripped); and `want` is the example's expected output (with indentation stripped). `name` is the string's name, and `lineno` is the line number where the example starts; both are used for error messages. uindentusourceu iNu u.cs$g|]}|ˆdd…‘qS(iN((u.0usl(uindent(u,/opt/alt/python33/lib64/python3.3/doctest.pyu øs u0DocTestParser._parse_example..uwantu *$cs g|]}|ˆd…‘qS(N((u.0uwl(uindent(u,/opt/alt/python33/lib64/python3.3/doctest.pyu Ćs umsgi’’’’i’’’’( ulenugroupusplitu_check_prompt_blanku _check_prefixujoinureumatchu _EXCEPTION_REuNoneu _find_options( uselfumunameulinenou source_linesusourceuwantu want_linesuexc_msguoptions((uindentu,/opt/alt/python33/lib64/python3.3/doctest.pyu_parse_example„s$ ("( "uDocTestParser._parse_exampleu#\s*doctest:\s*([^\n\'"]*)$c Csųi}xŗ|jj|ƒD]¦}|jdƒjddƒjƒ}x||D]t}|ddkss|dd…tkr“td|d||fƒ‚nt|dd…}|ddk||ūs u-DocTestParser._min_indent..iN(u _INDENT_REufindallulenumin(uselfusuindents((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _min_indentłs uDocTestParser._min_indentc Cs€xyt|ƒD]k\}}t|ƒ|dkr ||ddkr td||d||||d…|fƒ‚q q WdS(u  Given the lines of a source string (including prompts and leading indentation), check to make sure that every prompt is followed by a space character. If any line is not followed by a space character, then raise ValueError. iiu u8line %r of the docstring for %s lacks blank after %s: %riN(u enumerateulenu ValueError(uselfulinesuindentunameulinenouiuline((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_check_prompt_blanks *u!DocTestParser._check_prompt_blankcCs[xTt|ƒD]F\}}|r |j|ƒ r td||d||fƒ‚q q WdS(uŽ Check that every line in the given list starts with the given prefix; if any line does not, then raise a ValueError. uGline %r of the docstring for %s has inconsistent leading whitespace: %riN(u enumerateu startswithu ValueError(uselfulinesuprefixunameulinenouiuline((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _check_prefixsuDocTestParser._check_prefixN(u__name__u __module__u __qualname__u__doc__ureucompileu MULTILINEuVERBOSEu _EXAMPLE_REuDOTALLu _EXCEPTION_REumatchu_IS_BLANK_OR_COMMENTuparseu get_doctestu get_examplesu_parse_exampleu_OPTION_DIRECTIVE_REu _find_optionsu _INDENT_REu _min_indentu_check_prompt_blanku _check_prefix(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu DocTestParser4s"   '  3     cBs}|EeZdZdZdeƒdddd„Zdddddd„Z dd„Z dd „Z d d „Z d d „Z dS(u DocTestFinderu< A class used to extract the DocTests that are relevant to a given object, from its docstring and the docstrings of its contained objects. Doctests can currently be extracted from the following object types: modules, functions, classes, methods, staticmethods, classmethods, and properties. cCs(||_||_||_||_dS(ut Create a new doctest finder. The optional argument `parser` specifies a class or function that should be used to create new DocTest objects (or objects that implement the same interface as DocTest). The signature for this factory function should match the signature of the DocTest constructor. If the optional argument `recurse` is false, then `find` will only examine the given object, and not any contained objects. If the optional argument `exclude_empty` is false, then `find` will include tests for objects with empty docstrings. N(u_parseru_verboseu_recurseu_exclude_empty(uselfuverboseuparserurecurseu exclude_empty((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__(s   uDocTestFinder.__init__c Csē|dkrIt|ddƒ}|dkrItdt|ƒfƒ‚qIn|dkr^d}n|dkr|tj|ƒ}nytj|ƒ}Wntk r©d}Yn—X|sétj |ƒ}|d|d d…dkséd}qén|dkržd}nB|dk r"t j ||j ƒ}nt j |ƒ}|s@d}n|dkrs|dkrai}q|j j ƒ}n |j ƒ}|dk r›|j|ƒnd|kr“d|du__main__Fiž’’’(uNoneugetattru ValueErrorutypeuFalseuinspectu getmoduleu getsourcefileu TypeErrorugetfileu linecacheugetlinesu__dict__ucopyuupdateu_findusort( uselfuobjunameumoduleuglobsu extraglobsufileu source_linesutests((u,/opt/alt/python33/lib64/python3.3/doctest.pyufind>sJ$                    uDocTestFinder.findcCsø|dkrdStj|ƒdk r8|tj|ƒkStj|ƒrW|j|jkStj|ƒrv|j|j kSt |dƒr•|j|j kSt |t ƒrØdSt dƒ‚dS(uY Return true if the given object is defined in the given module. u __module__u"object must be a class or functionNT(uNoneuTrueuinspectu getmoduleu isfunctionu__dict__u __globals__uisclassu__name__u __module__uhasattru isinstanceupropertyu ValueError(uselfumoduleuobject((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _from_module¤s uDocTestFinder._from_modulec Cs|jrtd|ƒnt|ƒ|kr0dSd|t|ƒ<|j|||||ƒ}|dk rw|j|ƒntj|ƒr|jrx‚|j j ƒD]n\} } d|| f} tj | ƒsŁtj | ƒrŸ|j || ƒrŸ|j|| | ||||ƒqŸqŸWntj|ƒr|jrxźt|diƒj ƒD]Ķ\} } t| tƒs|tdt| ƒfƒ‚ntj | ƒpÄtj | ƒpÄtj| ƒpÄtj| ƒpÄt| tƒsćtdt| ƒfƒ‚nd|| f} |j|| | ||||ƒqEWntj |ƒr |jr xÖ|j j ƒD]Ā\} } t| tƒrnt|| ƒ} nt| tƒr’t|| ƒj} ntj | ƒsætj | ƒsæt| tƒrA|j || ƒrAd|| f} |j|| | ||||ƒqAqAWndS( um Find tests for the given object and any contained objects, and add them to `tests`. uFinding tests in %sNiu%s.%su__test__u5DocTestFinder.find: __test__ keys must be strings: %ru`DocTestFinder.find: __test__ values must be strings, functions, methods, classes, or modules: %ru%s.__test__.%s(u_verboseuprintuidu _get_testuNoneuappenduinspectuismoduleu_recurseu__dict__uitemsu isfunctionuisclassu _from_moduleu_findugetattru isinstanceustru ValueErrorutypeuismethodu staticmethodu classmethodu__func__uproperty( uselfutestsuobjunameumoduleu source_linesuglobsuseenutestuvalnameuval((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_findøsP  %uDocTestFinder._findc Cst|tƒr|}ndyC|jdkr3d}n'|j}t|tƒsZt|ƒ}nWnttfk r{d}YnX|j||ƒ}|jr¢| r¢dS|dkr·d}n>t|d|j ƒ}|dd…d krõ|dd …}n|j j |||||ƒS( us Return a DocTest for the given object, if it defines a docstring; otherwise, return None. uu__file__iNu.pycu.pyoiiü’’’(u.pycu.pyoi’’’’( u isinstanceustru__doc__uNoneu TypeErroruAttributeErroru _find_linenou_exclude_emptyugetattru__name__u_parseru get_doctest( uselfuobjunameumoduleuglobsu source_linesu docstringulinenoufilename((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _get_test÷s(      uDocTestFinder._get_testcCs–d}tj|ƒrd}ntj|ƒr•|dkr=dStjdt|ddƒƒ}x6t|ƒD]%\}}|j|ƒri|}PqiqiWntj |ƒr°|j }ntj |ƒrĖ|j }ntj |ƒrę|j}ntj|ƒr|j}ntj|ƒr)t|ddƒd}n|dk r’|dkrI|dStjdƒ}x7t|t|ƒƒD]}|j||ƒrn|SqnWndS( u‹ Return a line number of the given object's docstring. Note: this method assumes that the object has a docstring. iu^\s*class\s*%s\bu__name__u-uco_firstlinenoiu(^|.*:)\s*\w*("|')N(uNoneuinspectuismoduleuisclassureucompileugetattru enumerateumatchuismethodu__func__u isfunctionu__code__u istracebackutb_frameuisframeuf_codeuiscodeurangeulen(uselfuobju source_linesulinenoupatuiuline((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _find_linenos<           uDocTestFinder._find_linenoNFT(u__name__u __module__u __qualname__u__doc__uFalseu DocTestParseruTrueu__init__uNoneufindu _from_moduleu_findu _get_testu _find_lineno(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu DocTestFinders f  ? %cBsŪ|EeZdZdZddZddddd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z ejdƒZddd„Zddddd„Zddd„Zdd„ZdS( u DocTestRunneru3 A class used to run DocTest test cases, and accumulate statistics. The `run` method is used to process a single DocTest case. It returns a tuple `(f, t)`, where `t` is the number of test cases tried, and `f` is the number of test cases that failed. >>> tests = DocTestFinder().find(_TestClass) >>> runner = DocTestRunner(verbose=False) >>> tests.sort(key = lambda test: test.name) >>> for test in tests: ... print(test.name, '->', runner.run(test)) _TestClass -> TestResults(failed=0, attempted=2) _TestClass.__init__ -> TestResults(failed=0, attempted=2) _TestClass.get -> TestResults(failed=0, attempted=2) _TestClass.square -> TestResults(failed=0, attempted=1) The `summarize` method prints a summary of all the test cases that have been run by the runner, and returns an aggregated `(f, t)` tuple: >>> runner.summarize(verbose=1) 4 items passed all tests: 2 tests in _TestClass 2 tests in _TestClass.__init__ 2 tests in _TestClass.get 1 tests in _TestClass.square 7 tests in 4 items. 7 passed and 0 failed. Test passed. TestResults(failed=0, attempted=7) The aggregated number of tried examples and failed examples is also available via the `tries` and `failures` attributes: >>> runner.tries 7 >>> runner.failures 0 The comparison between expected outputs and actual outputs is done by an `OutputChecker`. This comparison may be customized with a number of option flags; see the documentation for `testmod` for more information. If the option flags are insufficient, then the comparison may also be customized by passing a subclass of `OutputChecker` to the constructor. The test runner's display output can be controlled in two ways. First, an output function (`out) can be passed to `TestRunner.run`; this function will be called with strings that should be displayed. It defaults to `sys.stdout.write`. If capturing the output is not sufficient, then the display output can be also customized by subclassing DocTestRunner, and overriding the methods `report_start`, `report_success`, `report_unexpected_exception`, and `report_failure`. u*iFicCsv|p tƒ|_|dkr0dtjk}n||_||_||_d|_d|_ i|_ t ƒ|_ dS(uc Create a new test runner. Optional keyword arg `checker` is the `OutputChecker` that should be used to compare the expected outputs and actual outputs of doctest examples. Optional keyword arg 'verbose' prints lots of stuff if true, only failures if false; by default, it's true iff '-v' is in sys.argv. Optional argument `optionflags` can be used to control how the test runner compares expected output to actual output, and how it displays failures. See the documentation for `testmod` for more information. u-viN( u OutputCheckeru_checkeruNoneusysuargvu_verboseu optionflagsuoriginal_optionflagsutriesufailuresu_name2ftu _SpoofOutu_fakeout(uselfucheckeruverboseu optionflags((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__Œs       uDocTestRunner.__init__cCs_|jr[|jr=|dt|jƒdt|jƒƒq[|dt|jƒdƒndS(u‡ Report that the test runner is about to process the given example. (Only displays a message if verbose=True) uTrying: u Expecting: uExpecting nothing N(u_verboseuwantu_indentusource(uselfuoututestuexample((u,/opt/alt/python33/lib64/python3.3/doctest.pyu report_start°s   (uDocTestRunner.report_startcCs|jr|dƒndS(ut Report that the given example ran successfully. (Only displays a message if verbose=True) uok N(u_verbose(uselfuoututestuexampleugot((u,/opt/alt/python33/lib64/python3.3/doctest.pyureport_success½s uDocTestRunner.report_successcCs3||j||ƒ|jj|||jƒƒdS(u7 Report that the given example failed. N(u_failure_headeru_checkeruoutput_differenceu optionflags(uselfuoututestuexampleugot((u,/opt/alt/python33/lib64/python3.3/doctest.pyureport_failureÅsuDocTestRunner.report_failurecCs.||j||ƒdtt|ƒƒƒdS(uO Report that the given example raised an unexpected exception. uException raised: N(u_failure_headeru_indentu_exception_traceback(uselfuoututestuexampleuexc_info((u,/opt/alt/python33/lib64/python3.3/doctest.pyureport_unexpected_exceptionĢsu)DocTestRunner.report_unexpected_exceptioncCsŹ|jg}|jrs|jdk rJ|jdk rJ|j|jd}nd}|jd|j||jfƒn!|jd|jd|jfƒ|jdƒ|j}|jt|ƒƒdj|ƒS(Niu?uFile "%s", line %s, in %suLine %s, in %suFailed example:u ( uDIVIDERufilenameulinenouNoneuappendunameusourceu_indentujoin(uselfutestuexampleuoutulinenousource((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_failure_headerÓs   !  uDocTestRunner._failure_headercCsjd}}|j}tdƒ\}}} |jj} x t|jƒD]ł\} } |jt@of|dk} ||_| jrĘxH| jjƒD]4\}}|rÆ|j|O_q‹|j|M_q‹Wn|jt @rŁqDn|d7}| s’|j ||| ƒnd|j | f}y<t t | j|d|dƒ|jƒ|jjƒd}Wn5tk re‚Yn!tjƒ}|jjƒYnX|jjƒ}|jjdƒ|}|dkrŪ| | j||jƒr‡|}q‡n¬tj|dd…Œd }| s|t|ƒ7}n| jdkr)| }n^| | j||jƒrJ|}n=|jt@r‡| t| jƒt|ƒ|jƒr‡|}q‡n||krµ| s=|j ||| |ƒq=qD||krķ| są|j!||| |ƒn|d7}qD|| kr%| s|j"||| |ƒn|d7}qDd sDt$d|fƒ‚qDW||_|j%|||ƒt&||ƒS( uŅ Run the examples in `test`. Write the outcome of each example with one of the `DocTestRunner.report_*` methods, using the writer function `out`. `compileflags` is the set of compiler flags that should be used to execute examples. Return a tuple `(f, t)`, where `t` is the number of examples tried, and `f` is the number of examples that failed. The examples are run in the namespace `test.globs`. iiiuusingleNiuunknown outcomei’’’’F('u optionflagsurangeu_checkeru check_outputu enumerateuexamplesuREPORT_ONLY_FIRST_FAILUREuoptionsuitemsuSKIPu report_startunameuexecucompileusourceuglobsudebuggeru set_continueuNoneuKeyboardInterruptusysuexc_infou_fakeoutugetvalueutruncateuwantu tracebackuformat_exception_onlyu_exception_tracebackuexc_msguIGNORE_EXCEPTION_DETAILu_strip_exception_detailsureport_successureport_failureureport_unexpected_exceptionuFalseuAssertionErroru_DocTestRunner__record_outcomeu TestResults(uselfutestu compileflagsuoutufailuresutriesuoriginal_optionflagsuSUCCESSuFAILUREuBOOMuchecku examplenumuexampleuquietu optionflaguvalufilenameu exceptionugotuoutcomeuexc_msg((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__runēs~                            uDocTestRunner.__runcCs^|jj|jdƒ\}}||||f|j|j<|j|7_|j|7_dS(u{ Record the fact that the given DocTest (`test`) generated `f` failures out of `t` tried examples. iN(ii(u_name2ftugetunameufailuresutries(uselfutestufutuf2ut2((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__record_outcomeasuDocTestRunner.__record_outcomeu..+)\[(?P\d+)\]>$cCsy|jj|ƒ}|re|jdƒ|jjkre|jjt|jdƒƒ}|jjddƒS|j ||ƒSdS(Nunameu examplenumukeependsT( u%_DocTestRunner__LINECACHE_FILENAME_REumatchugrouputestunameuexamplesuintusourceu splitlinesuTrueusave_linecache_getlines(uselfufilenameumodule_globalsumuexample((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__patched_linecache_getlinesns !u*DocTestRunner.__patched_linecache_getlinesc s~||_|dkr't|jƒ}ntj‰|dkr‡ˆj‰ˆdkscˆjƒdkroˆj}q‡‡‡fdd†}n|j t_tj ƒ}t j }t ˆƒ|_|jjƒ|jj t _ tj|_|jt_tj}tjt_z|j|||ƒSWdˆt_|t _ tj|ƒ|jt_|t_|ry|jjƒddl}d|_nXdS(uJ Run the examples in `test`, and display the results using the writer function `out`. The examples are run in the namespace `test.globs`. If `clear_globs` is true (the default), then this namespace will be cleared after the test runs, to help with garbage collection. If you would like to examine the namespace after the test completes, then use `clear_globs=False`. `compileflags` gives the set of flags that should be used by the Python compiler when running the examples. If not specified, then it will default to the set of future-import flags that apply to `globs`. The output of each example is checked using `DocTestRunner.check_output`, and the results are formatted by the `DocTestRunner.report_*` methods. uutf-8cs,t|jˆdƒˆƒ}ˆj|ƒdS(Nubackslashreplace(ustruencodeuwrite(us(uencodingu save_stdout(u,/opt/alt/python33/lib64/python3.3/doctest.pyuout–suDocTestRunner.run..outNi(utestuNoneu_extract_future_flagsuglobsusysustdoutuencodinguloweruwriteu_fakeoutugettraceupdbu set_traceu_OutputRedirectingPdbudebuggeruresetu linecacheugetlinesusave_linecache_getlinesu*_DocTestRunner__patched_linecache_getlinesu displayhooku__displayhook__u_DocTestRunner__runusettraceuclearubuiltinsu_( uselfutestu compileflagsuoutu clear_globsu save_traceusave_set_traceusave_displayhookubuiltins((uencodingu save_stdoutu,/opt/alt/python33/lib64/python3.3/doctest.pyurunvs<                     uDocTestRunner.runc CsK|dkr|j}ng}g}g}d}}xš|jjƒD]‰}|\}\} } | | ksnt‚|| 7}|| 7}| dkrž|j|ƒqD| dkrĄ|j|| fƒqD|j|ƒqDW|ro|rtt|ƒdƒ|jƒx|D]} td| ƒqWn|rott|ƒdƒ|jƒx+|D] \} } td| | fƒqEWqon|rÖt|j ƒtt|ƒdƒ|jƒx4|D])\} \} } td| | | fƒq¦Wn|rt|dt|jƒd ƒt||d |d ƒn|r+td |d ƒn|r>tdƒnt ||ƒS(u¦ Print a summary of all the test cases that have been run by this DocTestRunner, and return a tuple `(f, t)`, where `f` is the total number of failed examples, and `t` is the total number of tried examples. The optional `verbose` argument controls how detailed the summary is. If the verbosity is not specified, then the DocTestRunner's verbosity is used. iuitems had no tests:u uitems passed all tests:u %3d tests in %suitems had failures:u %3d of %3d in %sutests inuitems.u passed andufailed.u***Test Failed***u failures.u Test passed.N( uNoneu_verboseu_name2ftuitemsuAssertionErroruappenduprintulenusortuDIVIDERu TestResults( uselfuverboseunotestsupassedufailedutotaltutotalfuxunameufututhingucount((u,/opt/alt/python33/lib64/python3.3/doctest.pyu summarizeæsR             uDocTestRunner.summarizecCsv|j}xf|jjƒD]U\}\}}||kr^||\}}||}||}n||f||‹s u3OutputChecker.output_difference..uDifferences (%s): uuExpected: %sGot: %suExpected: %sGot nothing uExpected nothing Got: %suExpected nothing Got nothing T(uwantuDONT_ACCEPT_BLANKLINEureusubuBLANKLINE_MARKERu_do_a_fancy_diffu splitlinesuTrueu REPORT_UDIFFudifflibu unified_diffulistu REPORT_CDIFFu context_diffu REPORT_NDIFFuDifferuIS_CHARACTER_JUNKucompareuAssertionErroru_indentujoin( uselfuexampleugotu optionflagsuwantu want_linesu got_linesudiffukinduengine((u,/opt/alt/python33/lib64/python3.3/doctest.pyuoutput_differenceis8         uOutputChecker.output_differenceN(u__name__u __module__u __qualname__u__doc__u_toAsciiu check_outputu_do_a_fancy_diffuoutput_difference(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu OutputCheckers   ? cBs2|EeZdZdZdd„Zdd„ZdS(uDocTestFailureuÖA DocTest example has failed in debugging mode. The exception instance has variables: - test: the DocTest object being run - example: the Example object that failed - got: the actual output cCs||_||_||_dS(N(utestuexampleugot(uselfutestuexampleugot((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__¤s  uDocTestFailure.__init__cCs t|jƒS(N(ustrutest(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__str__©suDocTestFailure.__str__N(u__name__u __module__u __qualname__u__doc__u__init__u__str__(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyuDocTestFailure™s  cBs2|EeZdZdZdd„Zdd„ZdS(uUnexpectedExceptionuęA DocTest example has encountered an unexpected exception The exception instance has variables: - test: the DocTest object being run - example: the Example object that failed - exc_info: the exception info cCs||_||_||_dS(N(utestuexampleuexc_info(uselfutestuexampleuexc_info((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__·s  uUnexpectedException.__init__cCs t|jƒS(N(ustrutest(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__str__¼suUnexpectedException.__str__N(u__name__u __module__u __qualname__u__doc__u__init__u__str__(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyuUnexpectedException¬s  cBsG|EeZdZdZddd dd„Zdd„Zdd„ZdS( u DebugRunneru‹ Run doc tests but raise an exception as soon as there is a failure. If an unexpected exception occurs, an UnexpectedException is raised. It contains the test, the example, and the original exception: >>> runner = DebugRunner(verbose=False) >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42', ... {}, 'foo', 'foo.py', 0) >>> try: ... runner.run(test) ... except UnexpectedException as f: ... failure = f >>> failure.test is test True >>> failure.example.want '42\n' >>> exc_info = failure.exc_info >>> raise exc_info[1] # Already has the traceback Traceback (most recent call last): ... KeyError We wrap the original exception to give the calling application access to the test and example information. If the output doesn't match, then a DocTestFailure is raised: >>> test = DocTestParser().get_doctest(''' ... >>> x = 1 ... >>> x ... 2 ... ''', {}, 'foo', 'foo.py', 0) >>> try: ... runner.run(test) ... except DocTestFailure as f: ... failure = f DocTestFailure objects provide access to the test: >>> failure.test is test True As well as to the example: >>> failure.example.want '2\n' and the actual output: >>> failure.got '1\n' If a failure or error occurs, the globals are left intact: >>> del test.globs['__builtins__'] >>> test.globs {'x': 1} >>> test = DocTestParser().get_doctest(''' ... >>> x = 2 ... >>> raise KeyError ... ''', {}, 'foo', 'foo.py', 0) >>> runner.run(test) Traceback (most recent call last): ... doctest.UnexpectedException: >>> del test.globs['__builtins__'] >>> test.globs {'x': 2} But the globals are cleared if there is no error: >>> test = DocTestParser().get_doctest(''' ... >>> x = 2 ... ''', {}, 'foo', 'foo.py', 0) >>> runner.run(test) TestResults(failed=0, attempted=1) >>> test.globs {} cCs5tj||||dƒ}|r1|jjƒn|S(NF(u DocTestRunnerurunuFalseuglobsuclear(uselfutestu compileflagsuoutu clear_globsur((u,/opt/alt/python33/lib64/python3.3/doctest.pyurunsuDebugRunner.runcCst|||ƒ‚dS(N(uUnexpectedException(uselfuoututestuexampleuexc_info((u,/opt/alt/python33/lib64/python3.3/doctest.pyureport_unexpected_exception su'DebugRunner.report_unexpected_exceptioncCst|||ƒ‚dS(N(uDocTestFailure(uselfuoututestuexampleugot((u,/opt/alt/python33/lib64/python3.3/doctest.pyureport_failure#suDebugRunner.report_failureNT( u__name__u __module__u __qualname__u__doc__uNoneuTrueurunureport_unexpected_exceptionureport_failure(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu DebugRunneræsY c Cs|dkr!tjjdƒ}ntj|ƒsFtd|fƒ‚n|dkr^|j}ntd|ƒ} |r‹t d|d|ƒ} nt d|d|ƒ} x3| j ||d|d|ƒD]} | j | ƒqæW|ré| j ƒntdkrž| an tj| ƒt| j| jƒS( u* m=None, name=None, globs=None, verbose=None, report=True, optionflags=0, extraglobs=None, raise_on_error=False, exclude_empty=False Test examples in docstrings in functions and classes reachable from module m (or the current module if m is not supplied), starting with m.__doc__. Also test examples reachable from dict m.__test__ if it exists and is not None. m.__test__ maps names to functions, classes and strings; function and class docstrings are tested even if the name is private; strings are tested directly, as if they were docstrings. Return (#failures, #tests). See help(doctest) for an overview. Optional keyword arg "name" gives the name of the module; by default use m.__name__. Optional keyword arg "globs" gives a dict to be used as the globals when executing examples; by default, use m.__dict__. A copy of this dict is actually used for each docstring, so that each docstring's examples start with a clean slate. Optional keyword arg "extraglobs" gives a dictionary that should be merged into the globals that are used to execute examples. By default, no extra globals are used. This is new in 2.4. Optional keyword arg "verbose" prints lots of stuff if true, prints only failures if false; by default, it's true iff "-v" is in sys.argv. Optional keyword arg "report" prints a summary at the end when true, else prints nothing at the end. In verbose mode, the summary is detailed, else very brief (in fact, empty if all tests passed). Optional keyword arg "optionflags" or's together module constants, and defaults to 0. This is new in 2.3. Possible values (see the docs for details): DONT_ACCEPT_TRUE_FOR_1 DONT_ACCEPT_BLANKLINE NORMALIZE_WHITESPACE ELLIPSIS SKIP IGNORE_EXCEPTION_DETAIL REPORT_UDIFF REPORT_CDIFF REPORT_NDIFF REPORT_ONLY_FIRST_FAILURE Optional keyword arg "raise_on_error" raises an exception on the first unexpected exception or failure. This allows failures to be post-mortem debugged. Advanced tomfoolery: testmod runs methods of a local instance of class doctest.Tester, then merges the results into (or creates) global Tester instance doctest.master. Methods of doctest.master can be called directly too, if you want to do something unusual. Passing report=0 to testmod is especially useful then, to delay displaying a summary. Invoke doctest.master.summarize(verbose) when you're done fiddling. u__main__utestmod: module required; %ru exclude_emptyuverboseu optionflagsuglobsu extraglobsN(uNoneusysumodulesugetuinspectuismoduleu TypeErroru__name__u DocTestFinderu DebugRunneru DocTestRunnerufindurunu summarizeumasterumergeu TestResultsufailuresutries( umunameuglobsuverboseureportu optionflagsu extraglobsuraise_on_erroru exclude_emptyufinderurunnerutest((u,/opt/alt/python33/lib64/python3.3/doctest.pyutestmod/s$E   %    c CsW|r| rtdƒ‚nt|||| p1dƒ\} }|dkr^tjj|ƒ}n|dkrsi}n |jƒ}|dk r›|j|ƒnd|kr“d|d>> import doctest >>> old = doctest._unittest_reportflags >>> doctest.set_unittest_reportflags(REPORT_NDIFF | ... REPORT_ONLY_FIRST_FAILURE) == old True >>> doctest._unittest_reportflags == (REPORT_NDIFF | ... REPORT_ONLY_FIRST_FAILURE) True Only reporting flags can be set: >>> doctest.set_unittest_reportflags(ELLIPSIS) Traceback (most recent call last): ... ValueError: ('Only reporting flags allowed', 8) >>> doctest.set_unittest_reportflags(old) == (REPORT_NDIFF | ... REPORT_ONLY_FIRST_FAILURE) True uOnly reporting flags allowed(uREPORTING_FLAGSu ValueErroru_unittest_reportflags(uflagsuold((u,/opt/alt/python33/lib64/python3.3/doctest.pyuset_unittest_reportflags/s cBs¶|EeZdZdddddd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„ZeZdd„ZdS(u DocTestCaseicCsAtjj|ƒ||_||_||_||_||_dS(N(uunittestuTestCaseu__init__u_dt_optionflagsu _dt_checkeru_dt_testu _dt_setUpu _dt_tearDown(uselfutestu optionflagsusetUputearDownuchecker((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__Us     uDocTestCase.__init__cCs,|j}|jdk r(|j|ƒndS(N(u_dt_testu _dt_setUpuNone(uselfutest((u,/opt/alt/python33/lib64/python3.3/doctest.pyusetUp_s uDocTestCase.setUpcCs9|j}|jdk r(|j|ƒn|jjƒdS(N(u_dt_testu _dt_tearDownuNoneuglobsuclear(uselfutest((u,/opt/alt/python33/lib64/python3.3/doctest.pyutearDownes uDocTestCase.tearDownc CsĘ|j}tj}tƒ}|j}|t@s;|tO}ntd|d|jddƒ}z5dd|_ |j |d|j ddƒ\}}Wd|t_X|rĀ|j |j|jƒƒƒ‚ndS( Nu optionflagsucheckeruverboseu-iFuoutu clear_globsF(u_dt_testusysustdoutuStringIOu_dt_optionflagsuREPORTING_FLAGSu_unittest_reportflagsu DocTestRunneru _dt_checkeruFalseuDIVIDERurunuwriteufailureExceptionuformat_failureugetvalue(uselfutestuoldunewu optionflagsurunnerufailuresutries((u,/opt/alt/python33/lib64/python3.3/doctest.pyurunTestms        " uDocTestCase.runTestcCsp|j}|jdkr!d}n d|j}dj|jjdƒdd…ƒ}d|j|j|||fS(Nuunknown line numberu%su.iu:Failed doctest test for %s File "%s", line %s, in %s %si’’’’(u_dt_testulinenouNoneujoinunameusplitufilename(uselfuerrutestulinenoulname((u,/opt/alt/python33/lib64/python3.3/doctest.pyuformat_failure…s   %uDocTestCase.format_failurecCsO|jƒtd|jd|jddƒ}|j|jddƒ|jƒdS(uŅRun the test case without results and without catching exceptions The unit test framework includes a debug method on test cases and test suites to support post-mortem debugging. The test code is run in such a way that errors are not caught. This way a caller can catch the errors and initiate post-mortem debugging. The DocTestCase provides a debug method that raises UnexpectedException errors if there is an unexpected exception: >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42', ... {}, 'foo', 'foo.py', 0) >>> case = DocTestCase(test) >>> try: ... case.debug() ... except UnexpectedException as f: ... failure = f The UnexpectedException contains the test, the example, and the original exception: >>> failure.test is test True >>> failure.example.want '42\n' >>> exc_info = failure.exc_info >>> raise exc_info[1] # Already has the traceback Traceback (most recent call last): ... KeyError If the output doesn't match, then a DocTestFailure is raised: >>> test = DocTestParser().get_doctest(''' ... >>> x = 1 ... >>> x ... 2 ... ''', {}, 'foo', 'foo.py', 0) >>> case = DocTestCase(test) >>> try: ... case.debug() ... except DocTestFailure as f: ... failure = f DocTestFailure objects provide access to the test: >>> failure.test is test True As well as to the example: >>> failure.example.want '2\n' and the actual output: >>> failure.got '1\n' u optionflagsucheckeruverboseu clear_globsNF(usetUpu DebugRunneru_dt_optionflagsu _dt_checkeruFalseurunu_dt_testutearDown(uselfurunner((u,/opt/alt/python33/lib64/python3.3/doctest.pyudebug‘s B uDocTestCase.debugcCs |jjS(N(u_dt_testuname(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyuidŁsuDocTestCase.idcCstt|ƒt|ƒk rtS|j|jkos|j|jkos|j|jkos|j|jkos|j|jkS(N(utypeuNotImplementedu_dt_testu_dt_optionflagsu _dt_setUpu _dt_tearDownu _dt_checker(uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__eq__ÜsuDocTestCase.__eq__cCs ||k S(N((uselfuother((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__ne__ęsuDocTestCase.__ne__cCs"t|j|j|j|jfƒS(N(uhashu_dt_optionflagsu _dt_setUpu _dt_tearDownu _dt_checker(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__hash__ésuDocTestCase.__hash__cCs:|jjjdƒ}d|ddj|dd…ƒfS(Nu.u%s (%s)ii’’’’i’’’’(u_dt_testunameusplitujoin(uselfuname((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__repr__ķsuDocTestCase.__repr__cCsd|jjS(Nu Doctest: (u_dt_testuname(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyushortDescriptionósuDocTestCase.shortDescriptionN(u__name__u __module__u __qualname__uNoneu__init__usetUputearDownurunTestuformat_failureudebuguidu__eq__u__ne__u__hash__u__repr__u__str__ushortDescription(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu DocTestCaseSs     H    u DocTestCasecBsJ|EeZdZdd„Zdd„Zdd„Zdd„ZeZd S( uSkipDocTestCasecCs||_tj|dƒdS(N(umoduleu DocTestCaseu__init__uNone(uselfumodule((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__÷s uSkipDocTestCase.__init__cCs|jdƒdS(Nu-DocTestSuite will not work with -O2 and above(uskipTest(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyusetUpūsuSkipDocTestCase.setUpcCsdS(N((uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu test_skipžsuSkipDocTestCase.test_skipcCsd|jjS(NuSkipping tests from %s(umoduleu__name__(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyushortDescription su SkipDocTestCase.shortDescriptionN(u__name__u __module__u __qualname__u__init__usetUpu test_skipushortDescriptionu__str__(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyuSkipDocTestCaseös     uSkipDocTestCasec Ks6|dkrtƒ}nt|ƒ}|j|d|d|ƒ}| r{tjjdkr{tjƒ}|j t |ƒƒ|S|s“t |dƒ‚n|j ƒtjƒ}x†|D]~}t |jƒdkrŃq°n|js|j}|d d…d kr |dd …}n||_n|j t||ƒq°W|S(u Convert doctest tests for a module to a unittest test suite. This converts each documentation string in a module that contains doctest tests to a unittest test case. If any of the tests in a doc string fail, then the test case fails. An exception is raised showing the name of the file containing the test and a (sometimes approximate) line number. The `module` argument provides the module to be tested. The argument can be either a module or a module name. If no argument is given, the calling module is used. A number of options may be provided as keyword arguments: setUp A set-up function. This is called before running the tests in each file. The setUp function will be passed a DocTest object. The setUp function can access the test globals as the globs attribute of the test passed. tearDown A tear-down function. This is called after running the tests in each file. The tearDown function will be passed a DocTest object. The tearDown function can access the test globals as the globs attribute of the test passed. globs A dictionary containing initial global variables for the tests. optionflags A set of doctest option flags expressed as an integer. uglobsu extraglobsiuhas no docstringsiiNu.pycu.pyoiiü’’’(u.pycu.pyoi’’’’(uNoneu DocTestFinderu_normalize_moduleufindusysuflagsuoptimizeuunittestu TestSuiteuaddTestuSkipDocTestCaseu ValueErrorusortulenuexamplesufilenameu__file__u DocTestCase( umoduleuglobsu extraglobsu test_finderuoptionsutestsusuiteutestufilename((u,/opt/alt/python33/lib64/python3.3/doctest.pyu DocTestSuite s,%          cBs>|EeZdZdd„Zdd„ZeZdd„ZdS(u DocFileCasecCsdj|jjjdƒƒS(Nu_u.(ujoinu_dt_testunameusplit(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyuidR suDocFileCase.idcCs |jjS(N(u_dt_testufilename(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__repr__U suDocFileCase.__repr__cCsd|jj|jj|fS(Nu2Failed doctest test for %s File "%s", line 0 %s(u_dt_testunameufilename(uselfuerr((u,/opt/alt/python33/lib64/python3.3/doctest.pyuformat_failureY suDocFileCase.format_failureN(u__name__u __module__u __qualname__uidu__repr__u__str__uformat_failure(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu DocFileCaseP s  u DocFileCasec Ks±|dkri}n |jƒ}|r=| r=tdƒ‚nt||||pRdƒ\}}d|krw||d>> text = ''' ... Here are examples of simple math. ... ... Python has super accurate integer addition ... ... >>> 2 + 2 ... 5 ... ... And very friendly error messages: ... ... >>> 1/0 ... To Infinity ... And ... Beyond ... ... You can use logic if you want: ... ... >>> if 0: ... ... blah ... ... blah ... ... ... ... Ho hum ... ''' >>> print(script_from_examples(text)) # Here are examples of simple math. # # Python has super accurate integer addition # 2 + 2 # Expected: ## 5 # # And very friendly error messages: # 1/0 # Expected: ## To Infinity ## And ## Beyond # # You can use logic if you want: # if 0: blah blah # # Ho hum Niu # Expected:cSsg|]}d|‘qS(u## ((u.0ul((u,/opt/alt/python33/lib64/python3.3/doctest.pyu  s u(script_from_examples..u cSsg|]}t|ƒ‘qS((u _comment_line(u.0ul((u,/opt/alt/python33/lib64/python3.3/doctest.pyu  s u#ii’’’’i’’’’i’’’’i’’’’( u DocTestParseruparseu isinstanceuExampleuappendusourceuwantusplitupopujoin(usuoutputupieceuwant((u,/opt/alt/python33/lib64/python3.3/doctest.pyuscript_from_examplesĮ s:  0 "cslt|ƒ}tƒj|ƒ}‡fdd†|Dƒ}|sOtˆdƒ‚n|d}t|jƒ}|S(uExtract the test sources from a doctest docstring as a script. Provide the module (or dotted name of the module) containing the test to be debugged and the name (within the module) of the object with the doc string with tests to be debugged. cs%g|]}|jˆkr|‘qS((uname(u.0ut(uname(u,/opt/alt/python33/lib64/python3.3/doctest.pyu  s utestsource..unot found in testsi(u_normalize_moduleu DocTestFinderufindu ValueErroruscript_from_examplesu docstring(umoduleunameutestsutestutestsrc((unameu,/opt/alt/python33/lib64/python3.3/doctest.pyu testsource s  cCs t|ƒ}t|||ƒdS(u4Debug a single doctest docstring, in argument `src`'N(uscript_from_examplesu debug_script(usrcupmuglobsutestsrc((u,/opt/alt/python33/lib64/python3.3/doctest.pyu debug_src# s c CsĄddl}|r!|jƒ}ni}|r™yt|||ƒWq¼ttjƒdƒ|jddƒ}|jƒ|j dtjƒdƒYq¼Xn#|jddƒj d|||ƒdS(u7Debug a test script. `src` is the script, as a string.iNiunosigintiuexec(%r)T( updbucopyuexecuprintusysuexc_infouPdbuTrueuresetu interactionuNoneurun(usrcupmuglobsupdbup((u,/opt/alt/python33/lib64/python3.3/doctest.pyu debug_script( s  "u debug_scriptcCs2t|ƒ}t||ƒ}t|||jƒdS(uåDebug a single doctest docstring. Provide the module (or dotted name of the module) containing the test to be debugged and the name (within the module) of the object with the docstring with tests to be debugged. N(u_normalize_moduleu testsourceu debug_scriptu__dict__(umoduleunameupmutestsrc((u,/opt/alt/python33/lib64/python3.3/doctest.pyudebug< s cBs>|EeZdZdZdd„Zdd„Zdd„ZdS( u _TestClassuå A pointless class, for sanity-checking of docstring testing. Methods: square() get() >>> _TestClass(13).get() + _TestClass(-12).get() 1 >>> hex(_TestClass(13).square().get()) '0xa9' cCs ||_dS(u„val -> _TestClass object with associated value val. >>> t = _TestClass(123) >>> print(t.get()) 123 N(uval(uselfuval((u,/opt/alt/python33/lib64/python3.3/doctest.pyu__init__X su_TestClass.__init__cCs|jd|_|S(uosquare() -> square TestClass's associated value >>> _TestClass(13).square().get() 169 i(uval(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyusquareb su_TestClass.squarecCs|jS(u~get() -> return TestClass's associated value. >>> x = _TestClass(-42) >>> print(x.get()) -42 (uval(uself((u,/opt/alt/python33/lib64/python3.3/doctest.pyugetl su_TestClass.getN(u__name__u __module__u __qualname__u__doc__u__init__usquareuget(u __locals__((u,/opt/alt/python33/lib64/python3.3/doctest.pyu _TestClassJ s  u _TestClassuÄ Example of a string object, searched as-is. >>> x = 1; y = 2 >>> x + y, x * y (3, 2) ustringuÜ 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 ubool-int equivalenceuē Blank lines can be marked with : >>> print('foo\n\nbar\n') foo bar u blank linesuś 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] uellipsisuƒ 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] uwhitespace normalizationcCs&dd„tjdd…Dƒ}|s€tjjtjdƒ}dtƒkritjj|ƒ\}}ntdj|ƒƒdSxŸ|D]—}|j dƒrütjj |ƒ\}}tjj d|ƒt |dd …ƒ}tjd=t |ƒ\}}nt|d d ƒ\}}|r‡dSq‡WdS( NcSs,g|]"}|r|ddkr|‘qS(iu-((u.0uarg((u,/opt/alt/python33/lib64/python3.3/doctest.pyu Ŗ s u_test..iiu __loader__uusage: {0} [-v] file ...iu.pyiumodule_relativeiż’’’F(usysuargvuosupathubasenameuglobalsusplitextuprintuformatuendswithusplituinsertu __import__utestmodutestfileuFalse(u testfilesunameu_ufilenameudirnameumufailures((u,/opt/alt/python33/lib64/python3.3/doctest.pyu_test© s$   u_testu__main__(Ru__doc__u __docformat__u__all__u __future__udifflibuinspectu linecacheuosupdbureusysu tracebackuunittestuiouStringIOu collectionsu namedtupleu TestResultsuOPTIONFLAGS_BY_NAMEuregister_optionflaguDONT_ACCEPT_TRUE_FOR_1uDONT_ACCEPT_BLANKLINEuNORMALIZE_WHITESPACEuELLIPSISuSKIPuIGNORE_EXCEPTION_DETAILuCOMPARISON_FLAGSu REPORT_UDIFFu REPORT_CDIFFu REPORT_NDIFFuREPORT_ONLY_FIRST_FAILUREuREPORTING_FLAGSuBLANKLINE_MARKERuELLIPSIS_MARKERu_extract_future_flagsu_normalize_moduleu_load_testfileu_indentu_exception_tracebacku _SpoofOutu_ellipsis_matchu _comment_lineu_strip_exception_detailsuPdbu_OutputRedirectingPdbu_module_relative_pathuExampleuDocTestu DocTestParseru DocTestFinderu DocTestRunneru OutputCheckeru ExceptionuDocTestFailureuUnexpectedExceptionu DebugRunneruNoneumasteruTrueuFalseutestmodutestfileurun_docstring_examplesu_unittest_reportflagsuset_unittest_reportflagsuTestCaseu DocTestCaseuSkipDocTestCaseu DocTestSuiteu DocFileCaseu DocFileTestu DocFileSuiteuscript_from_examplesu testsourceu debug_srcu debug_scriptudebugu _TestClassu__test__u_testu__name__uexit(((u,/opt/alt/python33/lib64/python3.3/doctest.pyu.sņ                           1  % $GMė’2’¶”n  f   x $£I  I R ,