HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/_pytest/__pycache__/recwarn.cpython-310.pyc
o

%we�*�@s�dZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZed�Zede
dfdd��Zedd�de
eeeefddfdd ��Z ed!e	defd"ed#edefd$d ��Z 	d.d!e
e	defd"ed#ededeffd%d �Z e	d/dd�d&eee!eee!dffde
eeeefdd'fd(d)��Z"ed&eee!eee!dffd!e	defd"ed#edef
d*d)��Z"e!fdd�d&eee!eee!dffd"ede
eeeefd#eded'eff
d+d)�Z"Gd,d�dej#�Z$eGd-d'�d'e$��Z%dS)0z/Record warnings during test function execution.�N��pformat)�
TracebackType)�Any)�Callable)�	Generator)�Iterator)�List)�Optional)�Pattern)�Tuple)�Type)�TypeVar)�Union)�final)�overload)�check_ispytest)�WARNS_NONE_ARG)�fixture)�fail�T�return)�WarningsRecorderNNccsF�tdd�}|�t�d�|VWd�dS1swYdS)z�Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.

    See https://docs.pytest.org/en/latest/how-to/capture-warnings.html for information
    on warning categories.
    T��	_ispytest�defaultN)r�warnings�simplefilter)�wrec�r�H/home/arjun/projects/env/lib/python3.10/site-packages/_pytest/recwarn.py�recwarns�

"�r!.��matchr#rcC�dS�Nrr"rrr �deprecated_call*�r&�func�args�kwargscOr$r%r)r(r)r*rrr r&1r'cOs0d}|dur|f|}tttfg|�Ri|��S)a�Assert that code produces 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

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

    It can also be used by passing a function and ``*args`` and ``**kwargs``,
    in which case it will ensure calling ``func(*args, **kwargs)`` produces one of
    the warnings types above. The return value is the return value of the function.

    In the context manager form you may use the keyword argument ``match`` to assert
    that the warning matches a text or regex.

    The context manager produces a list of :class:`warnings.WarningMessage` objects,
    one for each warning raised.
    TN)�warns�DeprecationWarning�PendingDeprecationWarning)r(r)r*�__tracebackhide__rrr r&8s
�expected_warning�WarningsCheckercCr$r%r)r/r#rrr r+Xsr+cOr$r%r)r/r(r)r*rrr r+ascOs�d}|s|rd�t|��}td|�d���t||dd�S|d}t|�s0t|�dt|��d���t|dd	��||d
d�i|��Wd�S1sLwYdS)a�Assert that code raises a particular class of warning.

    Specifically, the parameter ``expected_warning`` can be a warning class or sequence
    of warning classes, and the code inside the ``with`` block must issue at least one
    warning of that class or classes.

    This helper produces a list of :class:`warnings.WarningMessage` objects, one for
    each warning raised (regardless of whether it is an ``expected_warning`` or not).

    This function can be used as a context manager, which will capture all the raised
    warnings inside it::

        >>> import pytest
        >>> with pytest.warns(RuntimeWarning):
        ...    warnings.warn("my warning", RuntimeWarning)

    In the context manager form you may use the keyword argument ``match`` to assert
    that the warning matches a text or regex::

        >>> with pytest.warns(UserWarning, match='must be 0 or None'):
        ...     warnings.warn("value must be 0 or None", UserWarning)

        >>> with pytest.warns(UserWarning, match=r'must be \d+$'):
        ...     warnings.warn("value must be 42", UserWarning)

        >>> with pytest.warns(UserWarning, match=r'must be \d+$'):
        ...     warnings.warn("this is not here", UserWarning)
        Traceback (most recent call last):
          ...
        Failed: DID NOT WARN. No warnings of type ...UserWarning... were emitted...

    **Using with** ``pytest.mark.parametrize``

    When using :ref:`pytest.mark.parametrize ref` it is possible to parametrize tests
    such that some runs raise a warning and others do not.

    This could be achieved in the same way as with exceptions, see
    :ref:`parametrizing_conditional_raising` for an example.

    Tz, z5Unexpected keyword arguments passed to pytest.warns: z"
