
    0-Phi                         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dS )    )contextmanagerN)all_warningsexpected_warningswarn   )
stacklevelc               #     K   ddl } |                                 }|r(|                     |          D ]}i |d         j        d<   ~t	          t
          j                                                  D ]/\  }}	 |j        	                                  # t          $ r Y ,w xY wt          j        d          5 }t          j        d           |V  ddd           dS # 1 swxY w Y   dS )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         Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/_shared/_warnings.pyr   r      sW     < NNN   ""E 6''.. 	6 	6A35AaDM/00ck//1122  #	#))++++ 	 	 	D	 
	 	-	-	- h'''                 s$   7B
BB6CC #C c           	   #   Z  K   t          | t                    rt          d          | dV  dS t          j                            dd          }|                                dk    rd}n7|                                dk    rd}nt          t          |                    }t                      5 }|V  d| v r| 
                    d           d| v d	 | D             }|D ]s}d}| D ]D}t          j        |t          |j                            d}||v r|
                    |           E|r&|s$t          d
t          |j                             t|r>t          |          dk    r+d}d| |                    |           }t          |          ddd           dS # 1 swxY w Y   dS )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falseFc                 @    g | ]}d |                     d          v|S )z\A\Z|)split).0ms     r   
<listcomp>z%expected_warnings.<locals>.<listcomp>   s,    HHH1G1773<<,G,GQ,G,G,G    zUnexpected warning: r   
zNo warning raised matching:)
isinstancestr
ValueErrorosenvirongetlowerboolintr   removeresearchmessagelenjoin)	matchingstrict_warningsr   	remainingr   foundmatchnewlinemsgs	            r   r   r   J   s@     J (C   
R
 
 	

 


jnn%CSIIO&((				 	 G	+	+s?3344	 "1 hOOD!!! hHHHHH	 	M 	MDE! 0 09UC$5$566B E	))!((/// Mu M !KDL8I8I!K!KLLL 	"I 2 2GRRi9P9PRRCS//!)" " " " " " " " " " " " " " " " " "s   /C$F  F$'F$)
contextlibr   r   r   r7   	functoolsr0   __all__partialr   r   r    r+   r   <module>rH      s    % % % % % % 



  				     				
7
7
7
 y1555 6 6 6r J" J" J" J" J"r+   