
    9i$                     B   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
rSSK
Jr  SSKJrJrJrJrJrJrJrJrJrJrJr  SSKJrJr  SSKJr  SS	KJrJ r J!r!J"r"  S
SK#J$r$  S
SK%J&r&  SSK'r'\'RP                  RR                  r)\'RP                  RT                  r*\'RP                  RV                  r+\'RX                  r,\'RZ                  r-\R\                  " S5      r/\R`                  " S5      S-  S:H  r1SS jr2SS jr3S r4S r5SS jr6SS jr7S r8SS jr9SS.S jr:g)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_warnings)is_wasmz%(\s*>>>.*?)(\s*)#\s*skip\s+if\s+(.*)$P       c                 D    U < SU< 3nUb  USU-   -  nX:  d   U5       eg )Nz is not lower than :  abmsgmessages       W/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/_shared/testing.pyassert_lessr'   5   s5    (.G
4#:5'5    c                 D    U < SU< 3nUb  USU-   -  nX:  d   U5       eg )Nz is not greater than r   r    r!   s       r&   assert_greaterr*   <   s5    *1%0G
4#:5'5r(   c                    U R                   R                  S5      n/ nU Ht  n[        R                  U5      nUc  UR	                  U5        M.  UR                  5       u  pVn [        XpR                  5      (       a  XV-   S-   nUR	                  U5        Mv     SR                  U5      U l         U $ ! [         a.    [        XpR                  R                  5      (       a  XV-   S-   n Ndf = f)a  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


z# doctest: +SKIP)__doc__splitSKIP_REmatchappendgroupseval__globals__AttributeError__init__join)funclines	new_linesliner0   codespaceexprs           r&   doctest_skip_parserr?   C   s    0 LLt$EId#=T"!LLNT	9D**++|&88 	! " 99Y'DLK  	9D--3344|&88	9s   "!B005C('C(c                    SU;  a  SU-   n[        USS9 nUR                  nSSS5        [        R                  " WXS9  [        R                  " XAS9n [
        R                  " U5        U$ ! , (       d  f       NP= f! [         a     U$ f = f)z/Save and read an image using a specified plugin.F)suffixdeleteN)plugin)r   namer   imsaveimreadosremove	Exception)imagerD   rB   	temp_filefnamenews         r&   	roundtriprO   r   s    
&v	6%	8I 
9IIeU*
))E
)C
		% J 
