%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2318/lib/python3.8/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2318/lib/python3.8/__pycache__/doctest.cpython-38.pyc

U

k�]e_��!@stdZdZdddddddd	d
ddd
ddddddddddddddddddd d!d"g!Zd#d$lZd#d$lZd#d$lZd#d$lZd#d$lZd#d$lZd#d$l	Z	d#d$l
Z
d#d$lZd#d$lZd#d%l
mZd#d&lmZed'd(�ZiZd)d�Zed�Zed�Zed�Zed�Zed�Zed�ZeeBeBeBeBeBZed
�Zed�Zed�Zed
�Zed�ZeeBeBeBeBZ d*Z!d+Z"d,d-�Z#dsd/d0�Z$d1d2�Z%d3d4�Z&dtd6d7�Z'd8d9�Z(Gd:d;�d;e�Z)d<d=�Z*d>d?�Z+d@dA�Z,GdBdC�dCej-�Z.dDdE�Z/GdFd�d�Z0GdGd�d�Z1GdHd�d�Z2GdId�d�Z3GdJd�d�Z4GdKd�d�Z5GdLd�de6�Z7GdMd�de6�Z8GdNd�de4�Z9d$a:dudQd�Z;dOd$d$d$d$dOd#d$dPe2�d$fdRd�Z<dvdTd�Z=d#a>dUd�Z?GdVdW�dWej@�ZAGdXdY�dYeA�ZBGdZd[�d[ejC�ZDdwd\d�ZEGd]d^�d^eA�ZFdOd$d$e2�d$fd_d`�ZGdad�ZHdbd�ZIdcd �ZJdxddd!�ZKdydedf�ZLdzdgd"�ZMGdhdi�di�ZNeNdjdkdldmdndo�ZOdpdq�ZPeQdrk�rpe
�ReP��d$S){a�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.
zreStructuredText en�register_optionflag�DONT_ACCEPT_TRUE_FOR_1�DONT_ACCEPT_BLANKLINE�NORMALIZE_WHITESPACE�ELLIPSIS�SKIP�IGNORE_EXCEPTION_DETAIL�COMPARISON_FLAGS�REPORT_UDIFF�REPORT_CDIFF�REPORT_NDIFF�REPORT_ONLY_FIRST_FAILURE�REPORTING_FLAGS�	FAIL_FAST�Example�DocTest�
DocTestParser�
DocTestFinder�
DocTestRunner�
OutputChecker�DocTestFailure�UnexpectedException�DebugRunner�testmod�testfile�run_docstring_examples�DocTestSuite�DocFileSuite�set_unittest_reportflags�script_from_examples�
testsource�	debug_src�debug�N)�StringIO)�
namedtuple�TestResultszfailed attemptedcCst�|dtt�>�S)N�)�OPTIONFLAGS_BY_NAME�
setdefault�len��name�r,�/usr/lib/python3.8/doctest.pyr�sz<BLANKLINE>z...cCs8d}tjD](}|�|d�}|tt|�kr
||jO}q
|S)z�
    Return the compiler-flags associated with the future features that
    have been imported into the given namespace (globs).
    r"N)�
__future__Zall_feature_names�get�getattrZ
compiler_flag)�globs�flagsZfnameZfeaturer,r,r-�_extract_future_flags�s
r3�cCsVt�|�r|St|t�r,t|t�t�dg�S|dkrJtjt�	|�j
dStd��dS)a�
    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.
    �*N�__name__z"Expected a module, string, or None)�inspect�ismodule�
isinstance�str�
__import__�globals�locals�sys�modules�	_getframe�	f_globals�	TypeError)�moduleZdepthr,r,r-�_normalize_module�s


rDcCsdD]}|�|d�}q|S)N)z
�
�
)�replace)�data�newliner,r,r-�_newline_convert�srJc
Cs�|rVt|d�}t||�}t|dd�dk	rVt|jd�rV|j�|�}|�|�}t|�|fSt||d��}|�	�|fW5QR�SQRXdS)N��
__loader__�get_data)�encoding)
rD�_module_relative_pathr0�hasattrrLrM�decoderJ�open�read)�filename�package�module_relativerNZ
file_contents�fr,r,r-�_load_testfile�s


rX�cCst�d|d|�S)z~
    Add the given number of space characters to the beginning of
    every non-blank line in `s`, and return the result.
    z
(?m)^(?!$)� )�re�sub)�s�indentr,r,r-�_indent�sr_cCs*t�}|\}}}tj||||d�|��S)zz
    Return a string containing a traceback message for the given
    exc_info tuple (as returned by sys.exc_info()).
    )�file)r#�	traceback�print_exception�getvalue)�exc_infoZexcout�exc_typeZexc_valZexc_tbr,r,r-�_exception_traceback�s
rfc@seZdZdd�Zddd�ZdS)�	_SpoofOutcCs$t�|�}|r |�d�s |d7}|S�NrF)r#rc�endswith)�self�resultr,r,r-rcs
z_SpoofOut.getvalueNcCs|�|�t�|�dS�N)�seekr#�truncate)rj�sizer,r,r-rn	s
z_SpoofOut.truncate)N)r6�
__module__�__qualname__rcrnr,r,r,r-rg�s	rgcCs�t|kr||kS|�t�}t|�dks*t�dt|�}}|d}|rb|�|�r^t|�}|d=ndS|d}|r�|�|�r�|t|�8}|d=ndS||kr�dS|D],}|�|||�}|dkr�dS|t|�7}q�dS)z_
    Essentially the only subtle case:
    >>> _ellipsis_match('aa...aa', 'aaa')
    False
    r4r"F���T)�ELLIPSIS_MARKER�splitr)�AssertionError�
