%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.12/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.12/__pycache__/doctest.cpython-312.pyc

�

���f���P�dZdZgd�ZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZddlmZedd�ZiZd	�Zed
�Zed�Zed�Zed
�Zed�Zed�ZeezezezezezZed�Zed�Zed�Zed�Zed�Z eezezeze zZ!dZ"dZ#d�Z$dWd�Z%d�Z&d�Z'dXd�Z(d�Z)Gd�de�Z*d�Z+d �Z,d!�Z-Gd"�d#ej\�Z/d$�Z0Gd%�d&�Z1Gd'�d(�Z2Gd)�d*�Z3Gd+�d,�Z4Gd-�d.�Z5Gd/�d0�Z6Gd1�d2e7�Z8Gd3�d4e7�Z9Gd5�d6e5�Z:da;			dYd9�Z<d7ddddd7ddd8e3�dfd:�Z=		dZd;�Z>da?d<�Z@Gd=�d>ej��ZBGd?�d@eB�ZCGdA�dBej��ZEd[dC�ZFGdD�dEeB�ZGd7dde3�dfdF�ZHdG�ZIdH�ZJdI�ZKd\dJ�ZLd\dK�ZMd]dL�ZNGdM�dN�ZOeOdOdPdQdRdSdT�ZPdU�ZQeRdVk(re
j�eQ��yy)^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�IncrementalNewlineDecoder)�
namedtuple�TestResultszfailed attemptedc�N�tj|dtt�z�S)N�)�OPTIONFLAGS_BY_NAME�
setdefault�len)�names �/usr/lib/python3.12/doctest.pyrr�s ���)�)�$��S�9L�5M�0M�N�N�rrrrrrr
rrr
rz<BLANKLINE>z...c��d}tjD]6}|j|d�}|tt|�us�(||jz}�8|S)z�
    Return the compiler-flags associated with the future features that
    have been imported into the given namespace (globs).
    r#N)�
__future__�all_feature_names�get�getattr�
compiler_flag)�globs�flags�fname�features    r.�_extract_future_flagsr:�sT��

