Ë
    æØjj36  ã                  ó  — 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)z¥Return 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    úQ/opt/eval-harness/bench_task/venv/lib/python3.12/site-packages/_pytest/recwarn.pyÚrecwarnr   $   s<   è ø€ ô  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%   :   s[   € ð2 ÐÜ&Ô(AÄ=ÐQ€LØ€|Ü�\Ð3 DÒ3¨FÑ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Ø.4¯j©j¸À$Ó.GˆÙØ—y‘y¤¨£Ó0ˆHÜØGÈÀzØ5ð6óð ô Ð/¸EÈTÔRÐRä˜Œ~Ü˜t˜h o´d¸4³j°\Ð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   € ð �z‰zÐr&   c                ó    — | j                   |   S )z Get a recorded warning by index.rI   )rF   Úis     r   Ú__getitem__zWarningsRecorder.__getitem__Ç   s   € à�z‰z˜!‰}Ðr&   c                ó,   — t        | j                  «      S )z&Iterate through the recorded warnings.)ÚiterrE   rJ   s    r   Ú__iter__zWarningsRecorder.__iter__Ë   s   € ä�D—J‘JÓÐ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�«      ‚)zÁPop 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®   € ð
  $ˆÜ˜dŸj™jÓ)ò 	‰DˆAˆqØ�z‰z˜SÒ Ø—z‘z—~‘~ aÓ(Ò(Ü˜!Ÿ*™* cÕ*ØÐ Ü! !§*¡*¨d¯j©j¸Ñ.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   ø€ Ø�=Š=Ø $ÐÜ ¨t¨h°fÐ=Ó>Ð>Ü‘Ñ!Ó#ˆàÐ Ð Ð ØˆŒ
Ü×Ñ˜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   ø€ ð �}Š}Ø $ÐÜ ¨d¨XÐ5LÐMÓNÐNä‰Ñ˜ 7¨FÔ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ÐÔ(à?ˆÜÐ&¬Ô.Ø'ò 5�Ü! #¤wÕ/Ü# C¬$¨s«)¡OÓ4Ð4ð5ð $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Ø�O‰O˜tÐ#ÒW¤r§y¡y°·±Ä#ÀgÇoÁoÓBVÓ'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"   ø€ Ü¸Ö>¨v˜FŸN›NÒ>À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"   øè ø€ ÒSÈ”z !§*¡*¨d×.CÑ.C×DÑSùs   ƒ*-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ŸÑ7ù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ð —O‘O¤s¨1¯9©9£~Õ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¢  ù€ ô 	‰Ñ˜ 7¨FÔ3à Ðð ÐÜ˜7¤IÔ.ä˜'¤4Ô(àõ	Jð9	ÜÓSÈdÔSÔSÜØ8¸×9NÑ9NÐ8Oð P*Ù*3«+¨°að9õô Ó7°$Ô7Ô7Ø �Ü˜dŸo™o¬sÔ3¼ó <à!ô<ô 9ð
 #P�KÜØ=¼cÀ$»i¸[ð IØ#Ÿ™Ð1ð 2*Ù*3«+¨°a¸°}ðFôð ò 	�Ø—|‘| A•Ü×*Ñ*Ø !§	¡	Ø!"§¡Ø!"§¡Ø Ÿx™xØ Ÿ|™|Ø Ÿx™xöð	ð& ò �Ü˜Ÿ	™	“?¬+Ñ5ð Ø—y‘y—~’~àØ—i‘i—n‘n QÑ'�Ü˜c¤3Ô'Øô  Ø:¸3¸'ÀÌÈcË×I[ÑI[ÐH\Ð\]Ð^óð ñøð' ò 	�Ø—|‘| A•Ü×*Ñ*Ø !§	¡	Ø!"§¡Ø!"§¡Ø Ÿx™xØ Ÿ|™|Ø Ÿx™xöð	ð& ò �Ü˜Ÿ	™	“?¬+Ñ5ð Ø—y‘y—~’~àØ—i‘i—n‘n QÑ'�Ü˜c¤3Ô'Øô  Ø:¸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ã å -Ý $Ý !Ý !ñ ˆCƒL€ð 	òó 	ðð 
à-0ñØ*ðàòó 
ðð
 
Ú Vó 
Ø Vð '+ð%Ø
#ð%Ø36ð%ØBEð%àó%ðD 
àBEðð +.ñØ?ðð (ðð ò	ó 
ðð 
ðØ?ðà
ðð ðð ð	ð
 òó 
ðð CJØ)-ð?)Ø?ð?)à
&ð?)ð ð?)ð ð	?)ð
 ó?)ôDV�x×.Ñ.ô Vðr ôrÐ&ó ró ñrr&   