startswithri�find)�want�gotZws�startpos�endpos�wr,r,r-�_ellipsis_matchs2


r}cCs|��}|rd|SdSdS)z)Return a commented form of the given linez# �#N)�rstrip)�liner,r,r-�
_comment_line?sr�cCshdt|�}}|�d�}|dkr$|}|�dd|�}|dkr>|}|�dd|�}|dkr\|d}|||�S)Nr"rF�:�.r&)r)rw�rfind)�msg�start�end�ir,r,r-�_strip_exception_detailsGs
r�c@s2eZdZdZdd�Zddd�Zdd�Zd	d
�ZdS)�_OutputRedirectingPdbz�
    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||dd�d|_dS)NFT)�stdout�nosigintr&)�_OutputRedirectingPdb__out�$_OutputRedirectingPdb__debugger_used�pdb�Pdb�__init__Zuse_rawinput)rj�outr,r,r-r�gsz_OutputRedirectingPdb.__init__NcCs*d|_|dkrt��j}tj�||�dS)NT)r�r>r@�f_backr�r��	set_trace)rj�framer,r,r-r�os
z_OutputRedirectingPdb.set_tracecCs|jrtj�|�dSrl)r�r�r��set_continue�rjr,r,r-r�usz"_OutputRedirectingPdb.set_continuecGs2tj}|jt_ztjj|f|��W�S|t_XdSrl)r>r�r�r�r��trace_dispatch)rj�args�save_stdoutr,r,r-r�{s
z$_OutputRedirectingPdb.trace_dispatch)N)r6rprq�__doc__r�r�r�r�r,r,r,r-r�as

r�cCs�t�|�std|��|�d�r(td��tjj|�d��}t	|d�rXtj�|j
�d}n�|jdkr�tt
j�dkr�t
jddkr�tj�t
jd�d}q�tj}nFt	|d�r�|jD]&}tj�||�}tj�|�r�|Sq�td	|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__))r7r8rBrv�
ValueError�os�path�joinrtrPr�r6r)r>�argv�curdirr��exists)rCZ	test_pathZbasedirZ	directory�fullpathr,r,r-rO�s(






�rOc@s*eZdZdZd
dd�Zdd�Zdd	�ZdS)ran
    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.
    Nr"cCsv|�d�s|d7}|r(|�d�s(|d7}|dk	rB|�d�sB|d7}||_||_||_||_|dkrfi}||_||_dSrh)ri�sourcerx�linenor^�options�exc_msg)rjr�rxr�r�r^r�r,r,r-r��s
zExample.__init__cCs\t|�t|�k	rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkSrl)�type�NotImplementedr�rxr�r^r�r��rj�otherr,r,r-�__eq__�s
�
�
�
�
�zExample.__eq__cCst|j|j|j|j|jf�Srl)�hashr�rxr�r^r�r�r,r,r-�__hash__�s�zExample.__hash__)Nr"r"N)r6rprqr�r�r�r�r,r,r,r-r�s"�
c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
rae
    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�rtd��||_||_|��|_||_||_||_	dS)z�
        Create a new DocTest containing the given examples.  The
        DocTest's globals are initialized with a copy of `globs`.
        z8DocTest no longer accepts str; use DocTestParser insteadN)
r9r:ru�examples�	docstring�copyr1r+rTr�)rjr�r1r+rTr�r�r,r,r-r�s�
zDocTest.__init__cCsRt|j�dkrd}n"t|j�dkr(d}ndt|j�}d|jj|j|j|j|fS)Nr"zno examplesr&z	1 examplez%d examplesz<%s %s from %s:%s (%s)>)r)r��	__class__r6r+rTr�)rjr�r,r,r-�__repr__s��zDocTest.__repr__cCs\t|�t|�k	rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkSrl)r�r�r�r�r1r+rTr�r�r,r,r-r�)s
�
�
�
�
�zDocTest.__eq__cCst|j|j|j|jf�Srl)r�r�r+rTr�r�r,r,r-r�4szDocTest.__hash__cCs:t|t�stS|j|j|jt|�f|j|j|jt|�fkSrl)r9rr�r+rTr��idr�r,r,r-�__lt__8s

�zDocTest.__lt__N)	r6rprqr�r�r�r�r�r�r,r,r,r-r�sc@s�eZdZdZe�dejejB�Ze�dejejBej	B�Z
e�d�jZddd�Z
dd	�Zdd
d�Zdd
�Ze�dej�Zdd�Ze�dej�Zdd�Zdd�Zdd�ZdS)rzD
    A class used to parse strings containing doctest examples.
    a�
        # Source consists of a PS1 line followed by zero or more PS2 lines.
        (?P<source>
            (?:^(?P<indent> [ ]*) >>>    .*)    # PS1 line
            (?:\n           [ ]*  \.\.\. .*)*)  # PS2 lines
        \n?
        # Want consists of any non-blank lines that do not start with PS1.
        (?P<want> (?:(?![ ]*$)    # 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<hdr> Traceback\ \(
            (?: most\ recent\ call\ last
            |   innermost\ last
            ) \) :
        )
        \s* $                # toss trailing whitespace on the header.
        (?P<stack> .*?)      # don't blink: absorb stuff until...
        ^ (?P<msg> \w+ .*)   #     a line *starts* with alphanum.
        z^[ ]*(#.*)?$�<string>c
s|��}|�|���dkr8d��fdd�|�d�D��}g}d\}}|j�|�D]�}|�|||����||�d||���7}|�	|||�\}}}	}
|�
|�s�|�t||	|
|�t|�
d��|d��||�d|��|���7}|��}qP|�||d��|S)	a=
        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.
        r"rFcsg|]}|�d��qSrlr,��.0�l�Z
