
    a6dU%                        d Z ddlZddlZddlZddlZddlZddlmZ ddlZ	ddlm
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZ ddlZddlmZmZ ddlmZ dd	lmZmZm Z m!Z! d
dl"m#Z# ddl$Z$e$j%        j&        Z&e$j%        j'        Z'e$j%        j(        Z(e$j)        Z)e$j*        Z* ej+        d          Z, ej-        d          dz  dk    Z.ej/        0                    dd          Z1e12                                dk    rdZ1n>e12                                dk    rdZ1n#	  e3 e4e1                    Z1n# e5$ r dZ1Y nw xY wd!dZ6d!dZ7d Z8d Z9d"dZ:d"dZ;d Z<d Z=d Z>e$j%        ?                                d#d             Z@dS )$z
Testing utilities.
    N)NamedTemporaryFile)testing)TestCaseassert_assert_warnsassert_no_warningsassert_equalassert_almost_equalassert_array_equalassert_allcloseassert_array_almost_equalassert_array_almost_equal_nulpassert_array_less   )dataio)_fetch)img_as_uintimg_as_float
img_as_intimg_as_ubyte   )expected_warningsz%(\s*>>>.*?)(\s*)#\s*skip\s+if\s+(.*)$P       #SKIMAGE_TEST_STRICT_WARNINGS_GLOBAL0trueTfalseFc                 H    | d|}||d|z   z  }| |k     s
J |            d S )Nz is not lower than :  abmsgmessages       7lib/python3.11/site-packages/skimage/_shared/testing.pyassert_lessr*   :   s?    ....G
4#:q555'55555    c                 H    | d|}||d|z   z  }| |k    s
J |            d S )Nz is not greater than r"   r#   r$   s       r)   assert_greaterr-   A   s?    00100G
4#:q555'55555r+   c                    | j                             d          }g }|D ]}t                              |          }||                    |           4|                                \  }}}	 t          || j                  r||z   dz   }n2# t          $ r% t          || j	        j                  r||z   dz   }Y nw xY w|                    |           d
                    |          | _         | S )aD   Decorator replaces custom skip test markup in doctests

    Say a function has a docstring::

        >>> something, HAVE_AMODULE, HAVE_BMODULE = 0, False, False
        >>> something # skip if not HAVE_AMODULE
        0
        >>> something # skip if HAVE_BMODULE
        0

    This decorator will evaluate the expression after ``skip if``.  If this
    evaluates to True, then the comment is replaced by ``# doctest: +SKIP``. If
    False, then the comment is just removed. The expression is evaluated in the
    ``globals`` scope of `func`.

    For example, if the module global ``HAVE_AMODULE`` is False, and module
    global ``HAVE_BMODULE`` is False, the returned function will have docstring::

        >>> something # doctest: +SKIP
        >>> something + else # doctest: +SKIP
        >>> something # doctest: +SKIP

    
Nz# doctest: +SKIP)__doc__splitSKIP_REmatchappendgroupseval__globals__AttributeError__init__join)funclines	new_linesliner3   codespaceexprs           r)   doctest_skip_parserrB   H   s   0 Lt$$EI  d##=T"""!LLNNeT	9D$*++ 9e|&88 	9 	9 	9D$-344 9e|&88	9
 	99Y''DLKs   ,B

,B98B9c                    d|vrd|z   }t          |d          5 }|j        }ddd           n# 1 swxY w Y   t          j        || |           t          j        ||          }	 t          j        |           n# t          $ r Y nw xY w|S )z/Save and read an image using a specified plugin.F)suffixdeleteN)plugin)r   namer   imsaveimreadosremove	Exception)imagerG   rE   	temp_filefnamenews         r)   	roundtriprR   w   s    
&v	6%	8	8	8 I              IeU6****
)E&
)
)
)C
	%   Js   /33(A= =
B
	B
pngc                    t          t          j                              }t          || |          }t	          j        ||           |dk    }t          || |          }t	          j        ||                    t                               t          |          }t          || |          }t	          j        ||           t          |          }|
                                dv r,|dz  }t          || |          }	t	          j        |	|           n3t          || |          }	t	          j        |	t          |                     t          |          }
t          |
| |          }t	          j        ||           dS )zCheck roundtrip behavior for color images.

    All major input types should be handled as ubytes and read
    back correctly.
       tiftiffd   N)r   r   chelsearR   r   r   astypeboolr   r   lowerr   rG   fmtimgr1img2r2img3r3img4r4img5r5s               r)   color_checkrj      sT    t|~~
&
&C	3	$	$BC$$$9D	4	%	%BD"))D//222D	4	%	%BB$$$c??D
yy{{''tVS))D))))tVS))L$6$6777sD	4	%	%BB$$$$$r+   c                 \   t          t          j                              }t          || |          }t	          j        ||           |dk    }t          || |          }t	          j        ||                    t                               t          |          }t          || |          }|j	        j
        dk    rt	          j        ||           n"t	          j        |t          |                     t          |          }|                                dv r,|dz  }t          || |          }	t	          j        |	|           n3t          || |          }	t	          j        |	t          |                     t          |          }
