
    	h*                        d Z ddl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m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.    Npformat)TracebackType)Any)Callable)	Generator)Iterator)List)Optional)Pattern)Tuple)Type)TypeVar)Union)final)overload)check_ispytest)WARNS_NONE_ARG)fixture)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    \/var/www/html/web-builder-api.evdpl.com/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(   *   	     C    funcargskwargsc                     d S r&   r'   )r+   r,   r-   s      r!   r(   r(   1   r)   r*   c                 N    d}| | f|z   }t          t          t          fg|R i |S )a  Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning``.

    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)r+   r,   r-   __tracebackhide__s       r!   r(   r(   8   s@    4 w~$&?@R4RRR6RRRr*   expected_warningWarningsCheckerc                    d S r&   r'   )r4   r$   s     r!   r0   r0   X   s	     Cr*   c                     d S r&   r'   )r4   r+   r,   r-   s       r!   r0   r0   a   s	     Cr*   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 sequence
    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 raised (regardless of whether it is an ``expected_warning`` or not).

    This function can be used as a context manager, which will capture all the raised
    warnings inside it::

        >>> 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, 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!   r0   r0   k   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                     t          | j                  D ]6\  }}t          |j        |          r| j                            |          c S 7d}t          |d          )z>Pop the first recorded warning, raise exception if not exists.Tz not found in warning list)	enumeraterG   
issubclasscategorypopAssertionError)rH   rW   rN   wr3   s        r!   r\   zWarningsRecorder.pop   so    dj)) 	) 	)DAq!*c** )z~~a((((() 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!   rd   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   rc   rD   __exit__)rH   re   rf   rg   r3   rI   s        r!   ri   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\   r`   rd   r   BaseExceptionr   ri   __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e         df         f                  deeee	e         f                  de
ddf 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          j        t
          d           d }nt          |t                    r<|D ]6}t          |t                    st          |t          |          z            7|}n8t          |t                    r|f}nt          |t          |          z            || _        || _        d S )NTr   z/exceptions must be derived from Warning, not %s   )
stacklevel)r   rD   rE   r   warnr   
isinstancetuplerZ   rq   r=   r?   r4   r9   )rH   r4   r9   r   msgexpected_warning_tupexcrI   s          r!   rE   zWarningsChecker.__init__   s     	y!!!4(((?#M.Q7777#'  (%00 	:' 5 5!#w// 5#C$s))O4445#3  ('22 	:$4#6  C$'7"8"88999 4$r*   re   rf   rg   c           	      2    t                                          |||           d} fd}||| j        t           fd D                       s'd}t	          d j         d |             d           d S  j         D ]]}t          |j         j                  rAt          j	         j                  
                    t          |j                            r d S ^t	          d j         d j         d |                        d S d S d S d S d S d S )	NTc                  :    t          d  D             d          S )Nc                     g | ]	}|j         
S r'   )message).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_str"  s%    >>>>>qIIIIr*   c              3   L   K   | ]}t          |j        j                  V  d S r&   )rZ   r[   r4   )r   rrH   s     r!   	<genexpr>z+WarningsChecker.__exit__.<locals>.<genexpr>(  s2      WWQ:aj$2GHHWWWWWWr*   z"DID NOT WARN. No warnings of type z0 were emitted.
The list of emitted warnings is: .z* matching the regex were emitted.
 Regex: z
 Emitted warnings: )rD   ri   r4   anyr   r9   rZ   r[   recompilesearchstrr   )rH   re   rf   rg   r3   r   r   rI   s   `      r!   ri   zWarningsChecker.__exit__  s    	7F333 	J 	J 	J 	J 	J FN$0WWWWRVWWWWW (,%KT=R K K<EIKKK K K     _0! 
 
%aj$2GHH &!z$/::AA#ai..QQ & %$#'#8$ $	$ $ IKK$ $     NN00 10r*   )rj   rk   rl   rq   r   r   r   r   r   r   rn   rE   rr   r   ri   rs   rt   s   @r!   r5   r5      s        9=%  % % %"$w-tG}c'9!::;
%
 U3#456% % 
% % % % % %:!4./! -(! '	!
 
! ! ! ! ! ! ! ! ! !r*   r&   ).)&rm   r   r   pprintr   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   _pytest.compatr   r   _pytest.deprecatedr   r   _pytest.fixturesr   _pytest.outcomesr   r   r"   r   r(   rq   r0   catch_warningsr   r5   r'   r*   r!   <module>r      s   5 5 				                                                                                            # # # # # # - - - - - - - - - - - - $ $ $ $ $ $ ! ! ! ! ! ! GCLL 		9: 	 	 	 		 
36  uS'#,./0   
 

36
#&25   
 *.S S
8CH%
&S69SEHS
s"#S S S S@ 
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!"<- <- <- <-~L L L L Lx. L L L^ ? ? ? ? ?& ? ? ? ? ?r*   