
    [j36                    
   d 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 ddlmZ ddlmZ erddlmZ ddlmZ  ed          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d4d            Zeddd5d            Z ed6d%            Z 	 d7d8d)Z e	 d9ddd:d-            Z!ed;d.            Z!e"dfd<d1Z! G d2 dej#                  Z$e G d3 d,e$                      Z%dS )=z/Record warnings during test function execution.    )annotations)Callable)	Generator)IteratorpformatN)TracebackType)Any)final)overload)TYPE_CHECKING)TypeVar)	ParamSpec)SelfP)check_ispytest)fixture)Exit)failTreturnGenerator[WarningsRecorder]c               #     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 :ref:`warnings` for information on warning categories.
    T	_ispytestdefaultN)WarningsRecorderwarningssimplefilter)wrecs    S/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/_pytest/recwarn.pyrecwarnr"   $   s       d+++D	  i(((


                 s   ;??.matchr$   str | re.Pattern[str] | Noner   c                    d S N r#   s    r!   deprecated_callr)   0   s	     s    funcCallable[P, T]argsP.argskwargsP.kwargsc                    d S r'   r(   )r+   r-   r/   s      r!   r)   r)   6   s    SVSVr*   Callable[..., Any] | Noner
   WarningsRecorder | Anyc                    d}t           t          t          f}| t          |g|R i |S t          |          5   | |i |cddd           S # 1 swxY w Y   dS )aR  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
        >>> with pytest.deprecated_call(match="^use v3 of this api$") as warning_messages:
        ...    assert api_call_v2() == 200

    You may use the keyword argument ``match`` to assert
    that the warning matches a text or regex.

    The return value is a list of :class:`warnings.WarningMessage` objects,
    one for each warning emitted
    (regardless of whether it is an ``expected_warning`` or not).
    TN)DeprecationWarningPendingDeprecationWarningFutureWarningwarns)r+   r-   r/   __tracebackhide__dep_warningss        r!   r)   r)   :   s    2 &(A=QL|\3D333F333	|		 % %tT$V$$% % % % % % % % % % % % % % % % % %s   AAAexpected_warning)type[Warning] | tuple[type[Warning], ...]WarningsCheckerc                   d S r'   r(   )r;   r$   s     r!   r8   r8   \   s	    
 cr*   c                    d S r'   r(   )r;   r+   r-   r/   s       r!   r8   r8   d   s	     	r*   Callable[..., object] | NoneWarningsChecker | Anyc                   d}|a|s_|                     dd          }|r5d                    t          |                    }t          d| d          t	          | |d          S t          |          s"t          |dt          |           d	          t	          | d
          5   ||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 should be used as a context manager::

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

    The ``match`` keyword argument can be used 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: Regex pattern did not match any of the 1 warnings emitted.
         Regex: ...
         Emitted warnings: ...UserWarning...

    **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.

    TNr$   z, z5Unexpected keyword arguments passed to pytest.warns: z"