�E��-�-�+���)�)�E�4�(���g�j�%�0�0��W�*�*�*�E�+��Lr/c��tj|�r|St|t�rt	|t�t
�dg�S|�(		tjtj|�Std��#t$r6tjtj|�jdcYSwxYw#t$rYywxYw)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�_getframemodulename�AttributeError�	_getframe�	f_globals�KeyError�	TypeError)�module�depths  r.�_normalize_modulerO�s���������
�	�F�C�	 ��&�'�)�V�X��u�=�=�	��	�
O��{�{�3�#:�#:�5�#A�B�B��<�=�=��"�
O��{�{�3�=�=��#7�#A�#A�*�#M�N�N�
O���	��	�s*�%A<�<<B;�8B>�:B;�;B>�>	C
�	C
c�:�tdd�j|d�S�NT)r%�decode)�datas r.�_newline_convertrT�s��$�T�4�0�7�7��d�C�Cr/c��|ryt|d�}t||�}t|dd�x}�	|jj}t
|d�r/|j|�}|j|�}t|�|fSt||��5}|j�|fcddd�S#t
$rY�owxYw#1swYyxYw)N��
__loader__�get_data)�encoding)rO�_module_relative_pathr4�__spec__�loaderrH�hasattrrXrRrT�open�read)�filename�package�module_relativerYr\�
file_contents�fs       r.�_load_testfilere�s����#�G�Q�/��(��(�;���g�|�T�:�:�F�C�
� �)�)�0�0���6�:�&�"�O�O�H�5�M�)�0�0��:�M�$�M�2�H�<�<�	
�h��	*�"�a��v�v�x��!�"�"��"�
��
��"�"�s�B%�	B4�%	B1�0B1�4B=c�6�tjd|dz|�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�indents  r.�_indentrl�s���6�6�,��s�
�A�.�.r/c�t�t�}|\}}}tj||||��|j�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_info�excout�exc_type�exc_val�exc_tbs     r.�_exception_tracebackrw�s8���Z�F� (��H�g�v�
���h���f�E��?�?��r/c��eZdZd�Zdd�Zy)�	_SpoofOutc�`�tj|�}|r|jd�s|dz
}|S�N�
)r$rq�endswith)�self�results  r.rqz_SpoofOut.getvalues0���"�"�4�(���&�/�/�$�/��d�N�F��
r/Nc�P�|j|�tj|�y�N)�seekr$�truncate)r~�sizes  r.r�z_SpoofOut.truncates���	�	�$�����$�r/r�)r=�
__module__�__qualname__rqr��r/r.ryrys��� r/ryc��t|vr||k(S|jt�}t|�dk\sJ�dt|�}}|d}|r!|j|�rt|�}|d=ny|d}|r$|j	|�r|t|�z}|d=ny||kDry|D]*}|j|||�}|dkry|t|�z
}�,y)z_
    Essentially the only subtle case:
    >>> _ellipsis_match('aa...aa', 'aaa')
    False
    �r#F���T)�ELLIPSIS_MARKER�splitr,�
startswithr}�find)�want�got�ws�startpos�endpos�ws      r.�_ellipsis_matchr�s����d�"��s�{��
���O�	$�B��r�7�a�<��<��#�c�(�f�H�
�1��A���>�>�!���1�v�H��1���
�2��A���<�<��?��c�!�f��F��2����&���
����8�8�A�x��0���a�<���C��F����r/c�2�|j�}|rd|zSy)z)Return a commented form of the given linez# �#)�rstrip)�lines r.�
_comment_liner�Fs���;�;�=�D���D�y��r/c���dt|�}}|jd�}|dk\r|}|jdd|�}|dk\r|}|jdd|�}|dk\r|dz}|||S)Nr#r|�:�.r))r,r��rfind)�msg�start�end�is    r.�_strip_exception_detailsr�Nsv���C��H�3�E������A��A�v�������a���A��A�v����	�	�#�q�#��A��A�v��!����u�c�?�r/c�*�eZdZdZd�Zdd�Zd�Zd�Zy)�_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.
    c�r�||_d|_tjj	||d��d|_y)NFT)�stdout�nosigintr))�_OutputRedirectingPdb__out�$_OutputRedirectingPdb__debugger_used�pdb�Pdb�__init__�use_rawinput)r~�outs  r.r�z_OutputRedirectingPdb.__init__ns2����
�$���������c�D��9���r/Nc��d|_|�tj�j}tj
j
||�yrQ)r�rErI�f_backr�r��	set_trace)r~�frames  r.r�z_OutputRedirectingPdb.set_tracevs4��#����=��M�M�O�*�*�E������$��&r/c�\�|jr tjj|�yyr�)r�r�r��set_continue�r~s r.r�z"_OutputRedirectingPdb.set_continue|s$������G�G� � ��&� r/c���tj}|jt_	tjj
|g|���|t_S#|t_wxYwr�)rEr�r�r�r��trace_dispatch)r~�args�save_stdouts   r.r�z$_OutputRedirectingPdb.trace_dispatch�sA���j�j���Z�Z��
�	%��7�7�)�)�$�6��6�$�C�J���C�J�s�A�
Ar�)r=r�r��__doc__r�r�r�r�r�r/r.r�r�hs���
�'�'�%r/r�c��tj|�std|z��|jd�rt	d��tjj|jd��}t|d�r-t
jj|j�d}n�|jdk(rwttj�dkDrJtjddk7r4t
jjtjd�d}n�t
j}nxt|d�rT|j D]E}t
jj||�}t
jj#|�s�C|cSt	d	|jz��t
jj||�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__))r>r?rLr��
ValueError�os�path�joinr�r]r�r=r,rE�argv�curdirr��exists)rM�	test_path�basedir�	directory�fullpaths     r.rZrZ�sN�����F�#��/�&�8�9�9����C� ��L�M�M������y���s�3�5�I��v�z�"��'�'�-�-����0��3��	���J�	&��s�x�x�=��?�s�x�x��{�b�0��g�g�m�m�C�H�H�Q�K�0��3�G��i�i�G��6�:�&�#�_�_�
$�	��7�7�<�<�	�9�=���7�7�>�>�(�+�#�O�
$��3�!�?�?�+�,�	,�
�7�7�<�<���+�+r/c�(�eZdZdZ		dd�Zd�Zd�Zy)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.
    Nc���|jd�s|dz
}|r|jd�s|dz
}|�|jd�s|dz
}||_||_||_||_|�i}||_||_yr{)r}�sourcer��linenork�options�exc_msg)r~r�r�r�r�rkr�s       r.r�zExample.__init__�s�����t�$��d�N�F���
�
�d�+��D�L�D���w�'7�'7��'=��t�O�G������	��������?�b�G������r/c�z�t|�t|�urtS|j|jk(xr�|j|jk(xrj|j|jk(xrO|j
|j
k(xr4|j|jk(xr|j|jk(Sr�)�type�NotImplementedr�r�r�rkr�r��r~�others  r.�__eq__zExample.__eq__�s�����:�T�%�[�(�!�!��{�{�e�l�l�*�-��y�y�E�J�J�&�-��{�{�e�l�l�*�-��{�{�e�l�l�*�-��|�|�u�}�}�,�	-�
�|�|�u�}�}�,�	-r/c��t|j|j|j|j|j
f�Sr�)�hashr�r�r�rkr�r�s r.�__hash__zExample.__hash__�s3���T�[�[�$�)�)�T�[�[�$�+�+��\�\�#�$�	$r/)Nr#r#N)r=r�r�r�r�r�r�r�r/r.rr�s!��!�DEF���$	-�$r/rc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)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.
    c��t|t�rJd��||_||_|j	�|_||_||_||_y)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)	r@rA�examples�	docstring�copyr6r-r`r�)r~r�r6r-r`r�r�s       r.r�zDocTest.__init__sP��
�h��,�	J�I�	J�,� ��
�"����Z�Z�\��
���	� ��
���r/c�&�t|j�dk(rd}n3t|j�dk(rd}ndt|j�z}d|jj�d|j�d|j
�d	|j�d
|�d�S)Nr#zno examplesr)z	1 examplez%d examples�<rgz from r�� (z)>)r,r��	__class__r=r-r`r�)r~r�s  r.�__repr__zDocTest.__repr__%sp���t�}�}���"�$�H�
����
�1�
$�"�H�$�s�4�=�=�'9�9�H�����(�(����D�M�M�4�;�;��B�	Cr/c�z�t|�t|�urtS|j|jk(xr�|j|jk(xrj|j|jk(xrO|j
|j
k(xr4|j|jk(xr|j|jk(Sr�)r�r�r�r�r6r-r`r�r�s  r.r�zDocTest.__eq__0s�����:�T�%�[�(�!�!��}�}����.�+��~�~����0�+��z�z�U�[�[�(�+��y�y�E�J�J�&�+��}�}����.�	+�
�{�{�e�l�l�*�	+r/c�p�t|j|j|j|jf�Sr�)r�r�r-r`r�r�s r.r�zDocTest.__hash__;s&���T�^�^�T�Y�Y��
�
�t�{�{�K�L�Lr/c�$�t|t�stS|j�|jnd}|j�|jnd}|j|j
|t
|�f|j|j
|t
|�fkS)Nr�)r@rr�r�r-r`�id)r~r��self_lno�	other_lnos    r.�__lt__zDocTest.__lt__?sv���%��)�!�!�"&�+�+�"9�4�;�;�r��$)�L�L�$<�E�L�L�"�	����D�M�M�8�R��X�>����U�^�^�Y��5�	�B�C�	Dr/N)	r=r�r�r�r�r�r�r�r�r�r/r.rr�s#���.�	C�	+�M�Dr/rc��eZdZdZej
dejejz�Zej
dejejzejz�Z
ej
d�jZdd�Z
d�Zdd�Zd�Zej
d	ej�Zd
�Zej
dej�Zd�Zd
�Zd�Zy)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^[ ]*(#.*)?$c��|j�}|j|�}|dkDr1dj|jd�D�cgc]}||d��	c}�}g}d\}}|jj|�D]�}|j
|||j��||jd||j��z
}|j|||�\}	}
}}|j|	�s;|j
t|	||||t|jd��z|
���||jd|j�|j��z
}|j�}��|j
||d�|Scc}w)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#r|N�r#r#rk)r�rkr�)�
expandtabs�_min_indentr�r��_EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr,�groupr�)
r~�stringr-�
min_indent�l�output�charnor��mr�r�r�r�s
             r.�parsezDocTestParser.parse|sj���"�"�$���%�%�f�-�
���>��Y�Y����T�8J�K�1��*�+��K�L�F��������!�!�*�*�6�2�	�A��M�M�&�����	�2�3��f�l�l�4������;�;�F��(�(��D�&�9�
-�V�W�d�G��,�,�V�4��
�
�w�v�t�W�+1�+5�c�!�'�'�(�:K�6L�+L�,3� 5�7�

�f�l�l�4�����A�E�E�G�<�<�F��U�U�W�F�#	�&	�
�
�f�V�W�o�&��
��3 Ls�Fc�B�t|j||�|||||�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)r~r�r6r-r`r�s      r.�get_doctestzDocTestParser.get_doctest�s+���t�(�(���6���X�v�v�7�	7r/c�l�|j||�D�cgc]}t|t�r|��c}Scc}w)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.
        )r�r@r)r~r�r-�xs    r.rzDocTestParser.get_examples�s8�� �:�:�f�d�3�+�a��a��)��+�	+��+s�1c	���t|jd��}|jd�jd�}|j||||�|j	|ddd|zdz||�dj|D�cgc]
}||dzd��c}�}|jd	�}|jd�}	t|	�dkDrt
jd
|	d�r|	d=|j	|	d|z||t|�z�dj|	D�
cgc]}
|
|d��	c}
�}|jj|�}|r|jd�}nd}|j|||�}||||fScc}wcc}
w)
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.
        rkr�r|r)Nrgr��r�z *$r�r�)