min_indentr,r-�
<listcomp>sz'DocTestParser.parse.<locals>.<listcomp>�r"r"r^)r�r^r�N)�
expandtabs�_min_indentr�rt�_EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr)�groupr�)rj�stringr+�outputZcharnor��mr�r�rxr�r,r�r-�parsess*
�

�
zDocTestParser.parsecCst|�||�|||||�S)a"
        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.
        )r�get_examples)rjr�r1r+rTr�r,r,r-�get_doctest�s	�zDocTestParser.get_doctestcCsdd�|�||�D�S)a�
        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.
        cSsg|]}t|t�r|�qSr,)r9r)r��xr,r,r-r��s
�z.DocTestParser.get_examples.<locals>.<listcomp>)r�)rjr�r+r,r,r-r��szDocTestParser.get_examplesc
s
t|�d���|�d��d�}|�|�||�|�|dd�d�d||�d��fdd	�|D��}|�d
�}|�d�}t|�dkr�t�d|d�r�|d=|�|d�||t|��d��fd
d	�|D��}|j�|�}|r�|�d�}nd}|�	|||�}	||	||fS)a�
        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.
        r^r�rFr&NrZr�csg|]}|�dd��qS)rYNr,)r�Zsl�r^r,r-r��sz0DocTestParser._parse_example.<locals>.<listcomp>rxz *$rrcsg|]}|�d��qSrlr,)r�Zwlr�r,r-r��sr�)
r)r�rt�_check_prompt_blank�
_check_prefixr�r[�match�
_EXCEPTION_RE�
_find_options)
rjr�r+r��source_linesr�rx�
want_linesr�r�r,r�r-r��s& 


�zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c	Cs�i}|j�|�D]v}|�d��dd���}|D]V}|ddksN|dd�tkrdtd|d||f��t|dd�}|ddk||<q.q|r�|�|�r�td	|||f��|S)
a
        Return a dictionary containing option overrides extracted from
        option directives in the given source string.

        `name` is the string's name, and `lineno` is the line number
        where the example starts; both are used for error messages.
        r&�,rZr"z+-Nz7line %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_REr�r�rGrtr'r�r�)	rjr�r+r�r�r�Zoption_strings�option�flagr,r,r-r��s"���zDocTestParser._find_optionsz
^([ ]*)(?=\S)cCs2dd�|j�|�D�}t|�dkr*t|�SdSdS)z;Return the minimum indentation of any non-blank line in `s`cSsg|]}t|��qSr,)r))r�r^r,r,r-r�
sz-DocTestParser._min_indent.<locals>.<listcomp>r"N)�
_INDENT_RE�findallr)�min)rjr]�indentsr,r,r-r�szDocTestParser._min_indentc	Cs^t|�D]P\}}t|�|dkr||ddkrtd||d||||d�|f��qdS)a

        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.
        rYrKrZz8line %r of the docstring for %s lacks blank after %s: %rr&N)�	enumerater)r�)rj�linesr^r+r�r�r�r,r,r-r�s ��z!DocTestParser._check_prompt_blankcCs>t|�D]0\}}|r|�|�std||d||f��qdS)z�
        Check that every line in the given list starts with the given
        prefix; if any line does not, then raise a ValueError.
        zGline %r of the docstring for %s has inconsistent leading whitespace: %rr&N)r�rvr�)rjr��prefixr+r�r�r�r,r,r-r�s
�zDocTestParser._check_prefixN)r�)r�)r6rprqr�r[�compile�	MULTILINE�VERBOSEr��DOTALLr�r�r�r�r�r�r�r�r�r�r�r�r�r,r,r,r-rCs(
��
'
3�c@sNeZdZdZde�ddfdd�Zddd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)ra<
    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.
    FTcCs||_||_||_||_dS)at
        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)�_parser�_verbose�_recurse�_exclude_empty)rj�verbose�parser�recurse�
exclude_emptyr,r,r-r�7szDocTestFinder.__init__Nc		CsN|dkr.t|dd�}|dkr.tdt|�f��|dkr<d}n|dkrNt�|�}zt�|�}Wntk
rtd}YndX|s�t�|�}|d|dd�dks�d}|dkr�d}n*|dk	r�t�	||j
�}n
t�	|�}|s�d}|dkr�|dkr�i}n
|j
��}n|��}|dk	�r|�|�d|k�r(d|d<g}|�
||||||i�|��|S)	aj
        Return a list of the DocTests that are defined by the given
        object's docstring, or by any of its contained objects'
        docstrings.

        The optional parameter `module` is the module that contains
        the given object.  If the module is not specified or is None, then
        the test finder will attempt to automatically determine the
        correct module.  The object's module is used:

            - As a default namespace, if `globs` is not specified.
            - To prevent the DocTestFinder from extracting DocTests
              from objects that are imported from other modules.
            - To find the name of the file containing the object.
            - To help find the line number of the object within its
              file.

        Contained objects whose module does not match `module` are ignored.

        If `module` is False, no attempt to find the module will be made.
        This is obscure, of use mostly in tests:  if `module` is False, or
        is None but cannot be found automatically, then all objects are
        considered to belong to the (non-existent) module, so all contained
        objects will (recursively) be searched for doctests.

        The globals for each DocTest is formed by combining `globs`
        and `extraglobs` (bindings in `extraglobs` override bindings
        in `globs`).  A new copy of the globals dictionary is created
        for each DocTest.  If `globs` is not specified, then it
        defaults to the module's `__dict__`, if specified, or {}
        otherwise.  If `extraglobs` is not specified, then it defaults
        to {}.

        Nr6zJDocTestFinder.find: name must be given when obj.__name__ doesn't exist: %rFr"���z<]>r�)r0r�r�r7�	getmoduleZ
