
    
3jH                     n   S SK r S SKrS SKrS SKrS SKJr  S SKJ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rS SKrS SKJrJrJrJrJrJr  S SKJr  SSKJrJrJr  SS	K J!r!  \ RD                  S
 5       r#S r$S r%S r&\ RD                  S 5       r'S r( " S S5      r)S r*    SS jr+SS S.S jr,S r-g)    N)uname)Path)parse)_api_pylab_helperscbookft2fontpyplotticker)Figure   )comparable_formatscompare_imagesmake_test_filename)ImageComparisonFailurec               #     #    [         R                  R                  R                  5       n  [        R
                  " 5          [         R                  " 5          S v   S S S 5        S S S 5        [         R                  R                  R                  5         [         R                  R                  R                  U 5        [        R                  " S5        g ! , (       d  f       N~= f! , (       d  f       N= f! [         R                  R                  R                  5         [         R                  R                  R                  U 5        [        R                  " S5        f = f7f)Nall)
matplotlibunitsregistrycopywarningscatch_warnings
rc_contextclearupdatepltclose)orig_units_registrys    W/home/wildlama/miniconda3/lib/python3.13/site-packages/matplotlib/testing/decorators.py_cleanup_cmr!      s     $**3388:$$&
(=(=(? )@& 	!!'')!!(()<=		% )@(?&& 	!!'')!!(()<=		%sN   )E"C6 C%CC%$C6 ,A(E"
C"	C%%
C3/C6 6A)EE"c                     U c  g[        U [        5      (       a  X 4n U  Vs/ s H  n[        U5      PM     n n[        [        R                  5      nU S   Us=:*  =(       a    U S   :*  $ s  $ s  snf )NTr   r   )
isinstancestrparse_versionr	   __freetype_version__)verxfounds      r    _check_freetype_versionr*   #   sm    
{#sj%(
)S=SC
)'667Eq6U$$c!f$$$$ *s   A,c                     SS K nUR                  R                  [        U 5      (       + SU  S[        R
                   S3[        SS9$ )Nr   z/Mismatched version of freetype. Test requires 'z', you have ''F)reasonraisesstrict)pytestmarkxfailr*   r	   r&   r   )required_freetype_versionr0   s     r    _checked_on_freetype_versionr4   /   sW    ;;#$=>>!!: ; <#889< &e  5 5    c                    ^^ U R                  S5        [        R                  " 5       mUU4S jmU R                  5        H  nT" U5        M     g )N c                   > U R                  S5        U R                  R                  T5        U R                  R                  T5        U R                  R                  T5        U R                  R                  T5         U R
                  R                  T5        U R
                  R                  T5        U R                   H  nT" U5        M     g! [         a     N(f = f)z,Remove ticks in *ax* and all its child Axes.r7   N)	set_titlexaxisset_major_formatterset_minor_formatteryaxiszaxisAttributeError
child_axes)axchildnull_formatterremove_tickss     r    rD   -remove_ticks_and_titles.<locals>.remove_ticks<   s    
R
$$^4
$$^4
$$^4
$$^4	HH((8HH((8 ]]E #  		s    6C 
CC)suptitler   NullFormatterget_axes)figurerA   rC   rD   s     @@r    remove_ticks_and_titlesrJ   9   s=    
OOB))+N  ooR  r5   c            	   #   4  #    [         R                  R                  n U R                  5        Vs/ s H  oPM     nn/ n Uv   [	        U R                  5        Vs/ s H  nX;  d  M
  UPM     snS S9nU Vs/ s H  oR
                  R                  PM     snUSS& gs  snf s  snf s  snf ! [	        U R                  5        Vs/ s H  nX;  d  M
  UPM     Os  snf snS S9nU Vs/ s H  oR
                  R                  PM     Os  snf snUSS& f = f7f)z
After::

    with _collect_new_figures() as figs:
        some_code()

