
    yIf5                        d Z ddlm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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ZddlmZ ddlmZ ddlmZ ddlmZ  ed          Zede
d         fd            Zedddeeeee         f                  ddfd            Zededef         d ed!edefd"            Z	 d+deedef                  d ed!ededef         fd#Ze	 d,ddd$eee          eee          df         f         deeeee         f                  dd%fd&            Z!ed$eee          eee          df         f         dedef         d ed!edef
d'            Z!e fddd$eee          eee          df         f         d edeeeee         f                  d!eded%ef         f
d(Z! G d) dej"                  Z#e	 G d* d%e#                      Z$dS )-z/Record warnings during test function execution.    pformatN)TracebackType)Any)Callable)final)	Generator)Iterator)List)Optional)overload)Pattern)Tuple)Type)TypeVar)Union)check_ispytest)fixture)Exit)failTreturn)WarningsRecorderNNc               #      K   t          d          } | 5  t          j        d           | V  ddd           dS # 1 swxY w Y   dS )zReturn 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)wrecs    C/var/www/piapp/venv/lib/python3.11/site-packages/_pytest/recwarn.pyrecwarnr"      s       d+++D	  i(((


                 s   ;??.matchr$   r   c                     d S N r#   s    r!   deprecated_callr(   ,   s	         funcargskwargsc                     d S r&   r'   )r*   r+   r,   s      r!   r(   r(   2   s    MPSr)   c                 Z    d}| | g|R }t          t          t          t          fg|R i |S )a  Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning`` or ``FutureWarning``.

    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.
    T)warnsDeprecationWarningPendingDeprecationWarningFutureWarning)r*   r+   r,   __tracebackhide__s       r!   r(   r(   6   sT    4 }t}}	6FIM  QW  r)   expected_warningWarningsCheckerc                    d S r&   r'   )r4   r$   s     r!   r/   r/   X   s	    
 r)   c                     d S r&   r'   )r4   r*   r+   r,   s       r!   r/   r/   `   s	     	r)   c                   d}|sI|r5d                     t          |                    }t          d| d          t          | |d          S |d         }t	          |          s"t          |dt          |           d          t          | d	          5   ||d
d         i |cddd           S # 1 swxY w Y   dS )a  Assert that code raises a particular class of warning.

    Specifically, the parameter ``expected_warning`` can be a warning class or tuple
    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 emitted (regardless of whether it is an ``expected_warning`` or not).
    Since pytest 8.0, unmatched warnings are also re-emitted when the context closes.

    This function can be used as a context manager::

        >>> 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):  # catch re-emitted warning
        ...     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_exprr   r   z object (type: z) must be callabler      N)joinsorted	TypeErrorr5   callabletype)r4   r$   r+   r,   r3   argnamesr*   s          r!   r/   r/   i   sA   ^  - 	yy00H6 6 6 6   /ETRRRRAw~~ 	VtTTd4jjTTTUUU->>> 	- 	-4abb,V,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   B55B9<B9c                       e Zd ZdZdddeddf fdZeded         fd	            Zd