Use context-manager form instead?)�
match_exprrrz object (type: z) must be callabler�N)�join�sorted�	TypeErrorr0�callable�type)r/r#r)r*r.�argnamesr(rrr r+ks.
�$�cs�eZdZdZdd�deddf�fdd�Zeded	fd
d��Zde	dd	fd
d�Z
ded	fdd�Zde	fdd�Z
efdeedd	fdd�Zddd�Zd �fdd�Zdeeedeedeeddf�fdd�Z�ZS)!raFA context manager to record raised warnings.

    Each recorded warning is an instance of :class:`warnings.WarningMessage`.

    Adapted from `warnings.catch_warnings`.

    .. note::
        ``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
        differently; see :ref:`ensuring_function_triggers`.

    FrrrNcs&t|�t�jdd�d|_g|_dS)NT)�recordF)r�super�__init__�_entered�_list)�selfr��	__class__rr r;�s
zWarningsRecorder.__init__zwarnings.WarningMessagecCs|jS)zThe list of recorded warnings.�r=�r>rrr �list�szWarningsRecorder.list�icCs
|j|S)z Get a recorded warning by index.rA)r>rDrrr �__getitem__��
zWarningsRecorder.__getitem__cC�
t|j�S)z&Iterate through the recorded warnings.)�iterr=rBrrr �__iter__�rFzWarningsRecorder.__iter__cCrG)z The number of recorded warnings.)�lenr=rBrrr �__len__�rFzWarningsRecorder.__len__�clscCsBt|j�D]\}}t|j|�r|j�|�Sqd}t|�d���)z>Pop the first recorded warning, raise exception if not exists.Tz not found in warning list)�	enumerater=�
issubclass�category�pop�AssertionError)r>rLrD�wr.rrr rP�s�zWarningsRecorder.popcCsg|jdd�<dS)z$Clear the list of recorded warnings.NrArBrrr �clear�szWarningsRecorder.clearcsD|jr
d}td|�d���t���}|dusJ�||_t�d�|S)NTz
Cannot enter z twice�always)r<�RuntimeErrorr:�	__enter__r=rr)r>r.r=r?rr rV�s

zWarningsRecorder.__enter__�exc_type�exc_val�exc_tbcs4|js
d}td|�d���t��|||�d|_dS)NTzCannot exit z without entering firstF)r<rUr:�__exit__)r>rWrXrYr.r?rr rZ�s

zWarningsRecorder.__exit__)rN)rr)�__name__�
__module__�__qualname__�__doc__�boolr;�propertyr	rC�intrErrIrK�Warningr
rPrSrVr
�
BaseExceptionrrZ�
__classcell__rrr?r r�s(

����c
s�eZdZedfdd�deeeeeeedffdeeee	efde
ddf�fd	d
�Zdeeedeed
ee
ddf�fdd�Z�ZS)r0NFrr/.r1rrcs�t|�t�jdd�d}|durtjtdd�d}n+t|t�r5|D]}t|t	�s1t
|t|���q"|}nt|t	�r>|f}nt
|t|���||_||_
dS)NTrz/exceptions must be derived from Warning, not %s�)�
stacklevel)rr:r;r�warnr�
isinstance�tuplerNrbr5r7r/r1)r>r/r1r�msg�expected_warning_tup�excr?rr r;�s"	

�

zWarningsChecker.__init__rWrXrYcs�t��|||�d}�fdd�}|duro|durq|durs�jdurut�fdd��D��s=d}td�j�d|��d��dS�jdurw�D]}t|j�j�r\t�	�j��
t|j��r\dSqDtd�j�d	�j�d
|����dSdSdSdSdSdS)NTcstdd��D�dd�S)NcSsg|]}|j�qSr)�message)�.0r9rrr �
<listcomp>#sz?WarningsChecker.__exit__.<locals>.found_str.<locals>.<listcomp>�)�indentrrrBrr �	found_str"sz+WarningsChecker.__exit__.<locals>.found_strc3s�|]
}t|j�j�VqdSr%)rNrOr/)rn�rrBrr �	<genexpr>(s�z+WarningsChecker.__exit__.<locals>.<genexpr>z"DID NOT WARN. No warnings of type z0 were emitted.
The list of emitted warnings is: �.z* matching the regex were emitted.
 Regex: z
 Emitted warnings: )
r:rZr/�anyrr1rNrO�re�compile�search�strrm)r>rWrXrYr.rrrsr?rBr rZs<

��
������zWarningsChecker.__exit__)r[r\r]rbr
rr
rrzrr_r;rcrrZrdrrr?r r0�s2�������
����r%).)&r^rwr�pprintr�typesr�typingrrrrr	r
rrr
rr�_pytest.compatrr�_pytest.deprecatedrr�_pytest.fixturesr�_pytest.outcomesrrr!rzr&rbr+�catch_warningsrr0rrrr �<module>s����
��������

� ������
����
������

�?O