ó
    Å“,j
(  ã                   óF  • 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S j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       Ú¥C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\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©%Ð0€GØ
�Ø�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 �L‰L×Ñ˜tÓ$€EØ€IÛˆÜ—‘˜dÓ#ˆØ‰=Ø×Ñ˜TÔ"ÙØ!ŸL™L›NÑˆ�Tð	9ä�D×*Ñ*×+Ñ+Ø‘|Ð&8Ñ8�ð 	×Ñ˜Öñ! ð" —9‘9˜YÓ'€D„LØ€Køô ó 	9ä�DŸ-™-×3Ñ3×4Ñ4Ø‘|Ð&8Ñ8�ùð	9ús   Á"!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°%Ò	8¸IØ—‘ˆ÷ 
9ä‡I‚Iˆe�UÒ*Ü
�)Š)�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[        X€U5      n	[        R
                  " X˜5        O,[        X€U5      n	[        R
                  " U	[        U5      5        [        U5      n
[        X U5      n[        R
                  " X²5        g)zwCheck roundtrip behavior for color images.

All major input types should be handled as ubytes and read
back correctly.
é€   ©ÚtifÚtifféd   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Ô$à�‰9€DÜ	�4 Ó	%€BÜ×Ò˜D§)¡)¬D£/Ô2ä˜Ó€DÜ	�4 Ó	%€BÜ×Ò˜BÔ$ä�c‹?€DØ
‡y�yƒ{�Ó'Ø�‰ˆÜ�t SÓ)ˆÜ×Ò Õ)ä�t SÓ)ˆÜ×Ò ¤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[        X€U5      n	[        R
                  " X˜5        O,[        X€U5      n	[        R
                  " U	[        U5      5        [        U5      n
[        X U5      n[        R
                  " Xº5        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!  € ô ”t—y’y“{Ó
#€CÜ	�3 Ó	$€BÜ×Ò˜CÔ$à�‰9€DÜ	�4 Ó	%€BÜ×Ò˜D§)¡)¬D£/Ô2ä˜Ó€DÜ	�4 Ó	%€BØ	‡x�x‡}�}˜ÓÜ×Ò Õ)ä×Ò ¤K°Ó$4Ô5ä�c‹?€DØ
‡y�yƒ{�Ó'Ø�‰ˆÜ�t SÓ)ˆÜ×Ò Õ)ä�t SÓ)ˆÜ×Ò ¤K°Ó$5Ô6ä�sÓ€DÜ	�4 Ó	%€BÜ×Ò˜BÕ%r(   c                 ór   •  [        XS9$ ! [        [        4 a    [        R                  " SU  3SS9   gf = f)aÚ  Attempt to fetch data, but if unavailable, skip the tests.

Parameters
----------
data_filename : str
    File path in the scikit-image repo tree, e.g.,
    'restoration/camera_rl.npy', possibly pointing to a remote location.

prefix : str, optional
    If None, `data_filename` is prefixed by 'src/skimage'
    If 'tests', `data_filename` is prefixed by 'tests/skimage'.

Returns
-------
file_path : str
    Path of the local file, possibly pointing to a remote location.

)ÚprefixzUnable to download T)Úallow_module_levelN)r   ÚConnectionErrorÚModuleNotFoundErrorÚpytestÚskip)Údata_filenamern   s     r&   Úfetchru   Ä   s@   € ð&TÜ�mÑ3Ð3øÜÔ0Ð1ó TÜ�ŠÐ)¨-¨Ð9ÈdÔSðTús   ‚ ‹(6µ6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
----------
workers : 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   )	rz   r{   ÚthreadsÚiÚthreadr8   Ú	threadingÚwarnings_matchingÚworkerss	        €€€€r&   ÚinnerÚ/run_in_parallel.<locals>.wrapper.<locals>.innerý   sˆ   ø€ ä"Ð#4Õ5Ø�Ü˜w¨™{Ö+�AØ&×-Ñ-°TÀÐ-ÐT�FØ—N‘N 6Ö*ñ ,ó &�FØ—L‘L–Nñ &ñ �dÐ%˜fÒ%ã%�FØ—K‘K–Mñ &÷ 6×5Ö5ús   �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   ù€ ð* �Q‹;Ðˆ;öð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 Ðä�MŠM‹O˜AÑ×$Ñ$€EØ—.‘. 6Ñ)€KØ�|‰|×'Ñ'€HØ�˜1˜[˜MÐ*€HÛˆØ×$Ñ$Ð% Q w§~¡~Ð&6Ð7ˆðØ#˜*ð %Ø˜ð !Ø×!Ñ!×*Ñ*Ð+¨2¨g¯o©oÐ->ð@ð 	ð Õ!Ð& 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   rr   ÚmarkÚskipifÚxfailÚparametrizeÚraisesÚfixtureÚcompiler/   ÚcalcsizeÚarch32r'   r*   r?   rO   rf   rl   ru   r‹   r    r    r(   r&   Ú<module>r¸      sö   ðñó 
Û Û 	Û Û 
Û Û Ý 'ã Ý ÷÷ ÷ ñ ÷ Ý #ß FÓ FÝ (Ý 'ã ð 
�‰×	Ñ	€Ø�‰×Ñ€Ø�k‰k×%Ñ%€Ø	�‰€Ø
�.‰.€à
�*Š*Ð=Ó
>€ð
 
�Š˜Ó	 Ñ	! RÑ	'€ôôò,ò^ô%ô@ &ôFTô6/ðd +-ö 6'r(   