
    i3                    &   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	r	SSK
Jr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  \(       a  SSKJr  SSKrSSKJr  SSKJr  SSKJr  SSKJr  \" S5      r\S!S j5       r\SS.   S"S jj5       r\S#S j5       r S$       S%S jjr\ S&SS.     S'S jjj5       r\          S(S j5       r\ 4SS.         S)S jjjr " S S\RB                  5      r"\ " S  S\"5      5       r#g)*z/Record warnings during test function execution.    )annotations)Callable)	Generator)Iterator)pformatN)TracebackType)Any)final)overload)TYPE_CHECKING)TypeVar)Self)check_ispytest)fixture)Exit)failTc               #     #    [        SS9n U    [        R                  " S5        U v   SSS5        g! , (       d  f       g= f7f)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    N/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/_pytest/recwarn.pyrecwarnr   !   s0      d+D	i(
 
s   A2	A
A A.matchr   c                    g N r   s    r   deprecated_callr#   -   s         c                    g r!   r"   )funcargskwargss      r   r#   r#   3   s    MPr$   c                T    SnU b  U /UQ7n[        [        [        [        4/UQ70 UD6$ )ae  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#   7   sC    4 }t}	6FIMQW r$   WarningsCheckerc                   g r!   r"   )expected_warningr   s     r   r*   r*   Y   s    
 r$   c                    g r!   r"   )r1   r&   r'   r(   s       r   r*   r*   a   s     	r$   c               H   SnU(       d:  U(       a)  SR                  [        U5      5      n[        SU S35      e[        XSS9$ US   n[	        U5      (       d  [        U< S[        U5       S35      e[        U SS	9   U" US
S 0 UD6sSSS5        $ ! , (       d  f       g= f)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	TypeErrorr/   callabletype)r1   r   r'   r(   r.   argnamesr&   s          r   r*   r*   j   s    ^ yy0HGz56  /TRRAw~~thod4j\ASTUU->ab,V, ?>>s   >B
B!c                     ^  \ rS rSrSrSS.SU 4S jjjr\SS j5       rSS jrSS jr	SS	 jr
\4SS
 jjrSS jrSU 4S jjr        SU 4S jjrSrU =r$ )r      a.  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               R   > [        U5        [        TU ]	  SS9  SU l        / U l        g )NT)recordF)r   super__init___entered_list)selfr   	__class__s     r   rA   WarningsRecorder.__init__   s)    y!%46
