Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/_pytest/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/_pytest/__pycache__/doctest.cpython-37.pyc

B

C$�X�.�@sdZddlmZddlZddlZddlmZmZmZddl	m
Z
dZdZdZ
d	Zd
Zeee
eefZdd�Zd
d�Zdd�ZGdd�de�ZGdd�dej�Zdd�Zdd�ZGdd�dej�Zdd�ZGdd�dej�Zdd �Zd!d"�Zd#d$�Zd%d&�Z d'd(�Z!ej"d)d*�d+d,��Z#dS)-z5 discover and run doctests in modules and test files.�)�absolute_importN)�
ExceptionInfo�ReprFileLocation�TerminalRepr)�FixtureRequestZnoneZcdiffZndiff�udiffZonly_first_failurecCsx|jddddgd�|�d�}|jddd	d
dd�|jd
tjddtdd�|jddgdddd�|jddd	ddd�dS)N�doctest_optionflagszoption flags for doctests�args�ELLIPSIS)�type�default�collectz--doctest-modules�
store_trueFzrun doctests in all .py modules�doctestmodules)�actionr�help�destz--doctest-reportrz9choose another output format for diffs on doctest failure�
doctestreport)rrr�choicesrz--doctest-glob�append�patz2doctests file matching pattern, default: test*.txt�doctestglob)rr�metavarrrz--doctest-ignore-import-errorszignore doctest ImportErrors�doctest_ignore_import_errors)ZaddiniZgetgroupZ	addoption�str�lower�DOCTEST_REPORT_CHOICES)�parser�group�r�@/opt/alt/python37/lib/python3.7/site-packages/_pytest/doctest.py�pytest_addoptions(
r!cCs>|j}|jdkr$|jjr:t||�Snt|||�r:t||�SdS)Nz.py)�config�ext�optionr�
DoctestModule�_is_doctest�DoctestTextfile)�path�parentr"rrr �pytest_collect_file0s
r*cCsL|jdkr|j�|�rdS|�d�p(dg}x|D]}|j|d�r0dSq0WdS)N)z.txtz.rstTrz	test*.txt)�fnmatchF)r#�sessionZ
isinitpath�	getoption�check)r"r(r)�globs�globrrr r&9s
r&c@seZdZdd�Zdd�ZdS)�ReprFailDoctestcCs||_||_dS)N)�reprlocation�lines)�selfr2r3rrr �__init__EszReprFailDoctest.__init__cCs*x|jD]}|�|�qW|j�|�dS)N)r3�liner2�
toterminal)r4Ztwr6rrr r7IszReprFailDoctest.toterminalN)�__name__�
__module__�__qualname__r5r7rrrr r1Csr1csBeZdZd�fdd�	Zdd�Zdd�Z�fdd	�Zd
d�Z�ZS)
�DoctestItemNcs.tt|��||�||_||_d|_d|_dS)N)�superr;r5�runner�dtest�obj�fixture_request)r4�namer)r=r>)�	__class__rr r5Ps
zDoctestItem.__init__cCsZ|jdk	rVt|�|_t|jjd�}x$|j�d���D]\}}|||<q4W|jj�|�dS)N)Z
getfixture�doctest_namespace)r>�_setup_fixturesr@�dictZgetfixturevalue�itemsr/�update)r4r/rA�valuerrr �setupWs

zDoctestItem.setupcCst|j�|j�|j�dS)N)�_check_all_skippedr>r=�run)r4rrr �runtest_s
zDoctestItem.runtestcsrddl}|�|j|jf��r^|j}|j}|j��j}�jdkrDd}n�j|jd}|j	j
}t|||�}t�}	t
|j�d��}
|dk	r�|jj�d�}�fdd�t|�D�}||jd|jd�}n4dg}d	}x(|j��D]}
|�d
||
f�d}q�W|�|j��r"||	�||j|
��d�7}n2t|jj�}|d
t|j�g7}|tj|jj�7}t||�Stt|�� |�SdS)Nr�rFcs&g|]\}}d|�jd|f�qS)z%03d %srM)�lineno)�.0�i�x)�testrr �
<listcomp>vsz,DoctestItem.repr_failure.<locals>.<listcomp>�	z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z	??? %s %sz...�
zUNEXPECTED EXCEPTION: %s)!�doctestZ
errisinstanceZDocTestFailureZUnexpectedExceptionrH�examplerR�filenamerNrr8r�_get_checker�_get_report_choicer"r-Z	docstring�
splitlines�	enumerate�sourcerZoutput_difference�got�splitr�exc_info�repr�	traceback�format_exceptionr1r<r;�repr_failure)r4�excinforVZdoctestfailurerWrXrN�messager2�checkerZ
report_choicer3�indentr6Z
inner_excinfo)rB)rRr rdcsB