Use context-manager form instead?)
match_exprr   z object (type: z) must be callabler   )popjoinsorted	TypeErrorr=   callabletype)r;   r+   r-   r/   r9   r$   argnamess          r!   r8   r8   m   sD   b |D|.4jj$.G.G 	yy00H6 6 6 6   /ETRRRR~~ 	VtTTd4jjTTTUUU->>> 	) 	)4(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   (B==CCc                       e Zd ZdZddd fdZed d
            Zd!dZd"dZd#dZ	e
fd$dZd%dZd& fdZd' 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   boolr   Nonec                   t          |           t                                          d           d| _        g | _        d S )NT)recordF)r   super__init___entered_list)selfr   	__class__s     r!   rQ   zWarningsRecorder.__init__   s>    y!!!%%%46


r*   list[warnings.WarningMessage]c                    | j         S )zThe list of recorded warnings.rS   rT   s    r!   listzWarningsRecorder.list   s     zr*   iintwarnings.WarningMessagec                    | j         |         S )z Get a recorded warning by index.rX   )rT   r[   s     r!   __getitem__zWarningsRecorder.__getitem__   s    z!}r*   !Iterator[warnings.WarningMessage]c                *    t          | j                  S )z&Iterate through the recorded warnings.)iterrS   rY   s    r!   __iter__zWarningsRecorder.__iter__   s    DJr*   c                *    t          | j                  S )z The number of recorded warnings.)lenrS   rY   s    r!   __len__zWarningsRecorder.__len__   s    4:r*   clstype[Warning]c                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)	enumeraterS   categoryrD   
issubclassAssertionError)rT   rg   best_idxr[   wr9   s         r!   rD   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.NrX   rY   s    r!   clearzWarningsRecorder.clear   s    
111r*   r   c                    | j         rd}t          d| d          t                                                      }|J || _        t          j        d           | S )NTzCannot enter z twicealways)rR   RuntimeErrorrP   	__enter__rS   r   r   )rT   r9   rS   rU   s      r!   ru   zWarningsRecorder.__enter__   sk    = 	? $=t===>>>!!##   
h'''r*   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Nonec                    | j         sd}t          d| d          t                                          |||           d| _         d S )NTzCannot exit z without entering firstF)rR   rt   rP   __exit__)rT   rv   rx   rz   r9   rU   s        r!   r}   zWarningsRecorder.__exit__   sY     } 	O $MdMMMNNN7F333 r*   )r   rL   r   rM   )r   rV   )r[   r\   r   r]   )r   r`   )r   r\   )rg   rh   r   r]   )r   rM   )r   r   rv   rw   rx   ry   rz   r{   r   rM   )__name__
__module____qualname____doc__rQ   propertyrZ   r_   rc   rf   WarningrD   rq   ru   r}   __classcell__rU   s   @r!   r   r      s%       
 
 -2 7 7 7 7 7 7 7 7    X              (/ C C C C C&   	 	 	 	 	 	         r*   c                  @     e Zd Zedfddd fdZddZd fdZ xZS )r=   NFr   r;   r<   rC   r%   r   rL   r   rM   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   rP   rQ   
isinstancetuplerl   r   rG   rI   r;   rC   )rT   r;   rC   r   msgexcexpected_warning_tuprU   s          r!   rQ   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*   warningr]   c                    | j         J t          |j        | j                   oAt          | j        d u p+t          j        | j        t          |j                                      S r'   )	r;   rl   rk   rL   rC   researchstrmessage)rT   r   s     r!   matcheszWarningsChecker.matches$  sc    $000'*D,ABB 
tOt#Wry#goBVBV'W'WH
 H
 	
r*   rv   rw   rx   ry   rz   r{   c                    t                                          |||           d}|,t          |t                    rt          |t                    rd S d fd}	 t           fd D                       s$t          d j         d |             d           nt           fd	 D                       snd
}t           j        t                    rt           fd D                       rd}t          dt                      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   r   c                 :    t          d  D             d          S )Nc                    g | ]	}|j         
S r(   )r   ).0rO   s     r!   
<listcomp>z?WarningsChecker.__exit__.<locals>.found_str.<locals>.<listcomp>@  s    >>>vFN>>>r*      )indentr   rY   s   r!   	found_strz+WarningsChecker.__exit__.<locals>.found_str?  s%    >>>>>qIIIIr*   c              3  L   K   | ]}t          |j        j                  V  d S r'   )rl   rk   r;   r   ro   rT   s     r!   	<genexpr>z+WarningsChecker.__exit__.<locals>.<genexpr>C  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>H  s-      77Qa777777r*    c              3     K   | ];}t          |j        j                  j        t	          |j                  k    V  <d S r'   )rl   rk   r;   rC   r   r   r   s     r!   r   z+WarningsChecker.__exit__.<locals>.<genexpr>J  s[       < <!!*d.CDD<Os19~~5< < < < < <r*   z*
 Did you mean to `re.escape()` the regex?z'Regex pattern did not match any of the z warnings emitted.
 Regex: z
 Emitted warnings: )r   rk   filenamelinenomodulesourcer   z$Warning must be str or Warning, got z (type ))r   r   )rP   r}   r   	Exceptionr   anyr   r;   rC   r   re   r   r   warn_explicitr   rk   r   r   r   r   rI   UserWarningr-   rG   r   )
rT   rv   rx   rz   r9   r   escape_hintro   r   rU   s
   `        r!   r}   zWarningsChecker.__exit__*  s    	7F333  7I..  '4(( 
 F	J 	J 	J 	J 	J 	J9	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  dos33 P < < < <!< < < 9 9 P
 #PKFc$ii F F#F F*3)++F F8CF F    	 	||A * !	!"!" x | x   "   	??+55 y~ inQ'c3''   ^3^^cI[^^^   '  	 	||A * !	!"!" x | x   "   	??+55 y~ inQ'c3''   ^3^^cI[^^^  s   CG6 6CK)r;   r<   rC   r%   r   rL   r   rM   )r   r]   r   rL   r~   )r   r   r   r   rQ   r   r}   r   r   s   @r!   r=   r=     s         GN37%
  % % % % % % % %4
 
 
 
Q Q Q Q Q Q Q Q Q Qr*   )r   r   )r$   r%   r   r   )r+   r,   r-   r.   r/   r0   r   r   r'   )r+   r2   r-   r
   r/   r
   r   r3   ).)r;   r<   r$   r%   r   r=   )
r;   r<   r+   r,   r-   r.   r/   r0   r   r   )
r;   r<   r+   r@   r-   r
   r/   r
   r   rA   )&r   
__future__r   collections.abcr   r   r   pprintr   r   typesr	   typingr
   r   r   r   r   typing_extensionsr   r   r   r   _pytest.deprecatedr   _pytest.fixturesr   _pytest.outcomesr   r   r   r"   r)   r8   r   catch_warningsr   r=   r(   r*   r!   <module>r      s   5 5 " " " " " " $ $ $ $ $ $ % % % % % % $ $ $ $ $ $       				                                            ++++++&&&&&&	#A  - - - - - - $ $ $ $ $ $ ! ! ! ! ! ! ! ! ! ! ! ! GCLL 	   	 
-0     

 
 V V V 
 V '+% % % % %D 
BE +.     
 
   
 CJ)-?) ?) ?) ?) ?)DV V V V Vx. V V Vr r r r r r& r r r r rr*   