B
    Wcf'                 @   s  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ dZerddlmZ nddlmZ eZG dd deZeefZG dd deZG dd deZG dd deZe
dedef dZe
de	e dZG dd deeef Zeeegeeef f dddZeed7dd eee ee ed!d"d#Zeed8ddd$ee ee ed%d&d'Z!eed9ee ee ed)d*d+Z"d:eeee ed,d-d.Z#G d/d0 d0eZ$ee$d;eed1d2d3Z%d<eee ee ed4d5d6Z&dS )=zZException classes and constants handling test outcomes as well as
functions creating them.    N)Any)Callable)cast)NoReturn)Optional)Type)TypeVar)KEYWORD_MSG_ARGF)Protocol)Genericc                   sB   e Zd ZdZd
ee edd fddZeddd	ZeZ	  Z
S )OutcomeExceptionzmOutcomeException and its subclass instances indicate and contain info
    about test and collection outcomes.NT)msgpytracereturnc                sN   |d k	r2t |ts2d}t|t| jt|jt | || _|| _	d S )NzY{} expected string as 'msg' parameter, got '{}' instead.
Perhaps you meant to use a mark?)

isinstancestr	TypeErrorformattype__name__super__init__r   r   )selfr   r   Z	error_msg)	__class__ /lib/python3.7/site-packages/_pytest/outcomes.pyr       s    zOutcomeException.__init__)r   c             C   s    | j d k	r| j S d| jj dS )N<z
 instance>)r   r   r   )r   r   r   r   __repr__+   s    
zOutcomeException.__repr__)NT)r   
__module____qualname____doc__r   r   boolr   r   __str____classcell__r   r   )r   r   r      s   r   c                   s:   e Zd ZdZd	ddee eeedd fddZ  ZS )
SkippedbuiltinsNTF)_use_item_location)r   r   allow_module_levelr&   r   c               s    t  j||d || _|| _d S )N)r   r   )r   r   r'   r&   )r   r   r   r'   r&   )r   r   r   r   ;   s    zSkipped.__init__)NTF)r   r   r   r   r   r!   r   r#   r   r   )r   r   r$   6   s     r$   c               @   s   e Zd ZdZdZdS )Failedz.Raised from an explicit call to pytest.fail().r%   N)r   r   r   r    r   r   r   r   r(   J   s   r(   c                   s0   e Zd ZdZdeee dd fddZ  ZS )Exitz=Raised for immediate program exits (no tracebacks/summaries).unknown reasonN)r   
returncoder   c                s   || _ || _t | d S )N)r   r+   r   r   )r   r   r+   )r   r   r   r   S   s    zExit.__init__)r*   N)	r   r   r   r    r   r   intr   r#   r   r   )r   r   r)   P   s   
r)   _F.)Zbound_ETc               @   s   e Zd ZU eed< eed< dS )_WithException	Exception__call__N)r   r   r   r.   __annotations__r-   r   r   r   r   r/   b   s   
r/   )exception_typer   c                s    t tt tf d fdd}|S )N)funcr   c                s   t tttf | } |_|S )N)r   r/   r-   r.   r0   )r4   Zfunc_with_exception)r3   r   r   decorateh   s    z!_with_exception.<locals>.decorate)r-   r/   r.   )r3   r5   r   )r3   r   _with_exceptiong   s    r6    )r   )reasonr+   r   r   c            C   s\   d}ddl m} | r |r |d| sN|dkr4|dtjtjddd	d
 |} t| |dS )ax  Exit testing process.

    :param reason:
        The message to show as the reason for exiting pytest.  reason has a default value
        only because `msg` is deprecated.

    :param returncode:
        Return code to be used when exiting pytest.

    :param msg:
        Same as ``reason``, but deprecated. Will be removed in a future version, use ``reason`` instead.
    Tr   )
