Your IP : 216.73.216.196


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__/recwarn.cpython-37.pyc

B

C$�X��@s�dZddlZddlZddlZddlZddlZddlZejdd��Z	dd�Z
ddd�Zd	d
�ZGdd�de
�ZGd
d�de
�ZGdd�de�ZdS)z4 recording warnings during test function execution. �Nc	cs*t�}|�t�d�|VWdQRXdS)aReturn a WarningsRecorder instance that provides these methods:

    * ``pop(category=None)``: return last warning matching the category.
    * ``clear()``: clear list of warnings

    See http://docs.python.org/library/warnings.html for information
    on warning categories.
    �defaultN)�WarningsRecorder�warnings�simplefilter)�requestZwrec�r�@/opt/alt/python37/lib/python3.7/site-packages/_pytest/recwarn.py�recwarns

r	cCs
ttd�S)N)�deprecated_call�warns)r
rrrrr�pytest_namespacesrcs�|sttd�Sg���fdd�}d��fdd�	}tj�tj�|t_|t_z|||�}Wd�t_�t_Xttf�t�fdd��D��s�d	}td
|f��|S)ag assert that calling ``func(*args, **kwargs)`` triggers a
    ``DeprecationWarning`` or ``PendingDeprecationWarning``.

    This function can be used as a context manager::

        >>> import warnings
        >>> def api_call_v2():
        ...     warnings.warn('use v3 of this api', DeprecationWarning)
        ...     return 200

        >>> with deprecated_call():
        ...    assert api_call_v2() == 200

    Note: we cannot use WarningsRecorder here because it is still subject
    to the mechanism that prevents warnings of the same type from being
    triggered twice for the same module. See #1190.
    )�expected_warningcs ��|��||f|�|�dS)N)�append)�message�category�args�kwargs)�
categories�old_warn_explicitrr�
warn_explicit8s
z&deprecated_call.<locals>.warn_explicitNcs8t|t�r��|j�n
��|��||f|�|�dS)N)�
isinstance�Warningr�	__class__)rrrr)r�old_warnrr�warn<s

zdeprecated_call.<locals>.warnc3s|]}t|��VqdS)N)�
issubclass)�.0�c)�deprecation_categoriesrr�	<genexpr>Msz"deprecated_call.<locals>.<genexpr>Tz%%r did not produce DeprecationWarning)N)�WarningsChecker�DeprecationWarningrrr�PendingDeprecationWarning�any�AssertionError)�funcrrrr�ret�__tracebackhide__r)rrrrrr
!s$
r
c	Os�t|�}|s|St|dt�r�|\}t|t�s2t�t�d�}|j��}|�|�|�(t	j
�|���}t
j�||j|�WdQRXn&|d}|�||dd�|�SQRXdS)aGAssert that code raises a particular class of warning.

    Specifically, the input @expected_warning can be a warning class or
    tuple of warning classes, and the code must return that warning
    (if a single class) or one of those warnings (if a tuple).

    This helper produces a list of ``warnings.WarningMessage`` objects,
    one for each warning raised.

    This function can be used as a context manager, or any of the other ways
    ``pytest.raises`` can be used::

        >>> with warns(RuntimeWarning):
        ...    warnings.warn("my warning", RuntimeWarning)
    r�N)r r�strr$�sys�	_getframe�f_locals�copy�update�_pytest�_codeZSource�compile�py�builtin�exec_�	f_globals)r
rrZwcheck�code�frame�locr%rrrrSs


rc@seZdZdd�ZdS)�RecordedWarningcCs(||_||_||_||_||_||_dS)N)rr�filename�lineno�file�line)�selfrrr:r;r<r=rrr�__init__wszRecordedWarning.__init__N)�__name__�
__module__�__qualname__r?rrrrr9vsr9c@sbeZdZdZddd�Zedd��Zdd�Zd	d
�Zdd�Z	e
fd
d�Zdd�Zdd�Z
dd�ZdS)rz^A context manager to record raised warnings.

    Adapted from `warnings.catch_warnings`.
    NcCs(|dkrtjdn||_d|_g|_dS)NrF)r*�modules�_module�_entered�_list)r>�modulerrrr?�szWarningsRecorder.__init__cCs|jS)zThe list of recorded warnings.)rF)r>rrr�list�szWarningsRecorder.listcCs
|j|S)z Get a recorded warning by index.)rF)r>�irrr�__getitem__�szWarningsRecorder.__getitem__cCs
t|j�S)z&Iterate through the recorded warnings.)�iterrF)r>rrr�__iter__�szWarningsRecorder.__iter__cCs
t|j�S)z The number of recorded warnings.)�lenrF)r>rrr�__len__�szWarningsRecorder.__len__cCsDx.t|j�D] \}}t|j|�r|j�|�SqWd}td|��dS)z>Pop the first recorded warning, raise exception if not exists.Tz%r not found in warning listN)�	enumeraterFrr�popr$)r>�clsrI�wr'rrrrP�s
zWarningsRecorder.popcCsg|jdd�<dS)z$Clear the list of recorded warnings.N)rF)r>rrr�clear�szWarningsRecorder.clearcsh�jrd}td���d�_�jj�_�jdd��j_�jj�_d�fdd�	}|�j_�j�d��S)NTzCannot enter %r twicec	s4�j�t||||||���j||||||d�dS)N)r<r=)rFrr9�_showwarning)rrr:r;r<r=)r>rr�showwarning�sz/WarningsRecorder.__enter__.<locals>.showwarning�always)NN)rE�RuntimeErrorrD�filters�_filtersrUrTr)r>r'rUr)r>r�	__enter__�s

zWarningsRecorder.__enter__cGs.|jsd}td|��|j|j_|j|j_dS)NTz%Cannot exit %r without entering first)rErWrYrDrXrTrU)r>�exc_infor'rrr�__exit__�s

zWarningsRecorder.__exit__)N)r@rArB�__doc__r?�propertyrHrJrLrNrrPrSrZr\rrrrr�s
rcs*eZdZd�fdd�	Z�fdd�Z�ZS)r Ncs~tt|�j|d�d}t|t�rJxR|D]}t�|�s&t|t|���q&Wn*t�|�r\|f}n|dk	rtt|t|���||_	dS)N)rGzDexceptions must be old-style classes or derived from Warning, not %s)
�superr r?r�tuple�inspect�isclass�	TypeError�typer
)r>r
rG�msg�exc)rrrr?�s



zWarningsChecker.__init__cshtt��j|�tdd�|D��rd�jdk	rdt�fdd��D��sdd}t�d��jdd��D���dS)Ncss|]}|dkVqdS)Nr)r�arrrr�sz+WarningsChecker.__exit__.<locals>.<genexpr>c3s|]}|j�jkVqdS)N)rr
)r�r)r>rrr�sTzXDID NOT WARN. No warnings of type {0} was emitted. The list of emitted warnings is: {1}.cSsg|]
}|j�qSr)r)rZeachrrr�
<listcomp>�sz,WarningsChecker.__exit__.<locals>.<listcomp>)	r_r r\�allr
r#�pytestZfail�format)r>r[r')r)r>rr\�s
zWarningsChecker.__exit__)NN)r@rArBr?r\�
__classcell__rr)rrr �sr )N)r]raZ
_pytest._coder/r2r*rrkZ
yield_fixturer	rr
r�objectr9rr rrrr�<module>s
2#
I