
    hfF                     ^   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  SSKJrJrJr  SSKJr  \ R>                  S	 5       r S
 r!S r"S r#\ R>                  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)_pylab_helperscbookft2fontpyplotticker   )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    O/var/www/html/env/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_versionr.   s     r   _checked_on_freetype_versionr2   .   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.r5   N)	set_titlexaxisset_major_formatterset_minor_formatteryaxiszaxisAttributeError
child_axes)axchildnull_formatterremove_tickss     r   rB   -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)figurer?   rA   rB   s     @@r   remove_ticks_and_titlesrH   8   s=    
OOB))+N  ooR  r3   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>`   s    '++r3   )keyN)r   GcffigsvaluessortedcanvasrG   )managersrM   preexistingnew_figsnew_managerss        r   _collect_new_figuresrZ   M   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__errrP   s         r   _raise_on_image_differencerf   d   s[    
3T
BC
1Cwwsx0CH 2$=@CDE 	E r3   c                   2    \ rS rSrSrS rS rSS.S jrSrg	)
_ImageComparisonBasep   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 rK   )func_image_directoriesbaseline_dir
result_dirrc   remove_textsavefig_kwargs)selfrk   rc   ro   rp   s        r   __init___ImageComparisonBase.__init__x   s,    	-?-E*4?&,r3   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                  " XE5        U$ ! , (       d  f       NS= 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^   	microsoftzMissing baseline image z0 because the following file cannot be accessed: )rm   with_suffixexistsr   rn   name
contextlibsuppressOSErrorr`   remover   releaselowersymlinkshutilcopyfiler   )rq   baseline	extensionbaseline_pathorig_expected_pathexpected_fnamere   s          r   copy_baseline"_ImageComparisonBase.copy_baseline   s5   ))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

->  .-  D 2C D 	2().)9 :6%&() /22	2sO   4D* C2%D* .AD 2
D <D*  D'#D* &D''D* *
E4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)NTru   pdfmetadata)CreatorProducerCreationDate)ro   rH   rn   rx   rp   r   
setdefaultr   
_lock_pathr{   nullcontextsavefigr   r   r   rf   rc   )
rq   figr   r   r   rd   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.)rm   rk   ro   rn   rp   rc   N)	__name__
__module____qualname____firstlineno____doc__rr   r   r   __static_attributes__ r3   r   rh   rh   p   s"    -0 :? M Mr3   rh   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.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 Ghostscript is not installedz!because Inkscape is not installed)r   rv   svgzon this systemzCannot compare z files )rc   ro   rp   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skiprh   r   testingset_font_settings_for_testingrZ   anynodeiter_markersgetfixturevaluelenzipr   )r   r   r   r   rd   r+   imgrR   
needs_lockour_baseline_imagesr   r   r   rk   old_sigr.   ro   rp   rc   s               r   wrapper<_pytest_image_comparison.<locals>.decorator.<locals>.wrapper   s    !%g000&/{#G...$+y! 2 44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wrapsr/   r   r   stylecontextr2   listr   rS   	Parameterreplace__signature__getattrr   )rk   r   r   new_sig	new_marksr   KEYWORD_ONLYr   
extensionsfreetype_versionr.   ro   rp   r   rc   s   `    @r   	decorator+_pytest_image_comparison.<locals>.decorator   s/   ##D)				 	 j	9				!	!%	(	%&6	7		)	H )	H 
 
8 
) 
: 

)	HV ',,3356
g0007,,[,GHHJG...7,,YEFFJ//Z/8 ' D,3g6H6HH	&r3   )r.   r   r   r   )
r   r   rc   r   ro   rp   r   r   r   r.   s
   ``````` @@r   _pytest_image_comparisonr      s/     $$11L@ @D r3   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[        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 all supported extensions: 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 optional style(s) to apply to the image test. The test itself
    can also apply additional styles if desired. Defaults to ``["classic",
    "_classic_test_patch"]``.
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   l        gQ?)r   r   rc   r   ro   rp   r   )
filterr   suffix
ValueErrorr   stemdictsysmaxsizer   )	r   r   rc   r   ro   savefig_kwargr   r   baseline_extss	            r   image_comparisonr     s   z "K&8G(I8GH )-X(=(=ab(A8G(I J K% 9: : =!A% ?@ @ 'J4CE4CX##O  E*

{{et#'C)$3 3+(IEs   "C.Cr   )r   rc   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", "pdf", "svg"]
    The extensions to test.
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 [        R
                  " S5      n[        R
                  " S5      n[        5        nT" X%US.UD6  S S S 5        W(       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  [        R                  " U5        [        R                  " U5        g ! , (       d  f       N= f! [        R                  " W5        [        R                  " W5        f = f)Nr   r   r5   c              3   8   >#    U  H  nUT;   d  M  Uv   M     g 7frK   r   )r   cALLOWED_CHARSs     r   r   Jcheck_figures_equal.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>  s"       7+<a#$#5 !"+<s   
	test	reference)r   r   zNumber of open figures changed during test. Make sure you are plotting to fig_test or fig_ref, or if this is deliberate explicitly close the new figure(s) inside the test.ru   z
-expected.)rc   )r   joinr   rz   r   rG   rZ   RuntimeErrorr   rf   r   )r   r   r   r   	file_namer   r   rR   test_image_pathref_image_pathr   rk   r   rn   rc   s             r   r   7check_figures_equal.<locals>.decorator.<locals>.wrapper  s5   *** #uG...$+y!  77<<+<+<  7 7I#::f-**[1)+t$7MfM ,& (H I I
 #-	C#0E"F!+y</G#/M!N  1/*" 		(#		'"# ,+  		(#		'"s%   6D5 D$AD5 $
D2.D5 5.E#>   r   r   r   r   r   )r.   rl   r   r   issubsetr   r   r/   r   rS   rz   r   r   r   r   r   )rk   r.   _r   paramr   r   r   r   rn   r   r   r   rc   s   `       @@r   r   &check_figures_equal.<locals>.decorator  s[   *40:##D)I&//0B0BCC ;;B)E F F 
	 	 
	3	# 	# 
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   rc   r   r   r   s   `` @@r   check_figures_equalr   ]  sH    F (<(<<xGHM$$11L; ;z r3   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)rk   module_pathrm   rn   s       r   rl   rl     sm     wt,-K%%(99K<L<LLL!O3k6F6FFJTD1##r3   )Nr   NFN)classic_classic_test_patch)+r{   r   r   r`   platformr   pathlibr   r   r   r   r   packaging.versionr   r#   matplotlib.styler   matplotlib.unitsmatplotlib.testingr   r   r   r	   r   r
   r   r   r   r   
exceptionsr   contextmanagerr   r(   r2   rH   rZ   rf   rh   r   r   r   rl   r   r3   r   <module>r     s       	     
  4    L L K K .  	%5* J J,	E>M >MBOd <=8=#'=	W3t '< cL$r3   