the list *figs* contains the figures that have been created during the
execution of ``some_code``, sorted by figure number.
c                     U R                   $ N)num)managers    r    <lambda>&_collect_new_figures.<locals>.<lambda>a   s    '++r5   )keyN)r   GcffigsvaluessortedcanvasrI   )managersrO   preexistingnew_figsnew_managerss        r    _collect_new_figuresr\   N   s     !!&&H*2//*;<*;w7*;K<HJhoo6G >6G7")"<  '6G >"=? =IIL~~,,LI =
> J hoo6G >6G7")"<  '6G >"=? =IIL~~,,LIsb   -DBDB- D	B#'B#-D8B(D-D	CCD)D	DDc                     Sn[        XUSS9nU(       a:  S H&  n[        R                  R                  XE   5      XE'   M(     [	        SU-  5      eg )NT)in_decorator)actualexpecteddiffzEimages not close (RMS %(rms).3f):
	%(actual)s
	%(expected)s
	%(diff)s)r   ospathrelpathr   )r`   r_   tol__tracebackhide__errrR   s         r    _raise_on_image_differencerh   e   s[    
3T
BC
1Cwwsx0CH 2$=@CDE 	E r5   c                   2    \ rS rSrSrS rS rSS.S jrSrg	)
_ImageComparisonBaseq   z
Image comparison base class

This class provides *just* the comparison-related functionality and avoids
any code that would be specific to any testing framework.
c                 d    Xl         [        U5      u  U l        U l        X l        X0l        X@l        g rM   )func_image_directoriesbaseline_dir
result_dirre   remove_textsavefig_kwargs)selfrm   re   rq   rr   s        r    __init___ImageComparisonBase.__init__y   s,    	-?-E*4?&,r5   c                    U R                   U-  nUR                  SU 35      nUS:X  a&  UR                  5       (       d  UR                  S5      n[        U R                  UR
                  -  S5      n [        R                  " [        5         [        R                  " U5        S S S 5         S[        5       R                  R                  5       ;   a  [        e[        R                  S:X  a  [        e[        R                   " XE5        U$ ! , (       d  f       Nm= f! [         a    ["        R$                  " XE5         U$ f = f! [         a  n['        SU SU 35      UeS nAff = f)	N.epsz.pdfr`   	microsoft
emscriptenzMissing baseline image z0 because the following file cannot be accessed: )ro   with_suffixexistsr   rp   name
contextlibsuppressOSErrorrb   remover   releaselowersysplatformsymlinkshutilcopyfiler   )rs   baseline	extensionbaseline_pathorig_expected_pathexpected_fnamerg   s          r    copy_baseline"_ImageComparisonBase.copy_baseline   sF   ))H4*669+G&8&?&?&A&A!3!?!?!G+OO0555zC	2$$W-		.) .D%'//"7"7"99!M<<</!M