UsageErrorzHcannot pass reason and msg to exit(), `msg` is deprecated, use `reason`.Nz!exit() requires a reason argumentexit)r4      )
stacklevel)Z_pytest.configr9   warningswarnr	   r   r)   )r8   r+   r   __tracebackhide__r9   r   r   r   r:   s   s    r:   )r'   r   )r8   r'   r   r   c            C   s    d}t d| |} t| |ddS )a  Skip an executing test with the given message.

    This function should be called only during testing (setup, call or teardown) or
    during collection by using the ``allow_module_level`` flag.  This function can
    be called in doctests as well.

    :param reason:
        The message to show the user as reason for the skip.

    :param allow_module_level:
        Allows this function to be called at module level, skipping the rest
        of the module. Defaults to False.

    :param msg:
        Same as ``reason``, but deprecated. Will be removed in a future version, use ``reason`` instead.

    .. note::
        It is better to use the :ref:`pytest.mark.skipif ref` marker when
        possible to declare a test to be skipped under certain conditions
        like mismatching platforms or dependencies.
        Similarly, use the ``# doctest: +SKIP`` directive (see :py:data:`doctest.SKIP`)
        to skip a doctest statically.
    Tskip)r   r'   N)_resolve_msg_to_reasonr$   )r8   r'   r   r?   r   r   r   r@      s    r@   T)r8   r   r   r   c             C   s    d}t d| |} t| |ddS )a  Explicitly fail an executing test with the given message.

    :param reason:
        The message to show the user as reason for the failure.

    :param pytrace:
        If False, msg represents the full failure information and no
        python traceback will be reported.

    :param msg:
        Same as ``reason``, but deprecated. Will be removed in a future version, use ``reason`` instead.
    Tfail)r   r   N)rA   r(   )r8   r   r   r?   r   r   r   rB      s    rB   )	func_namer8   r   r   c             C   sJ   d}|dk	rF|r,ddl m} |d|  dtjtj| ddd	 |}|S )
a  
    Handles converting the deprecated msg parameter if provided into
    reason, raising a deprecation warning.  This function will be removed
    when the optional msg argument is removed from here in future.

    :param str func_name:
        The name of the offending function, this is formatted into the deprecation message.

    :param str reason:
        The reason= passed into either pytest.fail() or pytest.skip()

    :param str msg:
        The msg= passed into either pytest.fail() or pytest.skip().  This will
        be converted into reason if it is provided to allow pytest.skip(msg=) or
        pytest.fail(msg=) to continue working in the interim period.

    :returns:
        The value to use as reason.

    TNr   )r9   z.Passing both ``reason`` and ``msg`` to pytest.z(...) is not permitted.)r4      )r<   )Zpytestr9   r=   r>   r	   r   )rC   r8   r   r?   r9   r   r   r   rA      s    rA   c               @   s   e Zd ZdZdS )XFailedz/Raised from an explicit call to pytest.xfail().N)r   r   r   r    r   r   r   r   rE      s   rE   )r8   r   c             C   s   d}t | dS )a  Imperatively xfail an executing test or setup function with the given reason.

    This function should be called only during testing (setup, call or teardown).

    :param reason:
        The message to show the user as reason for the xfail.

    .. note::
        It is better to use the :ref:`pytest.mark.xfail ref` marker when
        possible to declare a test to be xfailed under certain conditions
        like known bugs or missing features.
    TN)rE   )r8   r?   r   r   r   xfail   s    rF   )modname
minversionr8   r   c       	      C   s   ddl }d}t| dd | f |d yt|  W nH tk
r } z*|dkrbd| d| }t|dd	dW dd}~X Y nX W dQ R X tj|  }|dkr|S t	|d
d}|dk	rddl
m} |dks||||k rtd| ||f dd	|S )av  Import and return the requested module ``modname``, or skip the
    current test if the module cannot be imported.

    :param modname:
        The name of the module to import.
    :param minversion:
        If given, the imported module's ``__version__`` attribute must be at
        least this minimal version, otherwise the test is still skipped.
    :param reason:
        If given, this reason is shown as the message when the module cannot
        be imported.

    :returns:
        The imported module. This should be assigned to its canonical name.

    Example::

        docutils = pytest.importorskip("docutils")
    r   NTr7   evalignorezcould not import z: )r'   __version__)Versionz-module %r has __version__ %r, required is: %r)r=   compilecatch_warningssimplefilter
__import__ImportErrorr$   sysmodulesgetattrZpackaging.versionrL   )	rG   rH   r8   r=   r?   excmodZverattrrL   r   r   r   importorskip   s.    

*

rW   )r7   N)r7   )r7   TN)N)r7   )NN)'r    rR   r=   typingr   r   r   r   r   r   r   Z_pytest.deprecatedr	   ZTYPE_CHECKINGZtyping_extensionsr
   r   BaseExceptionr   r0   ZTEST_OUTCOMEr$   r(   r)   objectr-   r.   r/   r6   r   r,   r:   r!   r@   rB   rA   rE   rF   rW   r   r   r   r   <module>   sN   "#