zDoctestItem.repr_failurecCs|jdd|jfS)Nz[doctest] %s)�fspathrA)r4rrr �
reportinfo�szDoctestItem.reportinfo)NN)	r8r9r:r5rIrLrdrj�
__classcell__rr)rBr r;Os
)r;c
Cs0ddl}t|j|j|j|j|j|jt�t	�d�S)Nr)�DONT_ACCEPT_TRUE_FOR_1�DONT_ACCEPT_BLANKLINE�NORMALIZE_WHITESPACEr
�IGNORE_EXCEPTION_DETAIL�COMPARISON_FLAGS�
ALLOW_UNICODE�ALLOW_BYTES)
rVrErlrmrnr
rorp�_get_allow_unicode_flag�_get_allow_bytes_flag)rVrrr �_get_flag_lookup�srucCs4|j�d�}t�}d}x|D]}|||O}qW|S)Nrr)r"Zgetiniru)r)Zoptionflags_strZflag_lookup_tableZflag_acc�flagrrr �get_optionflags�s
rwc@seZdZdZdd�ZdS)r'Nc
cs|ddl}|j��}t|j�}|jj}ddi}t|�}|jd|t�d�}|��}|�	||||d�}	|	j
rxt|	j|||	�VdS)Nrr8�__main__)�verbose�optionflagsrg)
rVri�readr�basenamerw�DebugRunnerrYZ
DocTestParserZget_doctest�examplesr;rA)
r4rV�textrXrAr/rzr=rrRrrr r
�s


zDoctestTextfile.collect)r8r9r:r?r
rrrr r'�sr'cs2ddl�t�fdd�|jD��}|r.t�d�dS)z\raises pytest.skip() if all examples in the given DocTest have the SKIP
    option set.
    rNc3s|]}|j��jd�VqdS)FN)�options�getZSKIP)rOrQ)rVrr �	<genexpr>�sz%_check_all_skipped.<locals>.<genexpr>z!all tests skipped by +SKIP option)rV�allr~�pytest�skip)rRZall_skippedr)rVr rJ�srJc@seZdZdd�ZdS)r%ccs�ddl}|jjdkr&|jj�|j�}nDy|j��}Wn4tk
rh|j�d�rbt	�
d|j�n�YnX|��}t|�}|j
d|t�d�}x.|�||j�D]}|jr�t|j|||�Vq�WdS)Nrzconftest.pyrzunable to import module %r)ryrzrg)rVrir|r"Z
pluginmanagerZ_importconftestZpyimport�ImportError�getvaluer�r�Z
DocTestFinderrwr}rY�findr8r~r;rA)r4rV�module�finderrzr=rRrrr r
�s 
zDoctestModule.collectN)r8r9r:r
rrrr r%�sr%cCs>dd�}i|_|jj}|j||ddd�|_t|�}|��|S)zO
    Used by DoctestTextfile and DoctestItem to setup fixture information.
    cSsdS)Nrrrrr �func�sz_setup_fixtures.<locals>.funcNF)�noder��cls�funcargs)r�r,Z_fixturemanagerZgetfixtureinfoZ_fixtureinforZ
_fillfixtures)Zdoctest_itemr�Zfmr@rrr rD�srDcsHttd�rt��Sddl�ddl�G��fdd�d�j�}|t_t��S)aJ
    Returns a doctest.OutputChecker subclass that takes in account the
    ALLOW_UNICODE option to ignore u'' prefixes in strings and ALLOW_BYTES
    to strip b'' prefixes.
    Useful when the same doctest should run in Python 2 and Python 3.

    An inner class is used to avoid importing "doctest" at the module
    level.
    �LiteralsOutputCheckerrNcs:eZdZdZ��d�j�Z��d�j�Z��fdd�ZdS)z+_get_checker.<locals>.LiteralsOutputCheckerz�
        Copied from doctest_nose_plugin.py from the nltk project:
            https://github.com/nltk/nltk

        Further extended to also support byte literals.
        z(\W|^)[uU]([rR]?[\'\"])z(\W|^)[bB]([rR]?[\'\"])cs��j�||||�}|rdS|t�@}|t�@}|s:|s:dS�fdd�}|rb||j|�}||j|�}|r~||j|�}||j|�}�j�||||�}|SdS)NTFcs��|d|�S)Nz\1\2)�sub)ZregexZtxt)�rerr �remove_prefixesszQ_get_checker.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes)�
OutputChecker�check_outputrsrt�_unicode_literal_re�_bytes_literal_re)r4Zwantr^rz�resZ
allow_unicodeZallow_bytesr�)rVr�rr r�
s$

z8_get_checker.<locals>.LiteralsOutputChecker.check_outputN)	r8r9r:�__doc__�compile�UNICODEr�r�r�r)rVr�rr r��s)�hasattrrYr�rVr�r�)r�r)rVr�r rY�s

$rYcCsddl}|�d�S)z7
    Registers and returns the ALLOW_UNICODE flag.
    rNrq)rV�register_optionflag)rVrrr rs'srscCsddl}|�d�S)z5
    Registers and returns the ALLOW_BYTES flag.
    rNrr)rVr�)rVrrr rt/srtc
Cs,ddl}t|jt|jt|jt|jt	di|S)z�
    This function returns the actual `doctest` module flag value, we want to do it as late as possible to avoid
    importing `doctest` and all its dependencies when parsing options, as it adds overhead and breaks tests.
    rN)
rV�DOCTEST_REPORT_CHOICE_UDIFFZREPORT_UDIFF�DOCTEST_REPORT_CHOICE_CDIFFZREPORT_CDIFF�DOCTEST_REPORT_CHOICE_NDIFFZREPORT_NDIFF�(DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILUREZREPORT_ONLY_FIRST_FAILURE�DOCTEST_REPORT_CHOICE_NONE)�keyrVrrr rZ7srZr,)ZscopecCst�S)z2
    Inject names into the doctest namespace.
    )rErrrr rCFsrC)$r��
__future__rrbr�Z_pytest._code.coderrrZ_pytest.fixturesrr�r�r�r�r�rr!r*r&r1ZItemr;rurw�Moduler'rJr%rDrYrsrtrZZfixturerCrrrr �<module>s>	
A
	
8