getsourcefilerBZgetfile�	linecache�getlines�__dict__r��update�_find�sort)	rj�objr+rCr1�
extraglobsr`r��testsr,r,r-rwMsL$�






zDocTestFinder.findcCs�|dkrdSt�|�dk	r(|t�|�kSt�|�r>|j|jkSt�|�r|t|d�r\|jj}nt|d�rn|j}ndS|j	|kSt�
|�r�|j	|jkSt|d�r�|j	|jkSt|t�r�dSt
d��dS)zY
        Return true if the given object is defined in the given
        module.
        NT�__objclass__rpz"object must be a class or function)r7r��
isfunctionr��__globals__ZismethoddescriptorrPr�rpr6�isclassr9�propertyr�)rjrC�objectZobj_modr,r,r-�_from_module�s(








zDocTestFinder._from_modulec
Cs|jrtd|�t|�|kr"dSd|t|�<|�|||||�}|dk	rR|�|�t�|�r�|jr�|j�	�D]P\}	}
d||	f}	t�
t�|
��s�t�|
�rl|�
||
�rl|�||
|	||||�qlt�|��rn|j�rnt|di��	�D]�\}	}
t|	t��stdt|	�f��t�
|
��sJt�|
��sJt�|
��sJt|
t��sJtdt|
�f��d||	f}	|�||
|	||||�q�t�|��r|j�r|j�	�D]�\}	}
t|
t��r�t||	�}
t|
t��r�t||	�j}
t�
|
��s�t�|
��s�t|
t��r�|�
||
��r�d||	f}	|�||
|	||||��q�dS)	zm
        Find tests for the given object and any contained objects, and
        add them to `tests`.
        zFinding tests in %sNr&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)r��printr��	_get_testr�r7r8r�r��itemsZ	isroutineZunwraprrr�r0r9r:r�r��staticmethod�classmethod�__func__r)rjr�r�r+rCr�r1�seen�testZvalname�valr,r,r-r��sn
�
�������
�
��zDocTestFinder._findc		Cs�t|t�r|}nJz,|jdkr"d}n|j}t|t�s:t|�}Wnttfk
rXd}YnX|�||�}|jrt|stdS|dkr�d}n.t|dd�p�|j}|dd�dkr�|dd�}|j	�
|||||�S)zs
        Return a DocTest for the given object, if it defines a docstring;
        otherwise, return None.
        Nr�r�����.pycrr)r9r:r�rB�AttributeError�_find_linenor�r0r6r�r�)	rjr�r+rCr1r�r�r�rTr,r,r-rs,




�zDocTestFinder._get_testcCsd}t�|�rd}t�|�rb|dkr(dSt�dt|dd��}t|�D]\}}|�|�rF|}qbqFt�|�rr|j	}t�
|�r�|j}t�|�r�|j
}t�|�r�|j}t�|�r�t|dd�d}|dk	�r
|dkr�|dSt�d�}t|t|��D]}|�||�r�|Sq�dS)	z�
        Return a line number of the given object's docstring.  Note:
        this method assumes that the object has a docstring.
        Nr"z^\s*class\s*%s\br6�-�co_firstlinenor&z(^|.*:)\s*\w*("|\'))r7r8rr[r�r0r�r�Zismethodr
r��__code__Zistraceback�tb_frameZisframe�f_codeZiscode�ranger))rjr�r�r�Zpatr�r�r,r,r-r4s>


�








zDocTestFinder._find_lineno)NNNN)r6rprqr�rr�rwrr�rrr,r,r,r-r.s�

f?&c@s�eZdZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Ze
�d�Zd dd�Zd!dd�Zd"dd�Zdd�ZdS)#ra3	
    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`.
    zF**********************************************************************Nr"cCsN|pt�|_|dkrdtjk}||_||_||_d|_d|_i|_	t
�|_dS)ac
        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.
        N�-vr")r�_checkerr>r�r��optionflags�original_optionflags�tries�failures�_name2ftrg�_fakeout)rj�checkerr�rr,r,r-r��s
zDocTestRunner.__init__cCsH|jrD|jr.|dt|j�dt|j��n|dt|j�d�dS)z�
        Report that the test runner is about to process the given
        example.  (Only displays a message if verbose=True)
        zTrying:
zExpecting:
zExpecting nothing
N)r�rxr_r�)rjr�r�exampler,r,r-�report_start�s���zDocTestRunner.report_startcCs|jr|d�dS)zt
        Report that the given example ran successfully.  (Only
        displays a message if verbose=True)
        zok
N)r��rjr�rr!ryr,r,r-�report_success�szDocTestRunner.report_successcCs&||�||�|j�|||j��dS)z7
        Report that the given example failed.
        N)�_failure_headerr�output_differencerr#r,r,r-�report_failure�s�zDocTestRunner.report_failurecCs$||�||�dtt|���dS)zO
        Report that the given example raised an unexpected exception.
        zException raised:
N)r%r_rf�rjr�rr!rdr,r,r-�report_unexpected_exception�s
�
�z)DocTestRunner.report_unexpected_exceptioncCs�|jg}|jrR|jdk	r4|jdk	r4|j|jd}nd}|�d|j||jf�n|�d|jd|jf�|�d�|j}|�t|��d�|�S)Nr&�?zFile "%s", line %s, in %szLine %s, in %szFailed example:rF)�DIVIDERrTr�r�r+r�r_r�)rjrr!r�r�r�r,r,r-r%�s�
zDocTestRunner._failure_headerc	Cs�d}}|j}td�\}}}	|jj}
t|j�D�]H\}}|jt@oH|dk}
||_|jr�|j��D],\}}|r||j|O_q`|j|M_q`|jt	@r�q.|d7}|
s�|�
|||�d|j|f}z,tt
|j|d|d�|j�|j��d}Wn4tk
�r�Ynt��}|j��YnX|j��}|j�d�|}|dk�r`|
|j||j��r�|}n|tj|dd��d}|
�s�|t|�7}|jdk�r�|	}nB|
|j||j��r�|}n*|jt@�r�|
t|j�t|�|j��r�|}||k�r�|
�sd|�||||�nf||k�r(|
�s|� ||||�|d7}n<||	k�rR|
�sH|�!||||�|d7}nd	�sdt"d
|f��|r.|jt#@r.�qzq.||_|�$|||�t%||�S)a�
        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`.
        r"rKr&z<doctest %s[%d]>ZsingleNr4rrFzunknown outcome)&rrr�check_outputr�r�rr�rrr"r+�execr�r�r1�debuggerr��KeyboardInterruptr>rdrrcrnrxra�format_exception_onlyrfr�rr�r$r'r)rur�_DocTestRunner__record_outcomer%)rjr�compileflagsr�rrr�SUCCESS�FAILUREZBOOMZcheck�
examplenumr!�quietZ
optionflagr
rTZ	exceptionryZoutcomer�r,r,r-Z__run�s�
�
��



�




�
zDocTestRunner.__runcCsL|j�|jd�\}}||||f|j|j<|j|7_|j|7_dS)z{
        Record the fact that the given DocTest (`test`) generated `f`
        failures out of `t` tried examples.
        r�N)rr/r+rr)rjrrW�t�f2�t2r,r,r-Z__record_outcome|szDocTestRunner.__record_outcomez.<doctest (?P<name>.+)\[(?P<examplenum>\d+)\]>$cCsV|j�|�}|rF|�d�|jjkrF|jjt|�d��}|jjdd�S|�	||�SdS)Nr+r5T��keepends)
�%_DocTestRunner__LINECACHE_FILENAME_REr�r�rr+r��intr��
splitlines�save_linecache_getlines)rjrT�module_globalsr�r!r,r,r-Z__patched_linecache_getlines�s
z*DocTestRunner.__patched_linecache_getlinesTc		s||_|dkrt|j�}tj�|dkrV�j��dks@���dkrH�j}n��fdd�}|jt_t�	�}t
j}t��|_
|j
��|j
jt
_tj|_|jt_tj}tjt_z|�|||�W�S�t_|t
_t�|�|jt_|t_|�r�|j��ddl}d|_XdS)aJ
        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.
        N�utf-8cs t|��d���}��|�dS)N�backslashreplace)r:�encode�write)r]�rNr�r,r-r��szDocTestRunner.run.<locals>.outr")rr3r1r>r�rN�lowerrDr�gettracer�r�r�r.�resetr�r�r?�*_DocTestRunner__patched_linecache_getlines�displayhook�__displayhook__�settrace�clear�builtins�_�_DocTestRunner__run)	rjrr2r��clear_globsZ
save_traceZsave_set_traceZsave_displayhookrNr,rEr-�run�s<





zDocTestRunner.runc
Cs�|dkr|j}g}g}g}d}}|j��D]b}|\}\}	}
|	|
ksHt�||
7}||	7}|
dkrl|�|�q,|	dkr�|�||
f�q,|�|�q,|r�|r�tt|�d�|��|D]}td|�q�|r�tt|�d�|��|D]\}}td||f�q�|�rFt|j�tt|�d�|��|D] \}\}	}
td|	|
|f��q$|�rrt|d	t|j�d
�t||d|d�|�r�td
|d�n|�r�td�t	||�S)a�
        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.
        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.)
r�rrrur�rr)r�r+r%)
rjr�ZnotestsZpassedZfailedZtotaltZtotalfr�r+rWr7�thingr�r,r,r-�	summarize�sR
zDocTestRunner.summarizecCsR|j}|j��D]<\}\}}||kr@||\}}||}||}||f||<qdSrl)rr)rjr��dr+rWr7r8r9r,r,r-�mergeszDocTestRunner.merge)NNr")N)NNT)N)r6rprqr�r+r�r"r$r'r)r%rPr1r[r�r<rIrRrTrVr,r,r,r-rhs9
$
}



I
9c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)ra_
    A class used to check the whether the actual output from a doctest
    example matches the expected output.  `OutputChecker` defines two
    methods: `check_output`, which compares a given pair of outputs,
    and returns true if they match; and `output_difference`, which
    returns a string describing the differences between two outputs.
    cCst|�dd�d�S)z=
        Convert string to hex-escaped ASCII string.
        �ASCIIrB)r:rC)rjr]r,r,r-�_toAscii(szOutputChecker._toAsciicCs�|�|�}|�|�}||kr dS|t@sH||fdkr8dS||fdkrHdS|t@s�t�dt�t�d|�}t�dd|�}||kr�dS|t@r�d�|�	��}d�|�	��}||kr�dS|t
@r�t||�r�dSdS)	a�
        Return True iff the actual output from an example (`got`)
        matches the expected output (`want`).  These strings are
        always considered to match if they are identical; but
        depending on what option flags the test runner is using,
        several non-exact match types are also possible.  See the
        documentation for `TestRunner` for more information about
        option flags.
        T)zTrue