r,r�r��_check_prompt_blank�
_check_prefixr�rh�match�
_EXCEPTION_RE�
_find_options)
r~r�r-r�rk�source_lines�slr�r��
want_lines�wlr�r�s
             r.r�zDocTestParser._parse_example�so���Q�W�W�X�&�'���w�w�x�(�.�.�t�4��� � ��v�t�V�D����<���+�S��Z�#�-=�t�V�L����L�A�b�B�v�a�x�y�M�A�B��
�w�w�v����Z�Z��%�
��z�?�Q��2�8�8�F�J�r�N�#C��2�����:�s�6�z�4�!�C��$5�5�	7��y�y�
�;�"�"�V�W�+�;�<��
���$�$�T�*����g�g�e�n�G��G��$�$�V�T�6�:���w��g�-�-��/B��<s�;E,�E1z#\s*doctest:\s*([^\n\'"]*)$c
��i}|jj|�D]x}|jd�jdd�j	�}|D]B}|ddvs|ddt
vrt
d|dz�d|�d	|����t
|dd}|dd
k(||<�D�z|r%|j|�rt
d|�d|�d|����|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)�,rgr#z+-N�line z of the doctest for z has an invalid option: �+z4 has an option directive on a line with no example: )�_OPTION_DIRECTIVE_REr�r��replacer�r*r�r�)	r~r�r-r�r�r��option_strings�option�flags	         r.rzDocTestParser._find_options�s������*�*�3�3�F�;�		3�A��W�W�Q�Z�/�/��S�9�?�?�A�N�(�
3���1�I�T�)��1�2�J�&9�9�$�&,�Q�h��f�&>�?�?�+�6�!�"�:�6��!'���c�!1���
�
3�		3��t�0�0��8��$�d�F�4�5�
5��r/z
^([ ]*)(?=\S)c��|jj|�D�cgc]
}t|���}}t|�dkDrt|�Sycc}w)z;Return the minimum indentation of any non-blank line in `s`r#)�
_INDENT_RE�findallr,�min)r~rjrk�indentss    r.r�zDocTestParser._min_indentsG��-1�_�_�-D�-D�Q�-G�H�6�3�v�;�H��H��w�<�!���w�<����	Is�Ac��t|�D]E\}}t|�|dzk\s�||dzdk7s�$td||zdz�d|�d|||dz�d|����y	)
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.
        rrVrgrr)� of the docstring for z lacks blank after z: N)�	enumerater,r�)r~�linesrkr-r�r�r�s       r.rz!DocTestParser._check_prompt_blanksn��!��'�	@�G�A�t��4�y�F�1�H�$��f�Q�h��3�)>� �"(��(�1�*�d�"&�v�f�Q�h�"7��"?�@�@�	@r/c	��t|�D]3\}}|s�	|j|�r�td||zdz�d|�d|����y)z�
        Check that every line in the given list starts with the given
        prefix; if any line does not, then raise a ValueError.
        rr)rz& has inconsistent leading whitespace: N)r r�r�)r~r!�prefixr-r�r�r�s       r.rzDocTestParser._check_prefix'sK��
!��'�	;�G�A�t��D�O�O�F�3� �"(��(�1�*�d�D�":�;�;�	;r/N)z<string>)r=r�r�r�rh�compile�	MULTILINE�VERBOSEr��DOTALLr
r	r�r�rrr�rrrr�rrr�r/r.rrLs�����"�*�*���\�\�B�J�J�
&�(�K�,�B�J�J� ��Z�Z�"�,�,�
&����
2�4�M�&�2�:�:�o�6�<�<��%�N
7�+�*.�f&�2�:�:�&D�&(�l�l�4���8����,�b�l�l�;�J��@�	;r/rc�P�eZdZdZde�ddfd�Zdd�Zd�Zd�Zd	�Z	d
�Z
d�Zy)
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.
    FTc�<�||_||_||_||_y)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)r~�verbose�parser�recurse�
exclude_emptys     r.r�zDocTestFinder.__init__@s!��"�����
���
�+��r/Nc	��|�&t|dd�}|�tdt|�����|durd}n|�tj|�}	tj
|�}|s%tj|�}|d|ddzdk(sd}|�d}n=|�!tj||j�}ntj|�}|sd}	|� |�i}n+|jj�}n|j�}|�|j|�d|vrd|d<g}|j||||||i�|j�|S#t$rd}Y��wxYw)	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 {}.

        Nr=zHDocTestFinder.find: name must be given when obj.__name__ doesn't exist: Fr#���z<]>r�)r4r�r�r>�	getmodule�
getsourcefile�getfile�	linecache�getlines�__dict__rLr��update�_find�sort)	r~�objr-rMr6�
extraglobsrnr�testss	         r.r�zDocTestFinder.findVsx��H�<��3�
�D�1�D��|� �"&�s�)�".�/�/��U�?��F�
�^��&�&�s�+�F�
	(��(�(��-�D�����s�+���A�w�t�B�C�y�(�E�1�$�4��|�#���%�$-�#5�#5�d�F�O�O�#L�L�$-�#5�#5�d�#;�L�#�#'�L��=��~������,�,�.���J�J�L�E��!��L�L��$��U�"� *�E�*�����
�
�5�#�t�V�\�5�"�E�
	�
�
�����Y�	 ��L�	 �s�D?�?E
�E
c��|�ytj|��|tj|�uStj|�r|j|juStj
|�stj|�rLt|d�r|jj}nt|d�r
|j}ny|j|k(Stj|�r|j|jk(St|d�r|j|jk(St|t�rytd��)zY
        Return true if the given object is defined in the given
        module.
        T�__objclass__r�z"object must be a class or function)r>r4�
isfunctionr9�__globals__�ismethoddescriptor�ismethodwrapperr]rAr�r=�isclassr@�propertyr�)r~rM�object�obj_mods    r.�_from_modulezDocTestFinder._from_module�s
��
�>��
�
�
�v�
&�
2��W�.�.�v�6�6�6�
�
�
��
'��?�?�f�&8�&8�8�8��(�(��0��%�%�f�-��v�~�.� �-�-�8�8�����.� �+�+����?�?�g�-�-�
�_�_�V�
$��?�?�f�&7�&7�7�7�
�V�\�
*��?�?�f�&7�&7�7�7�
���
)���A�B�Br/c�z�|}	tj|�}tj|�S#t$rY� wxYw)zL
        Safely unwrap objects and determine if they are functions.
        )r>�unwrapr��	isroutine)r~r=�
maybe_routines   r.�_is_routinezDocTestFinder._is_routine�sC���
�	�#�N�N�=�9�M�� � ��/�/���	��	�s�.�	:�:c
�z�|jrtd|z�t|�|vryd|t|�<|j|||||�}|�|j	|�tj|�r�|jrz|jj�D]]\}	}
|�d|	��}	|j|
�stj|
�s�4|j||
�s�G|j||
|	||||��_tj|�r�|jr�t|di�j�D]�\}	}
t|	t �st#dt%|	�����tj&|
�sQtj|
�s<tj|
�s't|
t �st#dt%|
�����|�d|	��}	|j||
|	||||���tj|�r�|jr�|jj�D]�\}	}
t|
t(t*f�r|
j,}
tj&|
�s&tj|
�st|
t.�s�c|j||
�s�v|�d|	��}	|j||
|	||||���yyy)	zm
        Find tests for the given object and any contained objects, and
        add them to `tests`.
        zFinding tests in %sNr)r��__test__z3DocTestFinder.find: __test__ keys must be strings: z^DocTestFinder.find: __test__ values must be strings, functions, methods, classes, or modules: z
.__test__.)r+�printr��	_get_testr�r>r?r,r9�itemsrOrFrJr;r4r@rAr�r�rM�staticmethod�classmethod�__func__rG)r~r?r=r-rMrr6�seen�test�valname�vals           r.r;zDocTestFinder._find�sf��
�=�=��'�$�.�/��c�7�d�?����R��W�
��~�~�c�4����E�����L�L������C� �T�]�]� #��� 2� 2� 4�
,����%)�7�3���%�%�c�*�g�o�o�c�.B��%�%�f�c�2��J�J�u�c�7�F�L�$�d�,�

,����C� �T�]�]� '��Z�� <� B� B� D�

(����!�'�3�/�$�&*�7�m�&6�7�7� �)�)�#�.�'�/�/�#�2F��(�(��-��C��1E�$�'+�3�i�&2�3�3�/3�G�<���
�
�5�#�w��� �$�(�

(� �?�?�3��D�M�M� #��� 2� 2� 4�
,�����c�L�+�#>�?��,�,�C��&�&�s�+�w���s�/C� ��h�/��'�'���4�)-�w�7�G��J�J�u�c�7�F�L�$�d�,�
,�%2�r/c��t|t�r|}n7	|j�d}n'|j}t|t�st|�}|j||�}|jr|sy|�d}n(t|dd�xs|j}|dddk(r|dd}|jj|||||�S#ttf$rd}Y��wxYw)zs
        Return a DocTest for the given object, if it defines a docstring;
        otherwise, return None.
        Nr�r�����.pycr�)r@rAr�rLrH�_find_linenor-r4r=r*r)	r~r=r-rMr6rr�r�r`s	         r.rSzDocTestFinder._get_test!s����c�3���I�
��;�;�&� "�I� #���I�%�i��5�$'�	�N�	�
�"�"�3��5�����y���>��H��v�z�4�8�K�F�O�O�H����}��&�#�C�R�=���|�|�'�'�	�5�$�(0�&�:�	:��%�~�.�
��	�
�s�6B8�8C�Cc
��d}t|dd�}tj|�r|�d}tj|�rc|�a|�yt	j
dt	jt|dd��z�}t|�D]\}}|j|�s�|}ntj|�r|j}t|t�r|j}tj|�r,t|dd�rtj|�j }tj"|�r|j$}tj&|�r|j(}tj*|�r|j,dz
}|�N|�|dzSt	j
d�}t/|t1|��D]}|j||�s�|cSy)	z�
        Return a line number of the given object's docstring.

        Returns `None` if the given object does not have a docstring.
        Nr�r#z^\s*class\s*%s\br=�-r)z(^|.*:)\s*\w*("|\'))r4r>r?rFrhr$�escaper r	�ismethodrWr@rG�fgetrBrL�__code__�istraceback�tb_frame�isframe�f_code�iscode�co_firstlineno�ranger,)r~r=rr�r��patr�r�s        r.r_zDocTestFinder._find_linenoGs������C��D�1�	����C� �Y�%:��F�
�?�?�3��I�$9��#���*�*�0��Y�Y�w�s�J��'D�E�F�G�C�$�\�2�
���4��9�9�T�?��F��
����C� ����#��c�8�$��(�(�C����c�"�w�s�I�t�'D��.�.��%�.�.�C����s�#�3�<�<�S��?�?�3��s�z�z���>�>�#���'�'�!�+�F����#��a�x���*�*�3�4�C����L�(9�:�
"���9�9�\�&�1�2�!�M�
"�
r/�NNNN)r=r�r�r�rr�r�rJrOr;rSr_r�r/r.rr7s=��� %�]�_��T�,�,d�LC�:	0�;,�z$:�L4r/rc��eZdZdZdZdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Ze
jd�Zdd
�Zdd�Zdd�Zd�Zy)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**********************************************************************Nc���|xs
t�|_|�dtjv}||_||_||_d|_d|_i|_	t�|_y)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�_checkerrEr�r+�optionflags�original_optionflags�tries�failures�_name2ftry�_fakeout)r~�checkerr.rss    r.r�zDocTestRunner.__init__�s^��" �2�=�?��
��?��c�h�h�&�G���
�&���$/��!���
���
���
�"���
r/c���|jrf|jr8|dt|j�zdzt|j�z�y|dt|j�zdz�yy)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+r�rlr�)r~r�rY�examples    r.�report_startzDocTestRunner.report_start�sj��
�=�=��|�|��K�'�'�.�.�"9�9�"�#�%,�W�\�\�%:�;�<��K�'�'�.�.�"9�9�)�*�+�r/c�.�|jr	|d�yy)zt
        Report that the given example ran successfully.  (Only
        displays a message if verbose=True)
        zok
N)r+�r~r�rYr{r�s     r.�report_successzDocTestRunner.report_success�s��
�=�=���K�r/c��||j||�|jj|||j�z�y)z7
        Report that the given example failed.
        N)�_failure_headerrr�output_differencersr~s     r.�report_failurezDocTestRunner.report_failure�s>��	�D� � ��w�/��M�M�+�+�G�S�$�:J�:J�K�
L�	Mr/c�d�||j||�dztt|��z�y)zO
        Report that the given example raised an unexpected exception.
        zException raised:
N)r�rlrw�r~r�rYr{rrs     r.�report_unexpected_exceptionz)DocTestRunner.report_unexpected_exception�s8��	�D� � ��w�/�!�
"�$+�,@��,J�$K�
L�	Mr/c���|jg}|jrf|j�)|j�|j|jzdz}nd}|jd|j�d|�d|j���n.|jd|jdz�d|j���|jd�|j
}|jt
|��dj|�S)	Nr)�?zFile "�", line �, in zLine zFailed example:r|)�DIVIDERr`r�r�r-r�rlr�)r~rYr{r�r�r�s      r.r�zDocTestRunner._failure_headers����|�|�n���=�=��{�{�&�7�>�>�+E����w�~�~�5��9�����J�J��
�
�v�t�y�y�:�
;�
�J�J�7�>�>�!�+;�T�Y�Y�G�H��
�
�$�%������
�
�7�6�?�#��y�y��~�r/c
�\��dx}}|j}td�\}}}	|jj}
t	|j
�D�]�\}}|jtzxr|dkD}
||_|jrP|jj�D]3\}}|r|xj|zc_�|xj|zc_�5|jtzr��|dz
}|
s|j|||�d|j|fz}	tt|j|d|d�|j�|j j#�d}|j*j-�}|j*j/d�|}|�#|
|j0||j��r|}�nt3j4|dd�}t7|dt8�rV|dj:�d	�|dj<�d
|dj:�d	�f�t?�fd�t	|�D��}||d}djA|�}|
s|tC|�z
}|jD�|	}nf|
|jD||j�r|}nE|jtFzr2|
tI|jD�tI|�|j�r|}||ur|
s^|jK||||�nI||ur|
s|jM||||�|dz
}n)||	ur|
s|jO||||�|dz
}n	Jd
|f��|s���|jtPzs���n||_|jS|||�tU||�S#t$$r�t'j(�}|j j#�Y��RxYw)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#rVr)z<doctest %s[%d]>�singleTNr�r�r�c3�J�K�|]\}}|j��r|���y�wr�)r�)�.0�indexr��exception_line_prefixess   �r.�	<genexpr>z&DocTestRunner.__run.<locals>.<genexpr>qs*�����)�'�E�4��?�?�+B�C��)�s� #r�zunknown outcome)+rsrlrr�check_outputr r�r
r�rTrr|r-�execr$r�r6�debuggerr��KeyboardInterruptrErrrxrqr�r�ro�format_exception_only�
issubclass�SyntaxErrorr�r��nextr�rwr�rr�rr�r�r�_DocTestRunner__record_outcomer')r~rY�compileflagsr�rvrurt�SUCCESS�FAILURE�BOOM�check�
examplenumr{�quiet�
optionflagr[r`�	exceptionr��outcome�formatted_ex�
exc_msg_indexr�r�s                       @r.�__runzDocTestRunner.__runs�������5� $�/�/��!&�q�����$��
�
�*�*��$-�T�]�]�#;�o	��J���%�%�(A�A�"���\�
� 4�D�����)0���)>�)>�)@�8�%�Z����(�(�J�6�(��(�(�Z�K�7�(�	8����$�&��
�Q�J�E���!�!�#�t�W�5�
*�T�Y�Y�
�,C�C�H�


-��W�W�^�^�X�x�)�4�1�26�*�*�>��
�
�*�*�,� �	��-�-�(�(�*�C��M�M�"�"�1�%��G�� �����s�D�,<�,<�=�%�G� )�>�>�	�"�1�
�N���i��l�K�8�%�Q�<�4�4�5�Q�7�$�Q�<�2�2�3�1�Y�q�\�5N�5N�4O�q�Q�/�+�%)�)�+4�\�+B�)�%�M�
$0�
��#?�L��'�'�,�/����/�	�:�:�C��?�?�*�"�G��7�?�?�G�T�5E�5E�F�%�G��%�%�(?�?��5�g�o�o�F�5�g�>�!�-�-�/�#*���'�!���'�'��T�7�C�@��G�#���'�'��T�7�C�@��A�
���D����4�4�S�$��5>�@��A�
��:�0�'�:�:�u��D�,�,�y�8��_o	�d0���	
���d�H�e�4��8�U�+�+��_%�
��
-��L�L�N�	��
�
�*�*�,�s
�A	M/�/9N+c���|jj|jd�\}}||z||zf|j|j<|xj|z
c_|xj|z
c_y)z{
        Record the fact that the given DocTest (`test`) generated `f`
        failures out of `t` tried examples.
        r�N)rwr3r-rvru)r~rYrd�t�f2�t2s      r.�__record_outcomezDocTestRunner.__record_outcome�s[��
���"�"�4�9�9�e�4���B�$%�b�D�!�B�$�<��
�
�d�i�i� ��
�
���
��
�
�a��
r/z.<doctest (?P<name>.+)\[(?P<examplenum>\d+)\]>$c�J�|jj|�}|ru|jd�|jjk(rM|jj
t
|jd��}|jjd��S|j||�S)Nr-r�T��keepends)
�%_DocTestRunner__LINECACHE_FILENAME_REr	r�rYr-r��intr��
splitlines�save_linecache_getlines)r~r`�module_globalsr�r{s     r.�__patched_linecache_getlinesz*DocTestRunner.__patched_linecache_getlines�s���(�(�.�.�x�8��������D�I�I�N�N�2��i�i�(�(��Q�W�W�\�-B�)C�D�G��>�>�,�,�d�,�;�;��/�/��.�I�Ir/c�v�	�
�||_|�t|j�}tj�
|�4�
j
�	�	��	j
�dk(r
�
j}n�	�
fd�}|jt_tj�}tj}t�
�|_
|jj�|jjt_tj |_|j$t_tj&}tj(t_	|j+|||��
t_|t_tj,|�|j"t_|t_|r&|jj/�ddl}d|_SS#�
t_|t_tj,|�|j"t_|t_|r&|jj/�ddl}d|_wwxYw)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-8c�`��t|j�d���}�j|�y)N�backslashreplace)rA�encode�write)rjrYr�s ��r.r�zDocTestRunner.run.<locals>.out�s)����A�H�H�X�/A�B�H�M�A��%�%�a�(r/r#)rYr:r6rEr�rY�lowerr�rx�gettracer�r�r�r��resetr7r8r��*_DocTestRunner__patched_linecache_getlines�displayhook�__displayhook__�_DocTestRunner__run�settrace�clear�builtins�_)r~rYr�r��clear_globs�
save_trace�save_set_trace�save_displayhookr�rYr�s         @@r.�runzDocTestRunner.run�s����(��	���0����<�L��j�j���;�"�+�+�H���8�>�>�#3�w�#>�!�'�'��)��]�]��
��\�\�^�
�����-�k�:��
��
�
�����
�
�/�/��
�(1�'9�'9��$�!�>�>�	���?�?���-�-���	"��:�:�d�L�#�6�$�C�J�*�C�M��L�L��$�!%�!=�!=�I��.�C�O���
�
� � �"��!��
���%�C�J�*�C�M��L�L��$�!%�!=�!=�I��.�C�O���
�
� � �"��!��
��s
�=G�A5H8c��|�|j}g}g}g}dx}}|jj�D]\}|\}\}	}
|	|
ksJ�||
z
}||	z
}|
dk(r|j|��3|	dk(r|j||
f��L|j|��^|r{|r8t	t|�d�|j
�|D]}t	d|��|r?t	t|�d�|j
�|D]\}}t	d||fz��|rXt	|j�t	t|�d�|j
�|D]\}\}	}
t	d|	|
|fz��|r2t	|dt|j�d	�t	||z
d
|d�|rt	d|d
�n
|rt	d�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.
        r#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+rwrTr�rRr,r<r�r')