t          |
| |          }t	          j        ||
           dS )zsCheck the roundtrip behavior for images that support most types.

    All major input types should be handled.
    rU   frV   rY   N)r   r   moonrR   r   r   r[   r\   r   dtypekindr   r   r]   r^   s               r)   
mono_checkrp      s    ty{{
#
#C	3	$	$BC$$$9D	4	%	%BD"))D//222D	4	%	%B	x}b))))K$4$4555c??D
yy{{''tVS))D))))tVS))K$5$5666sD	4	%	%BB%%%%%r+   c                  l   t          j        d           t          rt          j                            d           t          j        d           t          j        ddt                     t          j        ddt                     t          j        ddt          d	           t          j        dd
t          d	           t          j        ddt                     t          j        ddt                     t          j        ddt                     t          j        ddt                     dS dS )zDefault package level setup routine for skimage tests.

    Import packages known to raise warnings, and then
    force warnings to raise errors.

    Also set the random seed to zero.
    defaultr   errorzunclosed file)r(   categoryz/Conversion of the second argument of issubdtypez.the matrix subclass is not the recommended waynumpy)r(   rt   modulezYour installed pillow versionz
skimage.ioz.The optional dask dependency is not installed.znumpy.ufunc size changedz#

The scipy.sparse array containersz-`np.int0` is a deprecated alias for `np.intp`N)warningssimplefilter_error_on_warningsnprandomseedfilterwarningsResourceWarningFutureWarningPendingDeprecationWarningUserWarningRuntimeWarningDeprecationWarningr#   r+   r)   
setup_testr      s    )$$$ 9

	qg&&&	
 	
 	
 	
 	E"	
 	
 	
 	
 	D.w	
 	
 	
 	
 	3 		
 	
 	
 	
 	D 	
 	
 	
 	
 	.#	
 	
 	
 	
 	;'	
 	
 	
 	
 	D'	
 	
 	
 	
 	
 	
k9
 9
r+   c                  f    t           r)t          j                     t          j        d           dS dS )zhDefault package level teardown routine for skimage tests.

    Restore warnings to default behavior
    rr   N)ry   rw   resetwarningsrx   r#   r+   r)   teardown_testr     s<    
  )   i((((() )r+   c                     	 t          |           S # t          t          f$ r t          j        d|  d           Y dS w xY w)z:Attempt to fetch data, but if unavailable, skip the tests.zUnable to download T)allow_module_levelN)r   ConnectionErrorModuleNotFoundErrorpytestskip)data_filenames    r)   fetchr     sl    -m$$$01 - - -9-99'+	- 	- 	- 	- 	- 	- 	--s    *??c                 &      dk    sJ  fd}|S )a`  Decorator to run the same function multiple times in parallel.

    This decorator is useful to ensure that separate threads execute
    concurrently and correctly while releasing the GIL.

    Parameters
    ----------
    num_threads : int, optional
        The number of times the function is run in parallel.

    warnings_matching: list or None
        This parameter is passed on to `expected_warnings` so as not to have
        race conditions with the warnings filters. A single
        `expected_warnings` context manager is used for all threads.
        If None, then no warnings are checked.

    r   c                 L     t          j                    fd            }|S )Nc                  T   t                    5  g }t          dz
            D ].}t          j        | |          }|                    |           /|D ]}|                                  | i | |D ]}|                                 	 d d d            d S # 1 swxY w Y   d S )Nr   )targetargskwargs)r   range	threadingThreadr4   startr:   )r   r   threadsithreadr;   num_threadswarnings_matchings        r)   innerz-test_parallel.<locals>.wrapper.<locals>.inner9  s   "#455 " "{Q// + +A&-T5;= = =FNN6****% # #FLLNNNNd%f%%%% " "FKKMMMM"" " " " " " " " " " " " " " " " " "s   A>BB!$B!)	functoolswraps)r;   r   r   r   s   ` r)   wrapperztest_parallel.<locals>.wrapper8  sC    				" 	" 	" 	" 	" 	" 
		" r+   r#   )r   r   r   s   `` r)   test_parallelr   "  s8    ( ????     & Nr+   )N)rS   )r   N)Ar0   rK   restructr   r   tempfiler   ru   rz   r   numpy.testingr   r   r   r   r	   r
   r   r   r   r   r   rw    r   r   data._fetchersr   utilr   r   r   r   	_warningsr   r   markskipifxfailparametrizeraisesfixturecompiler2   calcsizearch32environgetry   r]   r\   int
ValueErrorr*   r-   rB   rR   rj   rp   r   r   r   r   r   r#   r+   r)   <module>r      sE    
			 				          ' ' ' ' ' '                                             # # # # # # F F F F F F F F F F F F ( ( ( ( ( (  
	k%	
.
"*=
>
> 
			!R	' Z^^$I3OO ''7**#!T##&8"9"9:: # # #"#      , , ,^  % % % %@ &  &  &  &FC
 C
 C
L) ) )- - - ( ( ( ( ( (s   D) )D32D3