
    hhi                         d dl mZ d dlZd dlZd dlZd dlZd dlZg dZ ej                  ej                  d      Z	ed        Z
ed        Zy)    )contextmanagerN)all_warningsexpected_warningswarn   )
stacklevelc               #     K   ddl } | j                         }|r(| j                  |      D ]  }i |d   j                  d<    ~t	        t
        j                  j                               D ]   \  }}	 |j                  j                          " t        j                  d      5 }t        j                  d       | ddd       y# t        $ r Y gw xY w# 1 sw Y   yxY ww)a&  
    Context for use in testing to ensure that all warnings are raised.

    Examples
    --------
    >>> import warnings
    >>> def foo():
    ...     warnings.warn(RuntimeWarning("bar"), stacklevel=2)

    We raise the warning once, while the warning filter is set to "once".
    Hereafter, the warning is invisible, even with custom filters:

    >>> with warnings.catch_warnings():
    ...     warnings.simplefilter('once')
    ...     foo()                         # doctest: +SKIP

    We can now run ``foo()`` without a warning being raised:

    >>> from numpy.testing import assert_warns
    >>> foo()                             # doctest: +SKIP

    To catch the warning, we call in the help of ``all_warnings``:

    >>> with all_warnings():
    ...     assert_warns(RuntimeWarning, foo)
    r   N__warningregistry__T)recordalways)inspectcurrentframegetouterframesf_localslistsysmodulesitemsr
   clearAttributeErrorwarningscatch_warningssimplefilter)r   framefmod_namemodws         W/var/www/html/dev/engine/venv/lib/python3.12/site-packages/skimage/_shared/_warnings.pyr   r      s     <    "E''. 	6A35AaDMM/0	6ckk//12 #	##))+ 
	 	 	- h'   		 sB   A-C 0C
C "C<	C 	CC CC CC c           	   #   0  K   t        | t              rt        d      | d yt        j                  j                  dd      }|j                         dk(  rd}n*|j                         dk(  rd}nt        t        |            }t               5 }| d| v r| j                  d       d| v r| D cg c]  }d	|j                  d
      vs| }}|D ]s  }d}| D ]D  }t        j                  |t        |j                              -d}||v s4|j                  |       F |sQ|rTt        dt        |j                                |r1t        |      dkD  r#d}d| |j!                  |       }	t        |	      ddd       yc c}w # 1 sw Y   yxY ww)a  Context for use in testing to catch known warnings matching regexes

    Parameters
    ----------
    matching : None or a list of strings or compiled regexes
        Regexes for the desired warning to catch
        If matching is None, this behaves as a no-op.

    Examples
    --------
    >>> import numpy as np
    >>> rng = np.random.default_rng()
    >>> image = rng.integers(0, 2**16, size=(100, 100), dtype=np.uint16)
    >>> # rank filters are slow when bit-depth exceeds 10 bits
    >>> from skimage import filters
    >>> with expected_warnings(['Bad rank filter performance']):
    ...     median_filtered = filters.rank.median(image)

    Notes
    -----
    Uses `all_warnings` to ensure all warnings are raised.
    Upon exiting, it checks the recorded warnings for the desired matching
    pattern(s).
    Raises a ValueError if any match was not found or an unexpected
    warning was raised.
    Allows for three types of behaviors: `and`, `or`, and `optional` matches.
    This is done to accommodate different build environments or loop conditions
    that may produce different warnings.  The behaviors can be combined.
    If you pass multiple patterns, you get an orderless `and`, where all of the
    warnings must be raised.
    If you use the `|` operator in a pattern, you can catch one of several
    warnings.
    Finally, you can use `|\A\Z` in a pattern to signify it as optional.

    zA``matching`` should be a list of strings and not a string itself.NSKIMAGE_TEST_STRICT_WARNINGS1trueTfalseFz\A\Z|zUnexpected warning: r   
zNo warning raised matching:)
isinstancestr
ValueErrorosenvirongetlowerboolintr   removesplitresearchmessagelenjoin)
matchingstrict_warningsr   m	remainingr   foundmatchnewlinemsgs
             r   r   r   J   s    J (C R
 	

 
jjnn%CSIO&(				 G	+s?34	 "1 hOOD! h (H1G1773<,GQH	H 	MDE! 099UC$56B E	)!((/	0
 u #7DLL8I7J!KLL	M I 2G/yi9P8QRCS/!)" " I" "sU   BFF
.F
2FF7F
F
F
$F
'AF
<	FF

FF)
contextlibr   r   r   r2   	functoolsr*   __all__partialr   r   r        r   <module>rE      sa    % 
  	  	
7
 y15 6 6r J" J"rD   