r~r.�notests�passed�failed�totalt�totalfrr-rdr��thingr�s
             r.�	summarizezDocTestRunner.summarizes����?��m�m�G��������������$�$�&�
	!�A��L�D�&�1�a���6�M�6��a�K�F��a�K�F��A�v����t�$��a���
�
��a�y�*��
�
�a� �
	!����c�'�l�$9�:�����$�(�E��%��'�(���c�&�k�#<�=����
�$*�?�L�E�5��,��u�~�=�>�?���$�,�,���#�f�+�4�5��K�K�M�!'�
;�
��v��1��)�Q��5�M�9�:�
;���&�*�c�$�-�-�&8�(�C��&�6�/�<���C���%�v�{�;�
��.�!��6�6�*�*r/c��|j}|jj�D]%\}\}}||vr||\}}||z}||z}||f||<�'yr�)rwrT)r~r��dr-rdr�r�r�s        r.�mergezDocTestRunner.merge=sd���M�M��!�N�N�0�0�2�		�L�D�&�1�a��q�y�
�4����B���F����F����d�A�d�G�		r/)NNr#r��NNT)r=r�r�r�r�r�r|rr�r�r�r�r�rhr$r�r�r�r�r�r�r/r.rr�sn��6�r�G�$�H+��M�M��(L,�\�)�b�j�j�*F�G��J�D"�R4+�rr/rc�(�eZdZdZd�Zd�Zd�Zd�Zy)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.
    c�:�t|jdd�d�S)z=
        Convert string to hex-escaped ASCII string.
        �ASCIIr�)rAr�)r~rjs  r.�_toAsciizOutputChecker._toAsciiRs���1�8�8�G�%7�8�'�B�Br/c��|j|�}|j|�}||k(ry|tzs||fdk(ry||fdk(ry|tzsNtjdtj
t�zd|�}tjdd|�}||k(ry|tzrDdj|j��}dj|j��}||k(ry|tzr
t||�ryy)	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]+$rgF)r�rrrhrirb�BLANKLINE_MARKERrr�r�rr��r~r�r�rss    r.r�zOutputChecker.check_outputXs��� �m�m�C� ���}�}�T�"���$�;���4�4��D�z�.�.���D�z�/�/���3�3��6�6�/�B�I�I�6F�,G�G��d�$�D��&�&�*�B��4�C��d�{��
�-�-��(�(�3�9�9�;�'�C��8�8�D�J�J�L�)�D��d�{����!��t�S�)��r/c��|ttztzzsy|tzry|jd�dkDxr|jd�dkDS)NFTr|r�)r
rrr�r�s    r.�_do_a_fancy_diffzOutputChecker._do_a_fancy_diff�sV���l�*�+�*�+�,����%���z�z�$��!�#�;��	�	�$��!�(;�;r/c��|j}|tzstjdt|�}|j|||�r�|j
d��}|j
d��}|tzr)tj||d��}t|�dd}d}n�|tzr)tj||d��}t|�dd}d}nR|tzrBtjtj�	�}	t|	j!||��}d
}nJd��d|zt#d
j%|��zS|r|rdt#|��dt#|���S|rdt#|�zS|rdt#|�zSy)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�r�)�nNz#unified diff with -expected +actualz-context diff with expected followed by actual)�charjunkzndiff with -expected +actualzBad diff optionzDifferences (%s):
r�z
Expected:
zGot:
zExpected:
%sGot nothing
zExpected nothing
Got:
%szExpected nothing
Got nothing
)r�rrhrir�r�r�r
�difflib�unified_diff�listr�context_diffr�Differ�IS_CHARACTER_JUNK�comparerlr�)
r~r{r�rsr�r�	got_lines�diff�kind�engines
          r.r�zOutputChecker.output_difference�s_���|�|���3�3��&�&�*�,<�c�B�C�� � ��s�K�8����$��7�J������5�I��\�)��+�+�J�	�Q�G���D�z�!�"�~��<���|�+��+�+�J�	�Q�G���D�z�!�"�~��F���|�+� ����1J�1J�K���F�N�N�:�y�A�B��5��+�+�+�q�(�4�/�'�"�'�'�$�-�2H�H�H��C�.5�d�m�W�S�\�J�J�
�/�'�$�-�?�?�
�/�'�#�,�>�>�4r/N)r=r�r�r�r�r�r�r�r�r/r.rrJs���C�<�~<�.,5r/rc��eZdZdZd�Zd�Zy)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
    c�.�||_||_||_yr�)rYr{r�)r~rYr{r�s    r.r�zDocTestFailure.__init__�s����	������r/c�,�t|j�Sr��rArYr�s r.�__str__zDocTestFailure.__str__�����4�9�9�~�r/N�r=r�r�r�r�r�r�r/r.rr�s��	��
r/rc��eZdZdZd�Zd�Zy)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
    c�.�||_||_||_yr�)rYr{rr)r~rYr{rrs    r.r�zUnexpectedException.__init__�s����	���� ��
r/c�,�t|j�Sr�r�r�s r.r�zUnexpectedException.__str__�r�r/Nr�r�r/r.rr�s��	�!�
r/rc�$�eZdZdZdd�Zd�Zd�Zy)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
         {}

       Nc�p�tj||||d�}|r|jj�|S)NF)rr�r6r�)r~rYr�r�r��rs      r.r�zDebugRunner.run]s2�����d�D�,��U�C����J�J�����r/c��t|||��r�)rr�s     r.r�z'DebugRunner.report_unexpected_exceptioncs��!�$���:�:r/c��t|||��r�)rr~s     r.r�zDebugRunner.report_failurefs���T�7�C�0�0r/r�)r=r�r�r�r�r�r�r�r/r.rrs��X�t�;�1r/rTFc	���|�tjjd�}tj|�std|����|�|j}t|��}	|rt||��}
n
t||��}
|	j||||��D]}|
j|��|r|
j�t�|
a
ntj|
�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.
    r�ztestmod: module required; )r1�r.rs�r6r>)rErFr3r>r?rLr=rrrr�r�r��masterr�r'rvru)r�r-r6r.�reportrsr>�raise_on_errorr1�finder�runnerrYs            r.rrrs���J	�y�
�K�K�O�O�J�'�����A���!�=�>�>��|��z�z����
7�F���W�+�F���w�K�H�����A�t�5�Z��H����
�
�4��������
�~������V���v������5�5r/c��|r
|std��t||||xsd�\}}|�tjj	|�}|�i}n|j�}|�|j
|�d|vrd|d<|	rt||��}
n
t||��}
|
j||||d�}|
j|�|r|
j�t�|
antj|
�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.r�r=r�rr#)r�rer�r��basenamer�r:rrrr�r�rr�r'rvru)r`rbr-rar6r.rrsr>rr/rY�textrrYs               r.rr�s��d���+�,�	,�$�H�g��$,�$7��9�N�D�(��|��w�w����)��
�}����
�
�����
���Z� ����&��j����W�+�F���w�K�H�����d�E�4��1�=�D�
�J�J�t��
�����
�~������V���v������5�5r/c��t|d��}t||��}|j|||��D]}|j||���y)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.r0r)r6)r�N)rrr�r�)	rdr6r.r-r�rsrrrYs	         r.rrUsJ��$�7�E�
:�F�
�7��
D�F����A�t�5��1�4���
�
�4�l�
�3�4r/c�F�|tz|k7rtd|��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)rr��_unittest_reportflags)r7�olds  r.rrrs/��:	���E�)��7��?�?�
�C�!���Jr/c�l�eZdZ		d
d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Ze
jZd�Zy)�DocTestCaseNc��tjj|�||_||_||_||_||_yr�)�unittest�TestCaser��_dt_optionflags�_dt_checker�_dt_test�	_dt_setUp�_dt_tearDown)r~rYrs�setUp�tearDownrys      r.r�zDocTestCase.__init__�s>��	���"�"�4�(�*���"�����
����$��r/c��|j}|jj�|_|j�|j	|�yyr�)rr6r��	_dt_globsr�r~rYs  r.rzDocTestCase.setUp�s8���}�}�������*����>�>�%��N�N�4� �&r/c���|j}|j�|j|�|jj�|jj	|j
�yr�)rrr6r�r:rrs  r.rzDocTestCase.tearDown�sM���}�}�����(����d�#�	
�
�
�����
�
���$�.�.�)r/c��|j}tj}t�}|j}|t
zs	|tz}t||jd��}	d|_	|j||jd��\}}|t_|r.|j|j|j����y#|t_wxYw)NF�rsryr.zF----------------------------------------------------------------------)r�r�)rrEr�r$rrr
rrr�r�r��failureException�format_failurerq)r~rYr�newrsrrvrus        r.�runTestzDocTestCase.runTest�s����}�}���j�j���j���*�*���o�-�
�0�0�K��;�'+�'7�'7��H��	�#�F�N�$�j�j��#�)�)��)�8�O�H�e��C�J���'�'��(;�(;�C�L�L�N�(K�L�L����C�J�s�(C�
Cc
��|j}|j�d}nd|jz}dj|jj	d�dd�}d|j�d|j
�d|�d|�d	|��
S)
Nzunknown line numberz%sr�r��Failed doctest test for �	
  File "r�r�z

)rr�r�r-r�r`)r~�errrYr��lnames     r.r"zDocTestCase.format_failure�sj���}�}���;�;��*�F��D�K�K�'�F����������-�b�c�2�3���9�9�d�m�m�V�U�C�A�	r/c���|j�t|j|jd��}|j	|j
d��|j
�y)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 )r�N)rrrrr�rr)r~rs  r.r"zDocTestCase.debug�sI��D	
�
�
����)=�)=�%)�%5�%5�u�F���
�
�4�=�=�e�
�4��
�
�r/c�.�|jjSr��rr-r�s r.r�zDocTestCase.id	s���}�}�!�!�!r/c�D�t|�t|�urtS|j|jk(xrj|j|jk(xrO|j|jk(xr4|j
|j
k(xr|j|jk(Sr�)r�r�rrrrrr�s  r.r�zDocTestCase.__eq__"	s�����:�T�%�[�(�!�!��}�}����.�5��#�#�u�'<�'<�<�5��~�~����0�5�� � �E�$6�$6�6�5����5�#4�#4�4�		5r/c�p�t|j|j|j|jf�Sr�)r�rrrrr�s r.r�zDocTestCase.__hash__,	s3���T�)�)�4�>�>�4�;L�;L��%�%�'�(�	(r/c��|jjjd�}|d�ddj|dd��d�S)Nr�r�r��))rr-r�r�)r~r-s  r.r�zDocTestCase.__repr__0	s:���}�}�!�!�'�'��,�� ��H�c�h�h�t�C�R�y�&9�:�:r/c�4�d|jjzS)Nz	Doctest: r,r�s r.�shortDescriptionzDocTestCase.shortDescription6	s���T�]�]�/�/�/�/r/)r#NNN)r=r�r�r�rrr$r"r"r�r�r�r�rHr�r2r�r/r.rr�sM��AE��%�!�*�M�0
�F�P"�5�(�;��n�n�G�0r/rc�(�eZdZd�Zd�Zd�Zd�ZeZy)�SkipDocTestCasec�>�||_tj|d�yr�)rMrr�)r~rMs  r.r�zSkipDocTestCase.__init__:	s��������T�4�(r/c�&�|jd�y)Nz-DocTestSuite will not work with -O2 and above)�skipTestr�s r.rzSkipDocTestCase.setUp>	s���
�
�E�Fr/c��yr�r�r�s r.�	test_skipzSkipDocTestCase.test_skipA	���r/c�4�d|jjzS)NzSkipping tests from %s)rMr=r�s r.r2z SkipDocTestCase.shortDescriptionD	s��'�$�+�+�*>�*>�>�>r/N)r=r�r�r�rr9r2r�r�r/r.r4r49	s��)�G�
�?��Gr/r4c��eZdZd�Zy)�
_DocTestSuitec��yr�r�)r~r�s  r.�_removeTestAtIndexz _DocTestSuite._removeTestAtIndexL	r:r/N)r=r�r�r?r�r/r.r=r=J	s��
r/r=c���|�
t�}t|�}|j|||��}|sCtjj
dk\r&t
�}|jt|��|S|j�t
�}|D]b}t|j�dk(r�|js |j}|dddk(r|dd}||_|jt|fi|����d|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.
    Nrr�r#r]r^r�)rrOr�rEr7�optimizer=�addTestr4r<r,r�r`r�r)	rMr6r>�test_finderr�r?�suiterYr`s	         r.rrP	s���J��#�o��
�v�
&�F����V�5�Z��H�E��S�Y�Y�'�'�!�+����
�
�
�o�f�-�.���	�J�J�L��O�E��4���t�}�}���"���}�}����H����}��&�#�C�R�=��$�D�M�
�
�
�k�$�2�'�2�3�4��Lr/c��eZdZd�Zd�Zd�Zy)�DocFileCasec�j�dj|jjjd��S)Nr�r�)r�rr-r�r�s r.r�zDocFileCase.id�	s&���x�x��
�
�*�*�0�0��5�6�6r/c�.�|jjSr�)rr`r�s r.r�zDocFileCase.__repr__�	s���}�}�%�%�%r/c�h�d|jj�d|jj�d|��S)Nr&r'z", line 0

)rr-r`)r~r(s  r.r"zDocFileCase.format_failure�	s(���=�=�%�%�t�}�}�'=�'=�s�D�	r/N)r=r�r�r�r�r"r�r/r.rFrF�	s��7�&�r/rFc��|�i}n|j�}|r
|std��t||||xsd�\}}d|vr||d<tjj|�}|j
||||d�}	t|	fi|��S)Nrr�r�r#)r�r�rer�r�r	rrF)
r�rbrar6r/rYr��docr-rYs
          r.�DocFileTestrL�	s���
�}����
�
������+�,�	,��t�W�o�'�2�7�4�I�C����� ��j���7�7���D�!�D����c�5�$��a�8�D��t�'�w�'�'r/c��t�}|jdd�rt|jd��|d<|D]}|jt	|fi|����|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.
    rbTra)r=r3rOrBrL)�paths�kwrDr�s    r.rr�	s`��p