e	ddfdZ
ded         fdZde	fdZefdee         ddfdZddZd fdZdeee                  dee         dee         ddf fdZ xZS )r   aF  A 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`.

    Fr   r   r   Nc                    t          |           t                                          d           d| _        g | _        d S )NT)recordF)r   super__init___entered_list)selfr   	__class__s     r!   rE   zWarningsRecorder.__init__   s>    y!!!%%%46


r)   zwarnings.WarningMessagec                     | j         S )zThe list of recorded warnings.rG   rH   s    r!   listzWarningsRecorder.list   s     zr)   ic                     | j         |         S )z Get a recorded warning by index.rK   )rH   rN   s     r!   __getitem__zWarningsRecorder.__getitem__   s    z!}r)   c                 *    t          | j                  S )z&Iterate through the recorded warnings.)iterrG   rL   s    r!   __iter__zWarningsRecorder.__iter__   s    DJr)   c                 *    t          | j                  S )z The number of recorded warnings.)lenrG   rL   s    r!   __len__zWarningsRecorder.__len__   s    4:r)   clsc                 d   d}t          | j                  D ]j\  }}|j        |k    r| j                            |          c S t	          |j        |          r)|%t	          |j        | j        |         j                  s|}k|| j                            |          S d}t          |d          )zPop the first recorded warning which is an instance of ``cls``,
        but not an instance of a child class of any other match.
        Raises ``AssertionError`` if there is no match.
        NTz not found in warning list)	enumeraterG   categorypop
issubclassAssertionError)rH   rW   best_idxrN   wr3   s         r!   r[   zWarningsRecorder.pop   s    
 #'dj)) 	 	DAqzS  z~~a(((((!*c**  !!*dj.B.KLL ! :>>(+++ AAABBBr)   c                     g | j         dd<   dS )z$Clear the list of recorded warnings.NrK   rL   s    r!   clearzWarningsRecorder.clear   s    
111r)   c                     | j         rd}t          d| d          t                                                      }|J || _        t          j        d           | S )NTzCannot enter z twicealways)rF   RuntimeErrorrD   	__enter__rG   r   r   )rH   r3   rG   rI   s      r!   re   zWarningsRecorder.__enter__   sk    = 	? $=t===>>>!!##   
h'''r)   exc_typeexc_valexc_tbc                     | j         sd}t          d| d          t                                          |||           d| _         d S )NTzCannot exit z without entering firstF)rF   rd   rD   __exit__)rH   rf   rg   rh   r3   rI   s        r!   rj   zWarningsRecorder.__exit__   sY     } 	O $MdMMMNNN7F333 r)   )r   N)r   r   )__name__
__module____qualname____doc__boolrE   propertyr   rM   intrP   r
   rS   rV   Warningr   r[   ra   re   r   BaseExceptionr   rj   __classcell__rI   s   @r!   r   r      s       
 
 -2 7 7 7T 7d 7 7 7 7 7 7 d45    XS %>     (#<=             (/ C CtG} C3L C C C C&   	 	 	 	 	 	4./ -( '	
 
         r)   c            
           e Zd Zedfdddeee         eee         df         f         deeee	e         f                  de
ddf fd	Zd
ej        de
fdZdeee                  dee         dee         ddf fdZ xZS )r5   NFr   r4   .r9   r   r   c                   t          |           t                                          d           d}t          |t                    r<|D ]6}t          |t                    st          |t          |          z            7|}nMt          |t                    rt          |t                    r|f}nt          |t          |          z            || _	        || _
        d S )NTr   z/exceptions must be derived from Warning, not %s)r   rD   rE   
isinstancetupler\   rr   r=   r?   r4   r9   )rH   r4   r9   r   msgexcexpected_warning_tuprI   s          r!   rE   zWarningsChecker.__init__  s     	y!!!4(((?&.. 
	:' 5 5!#w// 5#C$s))O4445#3  ($// 	:Jg5
 5
 	: %5#6  C$'7"8"88999 4$r)   warningc                     | j         J t          |j        | j                   oAt          | j        d u p+t          j        | j        t          |j                                      S r&   )	r4   r\   rZ   ro   r9   researchstrmessage)rH   r}   s     r!   matcheszWarningsChecker.matches  sc    $000'*D,ABB 
tOt#Wry#goBVBV'W'WH
 H
 	
r)   rf   rg   rh   c                     t                                          |||           d}|,t          |t                    rt          |t                    rd S dt
          f fd}	 t           fd D                       s$t          d j         d |             d           nFt           fd D                       s+t          d j         d	 j	         d
 |             d            D ]O} 
                    |          s8t          j        |j        |j        |j        |j        |j        |j                   P D ]z}t'          |j                  t(          ur|j        j        s+|j        j        d         }t          |t
                    rSt-          d|dt'          |          j         d          d S #  D ]O} 
                    |          s8t          j        |j        |j        |j        |j        |j        |j                   P D ]z}t'          |j                  t(          ur|j        j        s+|j        j        d         }t          |t
                    rSt-          d|dt'          |          j         d          w xY w)NTr   c                  :    t          d  D             d          S )Nc                     g | ]	}|j         
S r'   )r   ).0rC   s     r!   
<listcomp>z?WarningsChecker.__exit__.<locals>.found_str.<locals>.<listcomp>:  s    >>>vFN>>>r)      )indentr   rL   s   r!   	found_strz+WarningsChecker.__exit__.<locals>.found_str9  s%    >>>>>qIIIIr)   c              3   L   K   | ]}t          |j        j                  V  d S r&   )r\   rZ   r4   r   r_   rH   s     r!   	<genexpr>z+WarningsChecker.__exit__.<locals>.<genexpr>=  s2      SSz!*d.CDDSSSSSSr)   z"DID NOT WARN. No warnings of type z" were emitted.
 Emitted warnings: .c              3   B   K   | ]}                     |          V  d S r&   )r   r   s     r!   r   z+WarningsChecker.__exit__.<locals>.<genexpr>B  s-      77Qa777777r)   z* matching the regex were emitted.
 Regex: z
 Emitted warnings: )r   rZ   filenamelinenomodulesourcer   z$Warning must be str or Warning, got z (type ))rD   rj   rx   	Exceptionr   r   anyr   r4   r9   r   r   warn_explicitr   rZ   r   r   rl   r   r?   UserWarningr+   r=   rk   )	rH   rf   rg   rh   r3   r   r_   rz   rI   s	   `       r!   rj   zWarningsChecker.__exit__$  sQ    	7F333  7I..  '4(( 
 F	J3 	J 	J 	J 	J 	J 	J2	SSSSdSSSSS 
99N 9 9*3)++9 9 9    7777$77777 99N 9 9#9 9*3)++9 9 9    	 	||A * !	!"!" x | x   "   	??+55 y~ inQ'c3''   ^3^^cI[^^^   '  	 	||A * !	!"!" x | x   "   	??+55 y~ inQ'c3''   ^3^^cI[^^^  s   $BF: :CJ)rk   rl   rm   rr   r   r   r   r   r   r   ro   rE   r   WarningMessager   rs   r   rj   rt   ru   s   @r!   r5   r5     s;        MT9=%
  % % %WuT']C5G/H HI% U3#456%
 % 
% % % % % %4
x6 
4 
 
 
 
J4./J -(J '	J
 
J J J J J J J J J Jr)   r&   ).)%rn   pprintr   r   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   _pytest.deprecatedr   _pytest.fixturesr   _pytest.outcomesr   r   r   r"   r   r(   rr   r/   catch_warningsr   r5   r'   r)   r!   <module>r      s   5 5       				                                                                                      - - - - - - $ $ $ $ $ $ ! ! ! ! ! ! ! ! ! ! ! ! GCLL 		9: 	 	 	 		 
36  uS'#,./0   

 
 P(36* P3 P# P! P P P 
 P *. 
8CH%
&69EH
s"#   D 
HK 14  DM5g1C+DDE E#ws|+,- 	   
 
DM5g1C+DDE
36
  	
    
 IP=- 15=- =- =-DM5g1C+DDE=-=- E#ws|+,-=- 	=-
 c!"=- =- =- =-@V V V V Vx. V V Vr k k k k k& k k k k kr)   