z1
)zFalse
z0
z(?m)^%s\s*?$r�z(?m)^[^\S\n]+$rZF)rXrrr[r\�escape�BLANKLINE_MARKERrr�rtrr}�rjrxryrr,r,r-r,.s4

�
zOutputChecker.check_outputcCs<|ttBtB@sdS|t@r dS|�d�dko:|�d�dkS)NFTrFr4)r	r
rr�r[r,r,r-�_do_a_fancy_diffms��zOutputChecker._do_a_fancy_diffc
Cs8|j}|t@st�dt|�}|�|||�r�|jdd�}|jdd�}|t@rptj	||dd�}t
|�dd�}d}nf|t@r�tj||dd�}t
|�dd�}d}n8|t
@r�tjtjd	�}	t
|	�||��}d
}nds�td��d
|td�|��S|�r|�rdt|�t|�fS|�rdt|�S|�r0dt|�SdSdS)z�
        Return a string describing the differences between the
        expected output for a given example (`example`) and the actual
        output (`got`).  `optionflags` is the set of option flags used
        to compare `want` and `got`.
        z(?m)^[ ]*(?=
)Tr:r4)�nNz#unified diff with -expected +actualz-context diff with expected followed by actual)Zcharjunkzndiff with -expected +actualr"zBad diff optionzDifferences (%s):
r�zExpected:
%sGot:
%szExpected:
%sGot nothing
zExpected nothing
Got:
%szExpected nothing
Got nothing
)rxrr[r\rZr\r>r	�difflibZunified_diff�listr
Zcontext_diffrZDifferZIS_CHARACTER_JUNKZcomparerur_r�)
rjr!ryrrxr�Z	got_linesZdiffZkindZenginer,r,r-r&�s6zOutputChecker.output_differenceN)r6rprqr�rXr,r\r&r,r,r,r-r s
?c@s eZdZdZdd�Zdd�ZdS)rz�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||_||_||_dSrl)rr!ry)rjrr!ryr,r,r-r��szDocTestFailure.__init__cCs
t|j�Srl�r:rr�r,r,r-�__str__�szDocTestFailure.__str__N�r6rprqr�r�rar,r,r,r-r�s
c@s eZdZdZdd�Zdd�ZdS)rz�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||_||_||_dSrl)rr!rd)rjrr!rdr,r,r-r��szUnexpectedException.__init__cCs
t|j�Srlr`r�r,r,r-ra�szUnexpectedException.__str__Nrbr,r,r,r-r�s
c@s*eZdZdZd
dd�Zdd�Zdd	�ZdS)ra�	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: <DocTest foo from foo.py:0 (2 examples)>

         >>> 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
         {}

       NTcCs$t�||||d�}|r |j��|S)NF)rrRr1rM)rjrr2r�rQ�rr,r,r-rR3s
zDebugRunner.runcCst|||��dSrl)rr(r,r,r-r)9sz'DebugRunner.report_unexpected_exceptioncCst|||��dSrl)rr#r,r,r-r'<szDebugRunner.report_failure)NNT)r6rprqr�rRr)r'r,r,r,r-r�sZ
TFc	Cs�|dkrtj�d�}t�|�s,td|f��|dkr:|j}t|d�}	|rVt||d�}
nt	||d�}
|	j
||||d�D]}|
�|�qt|r�|
��t
dkr�|
a
n
t
�|
�t|
j|
j�S)a*
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.
    Nr�ztestmod: module required; %r)r��r�r�r1r�)r>r?r/r7r8rBr6rrrrwrRrT�masterrVr%rr)r�r+r1r��reportrr��raise_on_errorr��finder�runnerrr,r,r-rHs$E


cCs�|r|std��t||||pd�\}}|dkr:tj�|�}|dkrHi}n|��}|dk	rb|�|�d|krrd|d<|	r�t||d�}
nt||d�}
|
�	||||d�}|
�
|�|r�|
��tdkr�|
an
t�
|
�t|
j|
j�S)a


    Test examples in the given file.  Return (#failures, #tests).

    Optional keyword arg "module_relative" specifies how filenames
    should be interpreted:

      - If "module_relative" is True (the default), then "filename"
         specifies a module-relative path.  By default, this path is
         relative to the calling module's directory; but if the
         "package" argument is specified, then it is relative to that
         package.  To ensure os-independence, "filename" should use
         "/" characters to separate path segments, and should not
         be an absolute path (i.e., it may not begin with "/").

      - If "module_relative" is False, then "filename" specifies an
        os-specific path.  The path may be absolute or relative (to
        the current working directory).

    Optional keyword arg "name" gives the name of the test; by default
    use the file's basename.

    Optional keyword argument "package" is a Python package or the
    name of a Python package whose directory should be used as the
    base directory for a module relative filename.  If no package is
    specified, then the calling module's directory is used as the base
    directory for module relative filenames.  It is an error to
    specify "package" if "module_relative" is False.

    Optional keyword arg "globs" gives a dict to be used as the globals
    when executing examples; by default, use {}.  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.

    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.  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.

    Optional keyword arg "parser" specifies a DocTestParser (or
    subclass) that should be used to extract tests from the files.

    Optional keyword arg "encoding" specifies an encoding that should
    be used to convert the file to unicode.

    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.
    �8Package may only be specified for module-relative paths.rANr6r�rdr")r�rXr�r��basenamer�r�rrr�rRrTrfrVr%rr)rTrVr+rUr1r�rgrr�rhr�rN�textrjrr,r,r-r�s2R�


�NoNamec	Cs@t|dd�}t||d�}|j|||d�D]}|j||d�q(dS)ar
    Test examples in the given object's docstring (`f`), using `globs`
    as globals.  Optional argument `name` is used in failure messages.
    If the optional argument `verbose` is true, then generate output
    even if there are no failures.

    `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`.

    Optional keyword arg `optionflags` specifies options for the
    testing and output.  See the documentation for `testmod` for more
    information.
    F)r�r�rd)r1)r2N)rrrwrR)	rWr1r�r+r2rrirjrr,r,r-r+scCs"|t@|krtd|��t}|a|S)a?Sets the unittest option flags.

    The old flag is returned so that a runner could restore the old
    value if it wished to:

      >>> 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
    zOnly reporting flags allowed)r
r��_unittest_reportflags)r2�oldr,r,r-rHs

c@sleZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Ze
jZdd�ZdS)�DocTestCaser"NcCs.tj�|�||_||_||_||_||_dSrl)�unittest�TestCaser��_dt_optionflags�_dt_checker�_dt_test�	_dt_setUp�_dt_tearDown)rjrr�setUp�tearDownr r,r,r-r�nszDocTestCase.__init__cCs|j}|jdk	r|�|�dSrl)rvrw�rjrr,r,r-ryxs
zDocTestCase.setUpcCs(|j}|jdk	r|�|�|j��dSrl)rvrxr1rMr{r,r,r-rz~s

zDocTestCase.tearDowncCs~|j}tj}t�}|j}|t@s(|tO}t||jdd�}z d|_	|j
||jdd�\}}W5|t_X|rz|�|�
|�����dS)NF�rr r�zF----------------------------------------------------------------------)r�rQ)rvr>r�r#rtr
rorrur+rRrDZfailureException�format_failurerc)rjrrp�newrrjrrr,r,r-�runTest�s(��zDocTestCase.runTestcCsP|j}|jdkrd}n
d|j}d�|j�d�dd��}d|j|j|||fS)Nzunknown line numberz%sr�rrz:Failed doctest test for %s
  File "%s", line %s, in %s

%s)rvr�r�r+rtrT)rj�errrr�Zlnamer,r,r-r}�s

�zDocTestCase.format_failurecCs6|��t|j|jdd�}|j|jdd�|��dS)a�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'

           Fr|)rQN)ryrrtrurRrvrz)rjrjr,r,r-r!�sB�zDocTestCase.debugcCs|jjSrl�rvr+r�r,r,r-r��szDocTestCase.idcCsPt|�t|�k	rtS|j|jkoN|j|jkoN|j|jkoN|j|jkoN|j|jkSrl)r�r�rvrtrwrxrur�r,r,r-r��s
�
�
�
�zDocTestCase.__eq__cCst|j|j|j|jf�Srl)r�rtrwrxrur�r,r,r-r��s�zDocTestCase.__hash__cCs,|jj�d�}d|dd�|dd��fS)Nr�z%s (%s)rr)rvr+rtr�)rjr+r,r,r-r�	szDocTestCase.__repr__cCsd|jjS)Nz	Doctest: r�r�r,r,r-�shortDescription		szDocTestCase.shortDescription)r"NNN)r6rprqr�ryrzrr}r!r�r�r�r�rrar�r,r,r,r-rqls�

H
rqc@s0eZdZdd�Zdd�Zdd�Zdd�ZeZd	S)
�SkipDocTestCasecCs||_t�|d�dSrl)rCrqr�)rjrCr,r,r-r�
	szSkipDocTestCase.__init__cCs|�d�dS)Nz-DocTestSuite will not work with -O2 and above)ZskipTestr�r,r,r-ry	szSkipDocTestCase.setUpcCsdSrlr,r�r,r,r-�	test_skip	szSkipDocTestCase.test_skipcCsd|jjS)NzSkipping tests from %s)rCr6r�r,r,r-r�	sz SkipDocTestCase.shortDescriptionN)r6rprqr�ryr�r�rar,r,r,r-r�	s
r�c@seZdZdd�ZdS)�
_DocTestSuitecCsdSrlr,)rj�indexr,r,r-�_removeTestAtIndex	sz _DocTestSuite._removeTestAtIndexN)r6rprqr�r,r,r,r-r�	sr�c	Ks�|dkrt�}t|�}|j|||d�}|sNtjjdkrNt�}|�t|��|S|�	�t�}|D]T}t
|j�dkrtq`|js�|j
}|dd�dkr�|dd�}||_|�t|f|��q`|S)a
    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.
    Nrer4r"rrrr)rrDrwr>r2�optimizer��addTestr�r�r)r�rTr�rq)	rCr1r�Ztest_finderr�r��suiterrTr,r,r-r#	s(%c@s$eZdZdd�Zdd�Zdd�ZdS)�DocFileCasecCsd�|jj�d��S)NrOr�)r�rvr+rtr�r,r,r-r�e	szDocFileCase.idcCs|jjSrl)rvrTr�r,r,r-r�h	szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s
  File "%s", line 0

%s)rvr+rT)rjr�r,r,r-r}k	s�zDocFileCase.format_failureN)r6rprqr�r�r}r,r,r,r-r�c	sr�c
Ksv|dkri}n|��}|r&|s&td��t||||p4d�\}}d|krL||d<tj�|�}|�||||d�}	t|	f|�S)NrkrAr�r")r�r�rXr�r�rlr�r�)
r�rVrUr1r�rNr��docr+rr,r,r-�DocFileTestp	s�r�cOsDt�}|�dd�r$t|�d��|d<|D]}|�t|f|��q(|S)a�A unittest suite for one or more doctest files.

    The path to each doctest file is given as a string; the
    interpretation of that string depends on the keyword argument
    "module_relative".

    A number of options may be provided as keyword arguments:

    module_relative
      If "module_relative" is True, then the given file paths are
      interpreted as os-independent module-relative paths.  By
      default, these paths are relative to the calling module's
      directory; but if the "package" argument is specified, then
      they are relative to that package.  To ensure os-independence,
      "filename" should use "/" characters to separate path
      segments, and may not be an absolute path (i.e., it may not
      begin with "/").

      If "module_relative" is False, then the given file paths are
      interpreted as os-specific paths.  These paths may be absolute
      or relative (to the current working directory).

    package
      A Python package or the name of a Python package whose directory
      should be used as the base directory for module relative paths.
      If "package" is not specified, then the calling module's
      directory is used as the base directory for module relative
      filenames.  It is an error to specify "package" if
      "module_relative" is False.

    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.

    parser
      A DocTestParser (or subclass) that should be used to extract
      tests from the files.

    encoding
      An encoding that will be used to convert the files to unicode.
    rVTrU)r�r/rDr�r�)�paths�kwr�r�r,r,r-r�	s8cCs�g}t��|�D]x}t|t�rh|�|jdd��|j}|r�|�d�|dd�|�d�dd�D�7}q|dd�|�d�dd�D�7}q|r�|ddkr�|��q�|r�|d	dkr�|�d	�q�d�	|�dS)
awExtract script from text with examples.

       Converts text with examples to a Python script.  Example input is
       converted to regular code.  Example output and all other words
       are converted to comments:

       >>> 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
       <BLANKLINE>
       Nrrz# Expected:cSsg|]}d|�qS)z## r,r�r,r,r-r�
sz(script_from_examples.<locals>.<listcomp>rFcSsg|]}t|��qSr,)r�r�r,r,r-r�
s�r~r")
rr�r9rr�r�rxrt�popr�)r]r�Zpiecerxr,r,r-r�	s :

"�

csJt|�}t��|�}�fdd�|D�}|s4t�d��|d}t|j�}|S)aExtract 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.
    csg|]}|j�kr|�qSr,r*)r�r7r*r,r-r�.
s
ztestsource.<locals>.<listcomp>znot found in testsr")rDrrwr�rr�)rCr+r�r�testsrcr,r*r-r%
s

cCst|�}t|||�dS)z4Debug a single doctest docstring, in argument `src`'N)r�debug_script)�src�pmr1r�r,r,r-r 5
scCs�ddl}|r|��}ni}|rvzt|||�Wq�tt��d�|jdd�}|��|�dt��d�Yq�Xn|jdd��	d|||�dS)z7Debug a test script.  `src` is the script, as a string.r"Nr&T)r�r4zexec(%r))
r�r�r-rr>rdr�rHZinteractionrR)r�r�r1r��pr,r,r-r�:
s
r�cCs$t|�}t||�}t|||j�dS)z�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)rDrr�r�)rCr+r�r�r,r,r-r!N
s
c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
_TestClassz�
    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)z�val -> _TestClass object with associated value val.

        >>> t = _TestClass(123)
        >>> print(t.get())
        123
        N�r
)rjr
r,r,r-r�j
sz_TestClass.__init__cCs|jd|_|S)zosquare() -> square TestClass's associated value

        >>> _TestClass(13).square().get()
        169
        r4r�r�r,r,r-�squaret
sz_TestClass.squarecCs|jS)z~get() -> return TestClass's associated value.

        >>> x = _TestClass(-42)
        >>> print(x.get())
        -42
        r�r�r,r,r-r/~
sz_TestClass.getN)r6rprqr�r�r�r/r,r,r,r-r�\
s


r�z�
                      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 <BLANKLINE>:
                    >>> print('foo\n\nbar\n')
                    foo
                    <BLANKLINE>
                    bar
                    <BLANKLINE>
            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]
            )r�r�zbool-int equivalencezblank linesZellipsiszwhitespace normalizationcCs"ddl}|jdd�}|jdddddd	�|jd
ddt��gd
d�|jddddd�|jdddd�|��}|j}|j}d}|jD]}|t|O}q�|j	r�|t
O}|D]v}|�d�r�tj
�|�\}}tj
�d|�t|dd��}	tj
d=t|	||d�\}
}nt|d||d�\}
}|
r�dSq�dS)Nr"zdoctest runner)Zdescriptionrz	--verbose�
store_trueFz'print very verbose output for all tests)�action�default�helpz-oz--optionr�zqspecify a doctest option flag to apply to the test run; may be specified more than once to apply multiple options)r��choicesr�r�z-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))r�r�r`r�z file containing the tests to run)�nargsr�z.py���rd)rVr�rr&)�argparse�ArgumentParser�add_argumentr'�keys�
parse_argsr`r�r�Z	fail_fastrrir�r�rtr>�insertr;rr)r�r�r�Z	testfilesr�r�r�rT�dirnamer�rrOr,r,r-�_test�
sL�
�
��

�
r�r�)r4)rY)	NNNNTr"NFF)FrnNr")NNNN)FN)FN)F)Sr�Z
__docformat__�__all__r.r^r7r�r�r�r[r>rarr�ior#�collectionsr$r%r'rrrrrrrrr	r
rrrr
rZrsr3rDrJrXr_rfrgr}r�r�r�r�rOrrrrrr�	Exceptionrrrrfrrrrorrsrqr�Z	TestSuiter�rr�r�rrrr r�r!r�rr�r6�exitr,r,r,r-�<module>	sF'�-
���������

1%.DKl<;n�
h�
{�
$!
@
�
IR


,	�3-


Zerion Mini Shell 1.0