�O�E�

�v�v���&�)�"�&�&��*;�<��9�
��/��
�
�
�k�$�-�"�-�.�/��Lr/c�^�g}t�j|�D]�}t|t�rg|j	|j
dd�|j}|s�@|j	d�||jd�ddD�cgc]}d|z��	c}z
}�z||jd�ddD�cgc]
}t|���c}z
}��|r#|ddk(r|j�|r	|ddk(r�|r$|ddk(r|jd�|r	|ddk(r�dj|�dzScc}wcc}w)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>
       Nr�z# Expected:r|z## r�r#)rr�r@rr�r�r�r�r��popr�)rjr��piecer�r�s     r.rr
s2��t�F���&�&�q�)�8���e�W�%��M�M�%�,�,�s��+�,��:�:�D���
�
�m�,��D�J�J�t�,<�S�b�,A�B�q�5��7�B�B��
� %���D� 1�#�2� 6�8��%�Q�'�8�
8�F�8��V�B�Z�3�&��
�
���V�B�Z�3�&�
�V�A�Y�#�%��
�
�1�
��V�A�Y�#�%��9�9�V��t�#�#��C��8s�D%�-D*c���t|�}t�j|�}|D�cgc]}|j|k(s�|��}}|st	|d��|d}t|j�}|Scc}w)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.
    znot found in testsr#)rOrr�r-r�rr�)rMr-r?r�rY�testsrcs      r.r r R
so���v�
&�F��O� � ��(�E��/�!����$��A�/�D�/����3�4�4���7�D�"�4�>�>�2�G��N��0s
�A.�A.c�4�t|�}t|||�y)z4Debug a single doctest docstring, in argument `src`'N)r�debug_script)�src�pmr6rTs    r.r!r!b
s��"�3�'�G���"�e�$r/c��ddl}|r|j�}ni}|r	t|||�y|jd��jd|z||�y#tt	j
�d�|jd��}|j�|jdt	j
�d�YyxYw)z7Debug a test script.  `src` is the script, as a string.r#Nr)T)r�r�zexec(%r))
r�r�r�rRrErrr�r��interactionr�)rWrXr6r��ps     r.rVrVg
s������
�
�����	�	3���e�U�#�	������"�"�:��#3�U�E�B��
	3��#�,�,�.��#�$������&�A�
�G�G�I�
�M�M�$�����q� 1�2�s�
A�A,Cc�`�t|�}t||�}t|||j�y)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)rOr rVr9)rMr-rXrTs    r.r"r"{
s*���v�
&�F����&�G���"�f�o�o�.r/c�"�eZdZdZd�Zd�Zd�Zy)�
_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'
    c��||_y)z�val -> _TestClass object with associated value val.

        >>> t = _TestClass(123)
        >>> print(t.get())
        123
        N�r[)r~r[s  r.r�z_TestClass.__init__�
s����r/c�.�|jdz|_|S)zosquare() -> square TestClass's associated value

        >>> _TestClass(13).square().get()
        169
        r�r`r�s r.�squarez_TestClass.square�
s���8�8�q�=����r/c��|jS)z~get() -> return TestClass's associated value.

        >>> x = _TestClass(-42)
        >>> print(x.get())
        -42
        r`r�s r.r3z_TestClass.get�
s
���x�x�r/N)r=r�r�r�r�rbr3r�r/r.r^r^�
s�����r/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 lines�ellipsiszwhitespace normalizationc��ddl}|jd��}|jddddd�	�|jd
ddtj	�gd
��|jdddd��|jddd��|j�}|j}|j}d}|jD]}|t|z}�|jr	|tz}|D]�}|jd�rstjj|�\}}tjj!d|�t#|dd�}	tjd=t%|	||��\}
}nt'|d||��\}
}|
s��yy)Nr#zdoctest runner)�descriptionrqz	--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)rh�choicesrirjz-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))rhrjrnrz file containing the tests to run)�nargsrjz.py���r)rbr.rsr))�argparse�ArgumentParser�add_argumentr*�keys�
parse_argsrnr.r�	fail_fastrr}r�r�r�rE�insertrBrr)rnr/r��	testfilesr.r�rr`�dirnamer�rvr�s            r.�_testrw�
s����
�
$�
$�1A�
$�
B�F�
����k�,��F��H�
����j�� 3� 8� 8� :�B�E��G�
����m�L�F��H�����c�?��A�����D��	�	�I��l�l�G��G��+�+�/���&�v�.�.��/��~�~��9���������U�#�!#���
�
�h� 7��G�X��H�H�O�O�A�w�'��8�C�R�=�)�A������!�!�W�'�J�K�H�a�"�8�U�-4�'�K�K�H�a����
r/r�)r�)r)	NNNNTr#NFF)F�NoNameNr#rn)FN)F)Tr��
__docformat__�__all__r1r�r>r7r�r�rhrEror�ior$r%�collectionsr&r'r*rrrrrrrr	r
rrr
rrr�r�r:rOrTrerlrwryr�r�r�r�r�rZrrrrrr�	Exceptionrrrrrrrr
rrrr4�	TestSuiter=rrFrLrrr r!rVr"r^rQrwr=�exitr�r/r.�<module>r�s7��%�N&�
�+��Z����	�
�	�
���2�"���(:�;��.��O�-�-E�F��+�,C�D��*�+A�B���z�*���6�"��-�.G�H��*�)�*�(�)����	�
,�,��#�>�2��"�>�2��"�>�2��/�0K�L����,�	��� �� �-�-��	��!����&
�>�2D�"�$/�	� �� �/�b��4"%�C�G�G�"%�J ,�\B$�B$�HGD�GD�Zd;�d;�VD�D�T
G�G�RP5�P5�d�Y��&�)��&e1�-�e1�\
��37�37�05�f6�P(,�$����d���U�=�?��y6�v:B�:;�4�6��!�Ha0�(�#�#�a0�F�k��"
�H�&�&�
�>�@�+��'+�D��=�?��(�4C�RP$�d� %�
C�(	/�*�*�X%��%(� ��)�Q0
��f*
�Z�z���C�H�H�U�W��r/

Zerion Mini Shell 1.0