->  .-  D 2C D 	2().)9 :6%&() /22	2sO   4E D%E .AD 
DE  E=E  EE 
E%E  E%F_lockc                b   SnU R                   (       a  [        U5        U R                  U-  R                  SU 35      nU R                  R                  5       nUS:X  a  UR                  SS S S S.5        U(       a  [        R                  " U5      O[        R                  " 5       nU    UR                  " U40 UD6  [        R                  " U5        U R                  X#5      n	[        XU R                   5        S S S 5        g ! [        R                  " U5        f = f! , (       d  f       g = f)NTrw   pdfmetadata)CreatorProducerCreationDate)rq   rJ   rp   r{   rr   r   
setdefaultr   
_lock_pathr~   nullcontextsavefigr   r   r   rh   re   )
rs   figr   r   r   rf   actual_pathkwargslockexpected_paths
             r    compare_ImageComparisonBase.compare   s     #C(1>>9+O$$))+j*.D/356
    -(446 	K262 		# ..xCM&}488L T 		# Ts$   *D ,D?=D DD  
D.)ro   rm   rq   rp   rr   re   N)	__name__
__module____qualname____firstlineno____doc__rt   r   r   __static_attributes__ r5   r    rj   rj   q   s"    -4 :? M Mr5   rj   c           	      p   ^ ^^^^^^^^	 SSK m	[        R                  R                  mUU UUU	UUUU4	S jnU$ )z
Decorate function with image comparison for pytest.

This function creates a decorator that wraps a figure-generating function
with image comparison code.
r   Nc                   >	^ ^ [         R                  " T 5      m[        R                  " T 5      T
R                  R                  ST5      [        R                  R                  T5      [        T	5      [        R                  " T 5      UU UU
UUU4S j5       5       5       5       5       n[        TR                  R                  5       5      nSTR                  ;  a  U[         R                  " ST5      /-  nSTR                  ;  a  U[         R                  " ST5      /-  nTR                  US9nX1l        [!        T S/ 5      UR"                  -   nXAl        U$ )Nr   c                   > SnSTR                   ;   a  XS'   STR                   ;   a  XS'   U [        5       ;  a.  SSSSS.R                  U S5      nTR                  S	U  S
U 35        [	        TTTTS9n[
        R                  R                  5         [        5        nT" U0 UD6  S S S 5        [        S UR                  R                  S5       5       5      nTb  Tn	OUR                  S5      n	[        W5      [        U	5      :X  d    S[        U5       S[        U	5       S35       e[        Xy5       H  u  pUR                  XXS9  M     g ! , (       d  f       N= f)NTr   requestz$because ImageMagick is not installedz$because Ghostscript is not installedz!because Inkscape is not installed)gifr   rx   svgzon this systemzCannot compare z files )re   rq   rr   c              3   F   #    U  H  nUR                   S    S:g  v   M     g7f)r   r   N)args).0markers     r    	<genexpr>O_pytest_image_comparison.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>   s%      HFF A+-Fs   !parametrizebaseline_imageszTest generated z images but there are z baseline imagesr   )
parametersr   getskiprj   r   testingset_font_settings_for_testingr\   anynodeiter_markersgetfixturevaluelenzipr   )r   r   r   r   rf   r-   imgrT   
needs_lockour_baseline_imagesr   r   r   rm   old_sigr0   rq   rr   re   s               r    wrapper<_pytest_image_comparison.<locals>.decorator.<locals>.wrapper   s    !%g000&/{#G...$+y! 2 44AAA>	
 #i!12  oi[xHI&t+6DFC<<>%'4d%f% (  H%ll77FH HJ *&5# '.&=&=%''# t9$7 88 ?!#d),B*+,,<>?8 "%T!?C9G "@+ ('s   	E
Er   r   
pytestmark)inspect	signature	functoolswrapsr1   r   r   stylecontextr4   listr   rU   	Parameterreplace__signature__getattrr   )rm   r   r   new_sig	new_marksr   KEYWORD_ONLYr   
extensionsfreetype_versionr0   rq   rr   r   re   s   `    @r    	decorator+_pytest_image_comparison.<locals>.decorator   s/   ##D)				 	 j	9				!	!%	(	%&6	7		*	H *	H 
 
8 
) 
: 

*	HX ',,3356
g0007,,[,GHHJG...7,,YEFFJ//Z/8 ' D,3g6H6HH	&r5   )r0   r   r   r   )
r   r   re   r   rq   rr   r   r   r   r0   s
   ``````` @@r    _pytest_image_comparisonr      s/     $$11LA AF r5   c           
         U b  / [        SU  Vs1 s H  n[        U5      R                  SS iM     sn5      QnU(       aO  Ub  [        S5      e[	        U5      S:  a  [        S5      eUnU  Vs/ s H  n[        U5      R
                  PM     n nUc  / SQnUc
  [        5       nUc  [        R                  " S5        Sn[        R                  S::  a  US	-  n[        XUX4XVS
9$ s  snf s  snf )a  
Compare images generated by the test with those specified in
*baseline_images*, which must correspond, else an `.ImageComparisonFailure`
exception will be raised.

Parameters
----------
baseline_images : list or None
    A list of strings specifying the names of the images generated by
    calls to `.Figure.savefig`.

    If *None*, the test function must use the ``baseline_images`` fixture,
    either as a parameter or with `pytest.mark.usefixtures`. This value is
    only allowed when using pytest.

extensions : None or list of str
    The list of extensions to test, e.g. ``['png', 'pdf']``.

    If *None*, defaults to: png, pdf, and svg.

    When testing a single extension, it can be directly included in the
    names passed to *baseline_images*.  In that case, *extensions* must not
    be set.

    In order to keep the size of the test suite from ballooning, we only
    include the ``svg`` or ``pdf`` outputs if the test is explicitly
    exercising a feature dependent on that backend (see also the
    `check_figures_equal` decorator for that purpose).

tol : float, default: 0
    The RMS threshold above which the test is considered failed.

    Due to expected small differences in floating-point calculations, on
    32-bit systems an additional 0.06 is added to this threshold.

freetype_version : str or tuple
    The expected freetype version or range of versions for this test to
    pass.

remove_text : bool
    Remove the title and tick text from the figure before comparison.  This
    is useful to make the baseline images independent of variations in text
    rendering between different versions of FreeType.

    This does not remove other, more deliberate, text, such as legends and
    annotations.

savefig_kwarg : dict
    Optional arguments that are passed to the savefig method.

style : str, dict, or list
    The style(s) to apply to the image test. The test itself can also apply
    additional styles if desired.

    .. versionchanged:: 3.11
        This defaults to ``['classic', '_classic_test_patch']``, but will be
        changing to ``'mpl20'`` as of Matplotlib 3.13. A warning is raised if not
        explicitly passed.
Nr   z[When including extensions directly in 'baseline_images', 'extensions' cannot be set as wellzaWhen including extensions directly in 'baseline_images', all baselines must share the same suffix)pngr   r   zThe default for the style parameter of image_comparsion() will be changing to "mpl20" in Matplotlib 3.13; explicitly pass style to continue working as before and suppress this warning.)classic_classic_test_patchl        gQ?)r   r   re   r   rq   rr   r   )filterr   suffix
ValueErrorr   stemdictr   warn_externalr   maxsizer   )	r   r   re   r   rq   savefig_kwargr   r   baseline_extss	            r    image_comparisonr     s.   @ "K&8G(I8GH )-X(=(=ab(A8G(I J K% 9: : =!A% ?@ @ 'J4CE4CX##O  E*
};	< 3
{{et#'C)$3 37(IEs   "C#.C()r   )r   re   c                    ^ ^^^ [        [        R                  [        R                  -   S-   5      m[        R
                  R                  mUUU U4S jnU$ )a  
Decorator for test cases that generate and compare two figures.

The decorated function must take two keyword arguments, *fig_test*
and *fig_ref*, and draw the test and reference images on them.
After the function returns, the figures are saved and compared.

This decorator should be preferred over `image_comparison` when possible in
order to keep the size of the test suite from ballooning.

Parameters
----------
extensions : list, default: ["png"]
    The extensions to test. Supported extensions are "png", "pdf", "svg".

    Testing with the one default extension is sufficient if the output is not
    format dependent, e.g. if you test that a ``bar()`` plot yields the same
    result as some manually placed Rectangles. You should use all extensions
    if a renderer property is involved, e.g. correct alpha blending.
tol : float
    The RMS threshold above which the test is considered failed.

Raises
------
RuntimeError
    If any new figures are created (and not subsequently closed) inside
    the test function.

Examples
--------
Check that calling `.Axes.plot` with a single argument plots it against
``[0, 1, 2, ...]``::

    @check_figures_equal()
    def test_plot(fig_test, fig_ref):
        fig_test.subplots().plot([1, 3, 5])
        fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])

z_-[]()c                   >^ ^^	 SS K n[        T 5      u  nm	[        R                  " T 5      mSS1R	                  TR
                  5      (       d  [        ST 35      eUR                  R                  ST5      U
U UU	U4S j5       nTR
                  R                  5        Vs/ s H  nUR                  S;  d  M  UPM     nnSTR
                  ;  a  U[        R                  " ST5      /-  nSTR
                  ;  a  U[        R                  " ST5      /-  nTR                  US	9nXcl        [        T S
/ 5      UR                  -   nXsl        U$ s  snf )Nr   fig_testfig_refzwThe decorated function must have at least the parameters 'fig_test' and 'fig_ref', but your function has the signature extc                   > STR                   ;   a  XS'   STR                   ;   a  XS'   SR                  U	4S jUR                  R                   5       5      n[	        5       n[	        5       nT
" X%US.UD6  [        UR                  5       5      S:X  a(  [        UR                  5       5      S:X  a  [        S5      eTUS-   U -   -  nTUS	-   U -   -  nUR                  U5        UR                  U5        [        XTS
9  g )Nr   r   r7   c              3   8   >#    U  H  nUT;   d  M  Uv   M     g 7frM   r   )r   cALLOWED_CHARSs     r    r   Jcheck_figures_equal.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>  s"       7+<a#$#5 !"+<s   
	)r   r   r   zKBoth figures are empty.  Make sure you are plotting to fig_test or fig_ref.rw   z
-expected.)re   )
r   joinr   r}   r   r   get_childrenRuntimeErrorr   rh   )r   r   r   r   	file_namer   r   test_image_pathref_image_pathr   rm   r   rp   re   s            r    r   7check_figures_equal.<locals>.decorator.<locals>.wrapper  s    *** #uG...$+y!  77<<+<+<  7 7IxHhG$7EfE8((*+q0S9M9M9O5PTU5U" $F G G )IOc,ABO'9|+Cc+IJN_-OON+&Sr5   >   r   r   r   r   r   )r0   rn   r   r   issubsetr   r   r1   r   rU   r}   r   r   r   r   r   )rm   r0   _r   paramr   r   r   r   rp   r   r   r   re   s   `       @@r    r   &check_figures_equal.<locals>.decorator  sZ   *40:##D)I&//0B0BCC ;;B)E F F 
	 	 
	3	 	 
4	4 !++224
4zz!88 4 	 

 ***7,,ULABBJG...7,,YEFFJ//Z/8 ' D,3g6H6HH	&#
s   "E:E)setstringdigitsascii_lettersr   r   r   )r   re   r   r   r   s   `` @@r    check_figures_equalr  j  sH    P (<(<<xGHM$$11L5 5n r5   c                     [        [        R                  " U 5      5      nUR                  S-  UR                  -  n[        5       R                  5       S-  UR                  -  nUR                  SSS9  X#4$ )a%  
Compute the baseline and result image directories for testing *func*.

For test module ``foo.bar.test_baz``, the baseline directory is at
``foo/bar/baseline_images/test_baz`` and the result directory at
``$(pwd)/result_images/test_baz``.  The result directory is created if it
doesn't exist.
r   result_imagesT)parentsexist_ok)r   r   getfileparentr   resolvemkdir)rm   module_pathro   rp   s       r    rn   rn     sm     wt,-K%%(99K<L<LLL!O3k6F6FFJTD1##r5   )Nr   NFNN).r~   r   r   rb   r   r   pathlibr   r   r  r   r   packaging.versionr   r%   matplotlib.styler   matplotlib.unitsmatplotlib.testingr   r   r   r	   r
   r   r   matplotlib.figurer   r   r   r   r   
exceptionsr   contextmanagerr!   r*   r4   rJ   r\   rh   rj   r   r   r  rn   r   r5   r    <module>r     s       	     
  4    R R $ K K .  	%5* J J,	E@M @MFPf <=8=#'`3F '0Q bJ$r5   