9	8  Js   A-A> -
A;>
BBc                    [        [        R                  " 5       5      n[        X U5      n[        R
                  " X#5        US:  n[        X@U5      n[        R
                  " XER                  [        5      5        [        U5      n[        X`U5      n[        R
                  " Xr5        [        U5      nUR                  5       S;   a(  US-  n[        XU5      n	[        R
                  " X5        O,[        XU5      n	[        R
                  " U	[        U5      5        [        U5      n
[        XU5      n[        R
                  " X5        g)zwCheck roundtrip behavior for color images.

All major input types should be handled as ubytes and read
back correctly.
   tiftiffd   N)r   r   chelsearO   r   r   astypeboolr   r   lowerr   rD   fmtimgr1img2r2img3r3img4r4img5r5s               r&   color_checkrf      s     t||~
&C	3	$BC$9D	4	%BD))D/2D	4	%BB$c?D
yy{'tS))tS)L$67sD	4	%BB$r(   c                    [        [        R                  " 5       5      n[        X U5      n[        R
                  " X#5        US:  n[        X@U5      n[        R
                  " XER                  [        5      5        [        U5      n[        X`U5      nUR                  R                  S:X  a  [        R
                  " Xg5        O [        R
                  " U[        U5      5        [        U5      nUR                  5       S;   a(  US-  n[        XU5      n	[        R
                  " X5        O,[        XU5      n	[        R
                  " U	[        U5      5        [        U5      n
[        XU5      n[        R
                  " X5        g)zkCheck the roundtrip behavior for images that support most types.

All major input types should be handled.
rQ   frR   rU   N)r   r   moonrO   r   r   rW   rX   r   dtypekindr   r   rY   rZ   s               r&   
mono_checkrl      s!    tyy{
#C	3	$BC$9D	4	%BD))D/2D	4	%B	xx}})K$45c?D
yy{'tS))tS)K$56sD	4	%BB%r(   c                 v     [        U 5      $ ! [        [        4 a    [        R                  " SU  3SS9   gf = f)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&   fetchrt      s@    Tm$$01 T)-9dSTs   
 (88c                 (   ^ ^ T S:  d   eU U4S jnU$ )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.

It is currently skipped when running on WASM-based platforms, as
the threading module is not supported.

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                 r   >^ ^ [         (       a  T $ SS Km[        R                  " T 5      U UUU4S j5       nU$ )Nr   c                  4  > [        T5         / n[        TS-
  5       H$  nTR                  TXS9nUR                  U5        M&     U H  nUR	                  5         M     T" U 0 UD6  U H  nUR                  5         M     S S S 5        g ! , (       d  f       g = f)Nr   )targetargskwargs)r   rangeThreadr1   startr7   )	ry   rz   threadsithreadr8   num_threads	threadingwarnings_matchings	        r&   inner/run_in_parallel.<locals>.wrapper.<locals>.inner   s    "#45{Q/A&--T-TFNN6* 0 &FLLN & d%f%%FKKM & 655s   A3B		
B)r   r   	functoolswraps)r8   r   r   r   r   s   ` @r&   wrapper run_in_parallel.<locals>.wrapper   s2    7K			" 
	" r(   r    )r   r   r   s   `` r&   run_in_parallelr      s    , ??0 Nr(   )offsetc          	      \   Sn[         R                  " 5       S   R                  nUR                  U-   nUR                  R
                  nU SU 3nU  HV  nUR                   SUR                   3nSU SU SUR                  R                   SUR                   3n	X:X  a  MQ   U	5       e   g)	a  Assert correct stacklevel of captured warnings.

When scikit-image raises warnings, the stacklevel should ideally be set
so that the origin of the warnings will point to the public function
that was called by the user and not necessarily the very place where the
warnings were emitted (which may be inside some internal function).
This utility function helps with checking that
the stacklevel was set correctly on warnings captured by `pytest.warns`.

Parameters
----------
warnings : collections.abc.Iterable[warning.WarningMessage]
    Warnings that were captured by `pytest.warns`.
offset : int, optional
    Offset from the line this function is called to the line were the
    warning is supposed to originate from. For multiline calls, the
    first line is relevant. Defaults to -1 which corresponds to the line
    right above the one where this function is called.

Raises
------
AssertionError
    If a warning in `warnings` does not match the expected line number or
    file name.

Examples
--------
>>> def test_something():
...     with pytest.warns(UserWarning, match="some message") as record:
...         something_raising_a_warning()
...     assert_stacklevel(record)
...
>>> def test_another_thing():
...     with pytest.warns(UserWarning, match="some message") as record:
...         iam_raising_many_warnings(
...             "A long argument that forces the call to wrap."
...         )
...     assert_stacklevel(record, offset=-3)
Tr   :z+Warning with wrong stacklevel:
  Expected: z
  Actual: z
  r   N)inspectstackframef_linenof_codeco_filenamefilenamelinenocategory__name__r%   )
warningsr   __tracebackhide__r   line_numberr   expectedwarningactualr$   s
             r&   assert_stacklevelr     s    P MMOA$$E..6)K||''H1[M*H$$%Qw~~&67#* % !!!**+2goo->@ 	 !&3&! r(   )N)png)r   N);r-   rH   platformrestructsysr   r   tempfiler   numpynpr   numpy.testingr   r   r   r   r	   r
   r   r   r   r   r    r   r   data._fetchersr   utilr   r   r   r   	_warningsr   _dependency_checksr   rq   markskipifxfailparametrizeraisesfixturecompiler/   calcsizearch32r'   r*   r?   rO   rf   rl   rt   r   r   r    r(   r&   <module>r      s    
  	  
   '       # F F ( '  
		kk%%	
..
**=
>
 
		!R	',^%@ &FT0f +- 6'r(   