
    ESj36                       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d#d       Zedd	 	 	 d$d       Z ed%d       Z 	 d&	 	 	 	 	 	 	 d'dZ e	 d(dd	 	 	 	 	 d)d       Z!e	 	 	 	 	 	 	 	 	 	 d*d       Z!e"df	 	 	 	 	 	 	 	 	 d+d Z! G d! dejF                        Z$e G d" de$             Z%y),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Tc               #     K   t        d      } | 5  t        j                  d       |  ddd       y# 1 sw Y   yxY ww)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    `/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/_pytest/recwarn.pyrecwarnr   $   s1      d+D	i(
 
s   A 4	A =A .matchr   c                     y N r    s    r   deprecated_callr%   0   s         c                     y r#   r$   )funcargskwargss      r   r%   r%   6   s    SVr&   c                    d}t         t        t        f}| t        |g|i |S t        |      5   | |i |cddd       S # 1 sw Y   yxY w)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%   :   sR    2 &(A=QL|\3D3F33	|	T$V$ 
		s   AAWarningsCheckerc                    y r#   r$   )expected_warningr!   s     r   r/   r/   \   s    
 r&   c                     y r#   r$   )r4   r(   r)   r*   s       r   r/   r/   d   s     	r&   c                D   d}|M|sK|j                  dd      }|r)dj                  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 Y   yxY w)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	TypeErrorr2   callabletype)r4   r(   r)   r*   r0   r!   argnamess          r   r/   r/   m   s    b |D.4jj$.Gyy0HGz56  /ETRR~thod4j\ASTUU->(( ?>>s   BB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   c               X    t        |       t        | 	  d       d| _        g | _        y )NT)recordF)r   super__init___entered_list)selfr   	__class__s     r   rC   zWarningsRecorder.__init__   s)    y!%46
r&   c                    | j                   S )zThe list of recorded warnings.rE   rF   s    r   listzWarningsRecorder.list   s     zzr&   c                     | j                   |   S )z Get a recorded warning by index.rI   )rF   is     r   __getitem__zWarningsRecorder.__getitem__   s    zz!}r&   c                ,    t        | j                        S )z&Iterate through the recorded warnings.)iterrE   rJ   s    r   __iter__zWarningsRecorder.__iter__   s    DJJr&   c                ,    t        | j                        S )z The number of recorded warnings.)lenrE   rJ   s    r   __len__zWarningsRecorder.__len__   s    4::r&   c                   d}t        | j                        D ]z  \  }}|j                  |k(  r| j                  j                  |      c S t	        |j                  |      sI|.t	        |j                  | j                  |   j                        ry|}| || j                  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)	enumeraterE   categoryr8   
issubclassAssertionError)rF   clsbest_idxrM   wr0   s         r   r8   zWarningsRecorder.pop   s    
  $djj)DAqzzS zz~~a((!**c* !!**djj.B.K.KL * ::>>(++ w&@ABBr&   c                "    g | j                   dd y)z$Clear the list of recorded warnings.NrI   rJ   s    r   clearzWarningsRecorder.clear   s    

1r&   c                    | j                   rd}t        d| d      t        |          }|J || _        t        j                  d       | S )NTzCannot enter z twicealways)rD   RuntimeErrorrB   	__enter__rE   r   r   )rF   r0   rE   rG   s      r   rb   zWarningsRecorder.__enter__   sW    == $thf=>>!#   
h'r&   c                p    | j                   sd}t        d| d      t        |   |||       d| _         y )NTzCannot exit z without entering firstF)rD   ra   rB   __exit__)rF   exc_typeexc_valexc_tbr0   rG   s        r   rd   zWarningsRecorder.__exit__   sA     }} $dX5LMNN7F3 r&   )r   boolreturnNone)ri   zlist[warnings.WarningMessage])rM   intri   warnings.WarningMessage)ri   z!Iterator[warnings.WarningMessage])ri   rk   )rZ   ztype[Warning]ri   rl   )ri   rj   )ri   r   re   ztype[BaseException] | Nonerf   zBaseException | Nonerg   zTracebackType | Noneri   rj   )__name__
__module____qualname____doc__rC   propertyrK   rN   rQ   rT   Warningr8   r^   rb   rd   __classcell__rG   s   @r   r   r      sz    
 -2 7    (/ 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 )
r2   NFr   c               T   t        |       t        | 	  d       d}t        |t              r1|D ])  }t        |t              rt        |t        |      z         |}n;t        |t              rt        |t              r|f}nt        |t        |      z        || _	        || _
        y )NTr   z/exceptions must be derived from Warning, not %s)r   rB   rC   