r$   c                    U R                   $ )zThe list of recorded warnings.rC   rD   s    r   listWarningsRecorder.list   s     zzr$   c                     U R                   U   $ )z Get a recorded warning by index.rH   )rD   is     r   __getitem__WarningsRecorder.__getitem__   s    zz!}r$   c                ,    [        U R                  5      $ )z&Iterate through the recorded warnings.)iterrC   rI   s    r   __iter__WarningsRecorder.__iter__   s    DJJr$   c                ,    [        U R                  5      $ )z The number of recorded warnings.)lenrC   rI   s    r   __len__WarningsRecorder.__len__   s    4::r$   c                   Sn[        U R                  5       H  u  p4UR                  U:X  a  U R                  R                  U5      s  $ [	        UR                  U5      (       d  MO  Ub4  [	        UR                  U R                  U   R                  5      (       a  M  UnM     Ub  U R                  R                  U5      $ Sn[        U< S35      e)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)	enumeraterC   categorypop
issubclassAssertionError)rD   clsbest_idxrM   wr.   s         r   r[   WarningsRecorder.pop   s    
  $djj)DAzzS zz~~a((!**c** !!**djj.B.K.KLL * ::>>(++ w&@ABBr$   c                "    / U R                   SS& g)z$Clear the list of recorded warnings.NrH   rI   s    r   clearWarningsRecorder.clear   s    

1r$   c                   > U R                   (       a  Sn[        SU < S35      e[        TU ]  5       nUc   eX l        [
        R                  " S5        U $ )NTzCannot enter z twicealways)rB   RuntimeErrorr@   	__enter__rC   r   r   )rD   r.   rC   rE   s      r   rh   WarningsRecorder.__enter__   sU    == $thf=>>!#   
h'r$   c                z   > U R                   (       d  Sn[        SU < S35      e[        TU ]  XU5        SU l         g )NTzCannot exit z without entering firstF)rB   rg   r@   __exit__)rD   exc_typeexc_valexc_tbr.   rE   s        r   rk   WarningsRecorder.__exit__   s?     }} $dX5LMNNF3 r$   )rB   rC   )r   boolreturnNone)rq   zlist[warnings.WarningMessage])rM   intrq   warnings.WarningMessage)rq   z!Iterator[warnings.WarningMessage])rq   rs   )r^   ztype[Warning]rq   rt   )rq   rr   )rq   r   rl   ztype[BaseException] | Nonerm   zBaseException | Nonern   zTracebackType | Nonerq   rr   )__name__
__module____qualname____firstlineno____doc__rA   propertyrJ   rN   rR   rV   Warningr[   rc   rh   rk   __static_attributes____classcell__rE   s   @r   r   r      s    
 -2 7 7    (/ C&	, & %	
 
 r$   c                  t   ^  \ rS rSr\S4SS.       S	U 4S jjjjrS
S jr        SU 4S jjrSrU =r	$ )r/   i  NFr   c               v  > [        U5        [        TU ]	  SS9  Sn[        U[        5      (       a8  U H/  n[        U[        5      (       a  M  [        U[        U5      -  5      e   UnOE[        U[        5      (       a  [        U[        5      (       a  U4nO[        U[        U5      -  5      eX`l	        X l
        g )NTr   z/exceptions must be derived from Warning, not %s)r   r@   rA   
isinstancetupler\   r|   r8   r:   r1   r4   )rD   r1   r4   r   msgexcexpected_warning_tuprE   s          r   rA   WarningsChecker.__init__  s     	y!4(?&..'!#w//#C$s)O44 ( $4 ($//Jg5
 5
 %5#6 C$'7"8899 4$r$   c                   U R                   c   e[        UR                  U R                   5      =(       aR    [        U R                  S L =(       d4    [
        R                  " U R                  [        UR                  5      5      5      $ r!   )	r1   r\   rZ   rp   r4   researchstrmessage)rD   warnings     r   matchesWarningsChecker.matches  se    $$000'**D,A,AB 
tOOt#Wryy#gooBV'WH
 	
r$   c                  >^  [         TT ]  XU5        SnUb+  [        U[        5      (       a  [        U[        5      (       a  g SU 4S jjn [        U 4S jT  5       5      (       d"  [        ST R                   SU" 5        S35        OH[        U 4S jT  5       5      (       d.  [        ST R                   ST R                   S	U" 5        S35        T  Hp  nT R                  U5      (       a  M  [        R                  " UR                  UR                  UR                  UR                  UR                   UR"                  S
9  Mr     T  H  n[%        UR                  5      [&        La  M!  UR                  R(                  (       d  M>  UR                  R(                  S   n[        U[*        5      (       a  Mn  [-        SU< S[%        U5      R.                   S35      e   g ! T  Hp  nT R                  U5      (       a  M  [        R                  " UR                  UR                  UR                  UR                  UR                   UR"                  S
9  Mr     T  H  n[%        UR                  5      [&        La  M!  UR                  R(                  (       d  M>  UR                  R(                  S   n[        U[*        5      (       a  Mn  [-        SU< S[%        U5      R.                   S35      e   f = f)NTc                 V   > [        T V s/ s H  o R                  PM     sn SS9$ s  sn f )N   )indent)r   r   )r?   rD   s    r   	found_str+WarningsChecker.__exit__.<locals>.found_str8  s$    >vNN>qII>s   &c              3  d   >#    U  H%  n[        UR                  TR                  5      v   M'     g 7fr!   )r\   rZ   r1   .0r`   rD   s     r   	<genexpr>+WarningsChecker.__exit__.<locals>.<genexpr><  s%     Sdz!**d.C.CDDds   -0z"DID NOT WARN. No warnings of type z" were emitted.
 Emitted warnings: .c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr!   )r   r   s     r   r   r   A  s     7$Qa$s   !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 ))rq   r   )r@   rk   r   	Exceptionr   anyr   r1   r4   r   r   warn_explicitr   rZ   r   r   rw   r   r:   UserWarningr'   r   r8   rv   )	rD   rl   rm   rn   r.   r   r`   r   rE   s	   `       r   rk   WarningsChecker.__exit__#  sq    	F3  7I..'4((	J2	SdSSS89N9N8O P**3+a9 7$77789N9N8O P#/ 0**3+a9 ||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/=C2K/)r1   r4   )r1   )type[Warning] | tuple[type[Warning], ...]r4   str | re.Pattern[str] | Noner   rp   rq   rr   )r   rt   rq   rp   ru   )
rv   rw   rx   ry   r|   rA   r   rk   r}   r~   r   s   @r   r/   r/     s     GN37%
  %C% 1%
 % 
% %4
J,J &J %	J
 
J Jr$   )rq   zGenerator[WarningsRecorder])r   r   rq   r   )r&   Callable[..., T]r'   r	   r(   r	   rq   r   r!   )r&   zCallable[..., Any] | Noner'   r	   r(   r	   rq   zWarningsRecorder | Any).)r1   r   r   r   rq   r/   )
r1   r   r&   r   r'   r	   r(   r	   rq   r   )
r1   r   r'   r	   r   r   r(   r	   rq   zWarningsChecker | Any)$rz   
__future__r   collections.abcr   r   r   pprintr   r   typesr   typingr	   r
   r   r   r   typing_extensionsr   r   _pytest.deprecatedr   _pytest.fixturesr   _pytest.outcomesr   r   r   r   r#   r*   r|   catch_warningsr   r/   r"   r$   r   <module>r      s   5 " $ % $  	        &  - $ ! ! CL 	 	 
-0* 

 
 P 
 P '+
#36BED 
BE +.? ( 	 
 
?
  	
  
 CJ=- +/=-?=-=- (=- 	=-
 =-@Tx.. Tn k& k kr$   