o
    h                      @  s   d dl mZ d dlmZmZ d dlZd dlZd dlZd dlm	Z	m
Z
mZ d dlZd dlmZ e	r8d dlmZmZ eeddddfd(ddZd)ddZd*ddZd+d d!Zd,d$d%Zd-d&d'ZdS ).    )annotations)contextmanagernullcontextN)TYPE_CHECKINGLiteralcast)PY311)	GeneratorSequencealwaysTexpected_warning7type[Warning] | bool | tuple[type[Warning], ...] | Nonefilter_levelALiteral['error', 'ignore', 'always', 'default', 'module', 'once']check_stacklevelboolraise_on_extra_warningsmatch
str | Nonereturn4Generator[list[warnings.WarningMessage], None, None]c                 c  s    d}t jddH}t | z|V  W | r%ttt | } t|| ||d |r-t|| d n| r?ttt | } t|| ||d |rHt|| d w w W d   dS 1 sTw   Y  dS )a$	  
    Context manager for running code expected to either raise a specific warning,
    multiple specific warnings, or not raise any warnings. Verifies that the code
    raises the expected warning(s), and that it does not raise any other unexpected
    warnings. It is basically a wrapper around ``warnings.catch_warnings``.

    Parameters
    ----------
    expected_warning : {Warning, False, tuple[Warning, ...], None}, default Warning
        The type of Exception raised. ``exception.Warning`` is the base
        class for all warnings. To raise multiple types of exceptions,
        pass them as a tuple. To check that no warning is returned,
        specify ``False`` or ``None``.
    filter_level : str or None, default "always"
        Specifies whether warnings are ignored, displayed, or turned
        into errors.
        Valid values are:

        * "error" - turns matching warnings into exceptions
        * "ignore" - discard the warning
        * "always" - always emit a warning
        * "default" - print the warning the first time it is generated
          from each location
        * "module" - print the warning the first time it is generated
          from each module
        * "once" - print the warning the first time it is generated

    check_stacklevel : bool, default True
        If True, displays the line that called the function containing
        the warning to show were the function is called. Otherwise, the
        line that implements the function is displayed.
    raise_on_extra_warnings : bool, default True
        Whether extra warnings not of the type `expected_warning` should
        cause the test to fail.
    match : str, optional
        Match warning message.

    Examples
    --------
    >>> import warnings
    >>> with assert_produces_warning():
    ...     warnings.warn(UserWarning())
    ...
    >>> with assert_produces_warning(False):
    ...     warnings.warn(RuntimeWarning())
    ...
    Traceback (most recent call last):
        ...
    AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
    >>> with assert_produces_warning(UserWarning):
    ...     warnings.warn(RuntimeWarning())
    Traceback (most recent call last):
        ...
    AssertionError: Did not see expected warning of class 'UserWarning'.

    ..warn:: This is *not* thread-safe.
    T)record)caught_warningsr   r   r   )r   r   N)warningscatch_warningssimplefilterr   typeWarning_assert_caught_expected_warning _assert_caught_no_extra_warnings)r   r   r   r   r   __tracebackhide__w r"   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/pandas/_testing/_warnings.pyassert_produces_warning   sH   C
"r$   warningtype[Warning]	conditionc                 K  s   |r
t | fi |S t S )zX
    Return a context manager that possibly checks a warning based on the condition
    )r$   r   )r%   r'   kwargsr"   r"   r#   maybe_produces_warnings   s   r)   r   !Sequence[warnings.WarningMessage]Nonec                 C  s   d}d}g }| D ]&}t |j|r.d}|rt| |dur.t|t|jr(d}q||j q|s;tdt	|j
 |rO|sQtdt	|j
 d| d| dS dS )zEAssert that there was the expected warning among the caught warnings.FTNz&Did not see expected warning of class zDid not see warning z matching 'z$'. The emitted warning messages are )
issubclasscategory&_assert_raised_with_correct_stacklevelresearchstrmessageappendAssertionErrorrepr__name__)r   r   r   r   saw_warningmatched_messageunmatched_messagesactual_warningr"   r"   r#   r   }   s8   r   c                 C  s   g }| D ]5}t ||r9|jtkr#dt|jv rqtdd tjD r#qtr+|jt	kr+q|
|jj|j|j|jf q|rEtdt| dS )zFAssert that no extra warnings apart from the expected ones are caught.zunclosed <ssl.SSLSocketc                 s  s    | ]}d |v V  qdS )
matplotlibNr"   ).0modr"   r"   r#   	<genexpr>   s    z3_assert_caught_no_extra_warnings.<locals>.<genexpr>zCaused unexpected warning(s): N)_is_unexpected_warningr-   ResourceWarningr1   r2   anysysmodulesr   EncodingWarningr3   r6   filenamelinenor4   r5   )r   r   extra_warningsr:   r"   r"   r#   r      s*   

	r   r:   warnings.WarningMessagec                 C  s,   | r|sdS t tt |}tt| j| S )z1Check if the actual warning issued is unexpected.T)r   r   r   r   r,   r-   )r:   r   r"   r"   r#   r?      s   r?   c                 C  sb   t  }tdD ]}|j}qzt |}W ~n~w d| j d| d| j }| j|ks/J |d S )N   zGWarning not set with correct stacklevel. File where warning is raised: z != z. Warning message: )inspectcurrentframerangef_backgetfilerE   r2   )r:   frame_caller_filenamemsgr"   r"   r#   r.      s   r.   )r   r   r   r   r   r   r   r   r   r   r   r   )r%   r&   r'   r   )
r   r*   r   r&   r   r   r   r   r   r+   )r   r*   r   r   r   r+   )r:   rH   r   r   r   r   )r:   rH   r   r+   )
__future__r   
contextlibr   r   rJ   r/   rB   typingr   r   r   r   pandas.compatr   collections.abcr	   r
   r   r$   r)   r   r   r?   r.   r"   r"   r"   r#   <module>   s,    
X


'
'