isinstancetuplerX   rs   r;   r=   r4   r7   )rF   r4   r7   r   msgexcexpected_warning_tuprG   s          r   rC   zWarningsChecker.__init__
  s     	y!4(?&.'!#w/#C$s)O44 ( $4 ($/Jg5
 %5#6 C$'7"8899 4$r&   c                    | j                   J t        |j                  | j                         xrL t        | j                  d u xs3 t        j                  | j                  t        |j                                    S r#   )	r4   rX   rW   rh   r7   researchstrmessage)rF   warnings     r   matcheszWarningsChecker.matches$  se    $$000'**D,A,AB 
tOOt#Wryy#gooBV'WH
 	
r&   c                    t         	   |||       d}|!t        |t              rt        |t              ry d fd}	 t         fd D              s"t        d j                   d |        d       nut         fd D              sad}t         j                  t              rt         fd	 D              rd
}t        dt                d j                  d |        d|         D ]k  } j                  |      rt        j                  |j                  |j                  |j                   |j"                  |j$                  |j&                         m  D ]  }t)        |j                        t*        ur|j                  j,                  s6|j                  j,                  d   }t        |t              r`t/        d|dt)        |      j0                   d       y #  D ]k  } j                  |      rt        j                  |j                  |j                  |j                   |j"                  |j$                  |j&                         m  D ]  }t)        |j                        t*        ur|j                  j,                  s6|j                  j,                  d   }t        |t              r`t/        d|dt)        |      j0                   d       w xY w)NTc                 X    t        D  cg c]  } | j                   c} d      S c c} w )N   )indent)r   r   )rA   rF   s    r   	found_strz+WarningsChecker.__exit__.<locals>.found_str?  s&    >vFNN>qII>s   'c              3  ^   K   | ]$  }t        |j                  j                         & y wr#   )rX   rW   r4   .0r\   rF   s     r   	<genexpr>z+WarningsChecker.__exit__.<locals>.<genexpr>C  s#     Sdz!**d.C.CDds   *-z"DID NOT WARN. No warnings of type z" were emitted.
 Emitted warnings: .c              3  @   K   | ]  }j                  |        y wr#   )r   r   s     r   r   z+WarningsChecker.__exit__.<locals>.<genexpr>H  s     7$Qa$s    c              3     K   | ]F  }t        |j                  j                        r$j                  t	        |j
                        k(   H y wr#   )rX   rW   r4   r7   r   r   r   s     r   r   z+WarningsChecker.__exit__.<locals>.<genexpr>J  s>      <!!!**d.C.CD OOs199~5!s   AA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   rW   filenamelinenomodulesourcer   z$Warning must be str or Warning, got z (type ))ri   r   )rB   rd   rx   	Exceptionr   anyr   r4   r7   r   rS   r   r   warn_explicitr   rW   r   r   ro   r   r=   UserWarningr)   r;   rn   )
rF   re   rf   rg   r0   r   escape_hintr\   rz   rG   s
   `        r   rd   zWarningsChecker.__exit__*  s    	7F3  7I.'4(	J9	SdSS89N9N8O P**3+a9 7$77 doos3 <!< 9
 #PK=c$i[ I#1 2**3+a}F ||A** !		!"!" xx || xx & 		?+5 yy~~iinnQ'c3'  :3'cI[I[H\\]^  ' ||A** !		!"!" xx || xx & 		?+5 yy~~iinnQ'c3'  :3'cI[I[H\\]^  s    B+G$ $K<C"K)r4   )type[Warning] | tuple[type[Warning], ...]r7   str | re.Pattern[str] | Noner   rh   ri   rj   )r   rl   ri   rh   rm   )rn   ro   rp   rs   rC   r   rd   rt   ru   s   @r   r2   r2     s}     GN37%
  %C% 1%
 % 
%4
Q,Q &Q %	Q
 
Q Qr&   )ri   zGenerator[WarningsRecorder])r!   r   ri   r   )r(   Callable[P, T]r)   P.argsr*   P.kwargsri   r   r#   )r(   zCallable[..., Any] | Noner)   r	   r*   r	   ri   zWarningsRecorder | Any).)r4   r   r!   r   ri   r2   )
r4   r   r(   r   r)   r   r*   r   ri   r   )
r4   r   r(   zCallable[..., object] | Noner)   r	   r*   r	   ri   zWarningsChecker | Any)&rq   
__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%   r/   rs   catch_warningsr   r2   r$   r&   r   <module>r      s   5 " $ % $  	        +&#A  - $ ! ! CL 	 	 
-0* 

 
 V 
 V '+%
#%36%BE%%D 
BE +.? ( 	 
 
?
  	
  
 CJ)-?)??)
&?) ?) 	?)
 ?)DVx.. Vr r& r rr&   