o
    li.                     @   sf  d dl Z d dlm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Zd dlmZ d dlmZmZ d dlmZmZ d dlmZmZ d dlmZmZmZ d dlmZmZm Z m!Z! ed	d
 \Z"Z#i d fddZ$e
j%&dg ddd Z'e!e
j%(ddd Z)dd Z*e!e
j%(dedgdddd Z+ze,dj-e	dk Z.W n ej/y   dZ.Y nw e e
j%j0ed dd e
j%(ded!gde.rd"nd d#d$d% Z1e!e ej23de
j%(dd&d' Z4e!ej23de
j%(dd(d) Z5e!e
j%(ded*gddd+d, Z6e!ej23de
j%(dd-d. Z7ej23de
j%(de
j%&d/e
j8d0egd1e
j8d2e gd1e
j8d3e!gd1gd4d5 Z9ej23de
j%(de
j%&d/e
j8d0egd1e
j8d2e gd1e
j8d3e!gd1gd6d7 Z:e!d8d9 Z;e!d:d; Z<e!ed<d= Z=e!d>d? Z>ed@gdAe
j%&dBdCe
j%(ddDdE Z?e
j%(ddFdG Z@dS )H    N)BytesIO)parse)_has_tex_package_check_for_pgf)compare_imagesImageComparisonFailure)PdfPages_tex_escape)_image_directoriescheck_figures_equalimage_comparison)needs_ghostscriptneeds_pgf_lualatexneeds_pgf_pdflatexneeds_pgf_xelatexc                   C   s   dS )Nz
dummy func r   r   r   _/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/matplotlib/tests/test_backend_pgf.py<lambda>   s    r   c                 C   sf   t jt| }tj|fi | t jtd|  }tt jt| | t	|||d}|r1t
|d S )Nzexpected_%stol)ospathjoin
result_dirpltsavefigshutilcopyfilebaseline_dirr   r   )fnamesavefig_kwargsr   actualexpectederrr   r   r   compare_figure   s   r$   zplain_text, escaped_text))zquad_sum: $\sum x_i^2$z&quad_sum: \(\displaystyle \sum x_i^2\))z% not a commentz\% not a comment)z^notz\^notc                 C   s   t | |ksJ d S )N)r	   )
plain_textescaped_textr   r   r   test_tex_escape$   s   r'   pgfc                 C   s(   t  }|ddd || d  d S )N      ?z
_^ $a_b^c$ztest.pdf)r   figuretextr   )tmp_pathfigr   r   r   test_tex_special_chars-   s   r.   c                  C   s   t   tddd} t | | d d t | d| d  d t jddgddgd	d
dd t g dg dd t jdgdgddd t jdddddd t jdddd t 	dd t 
dd d S )Nr            zb-zg>        g?z//	lightgrayred)hatch	facecolor	edgecolor)   r8   皙?r9   r8   )r1   r:   r   r1   bg?r)   ror8   )
markersizeu/   unicode (ü, °, §) and math ($\mu_i = x_i^2$)right   )hafontsizez*sans-serif, blue, $\frac{\sqrt{x}}{y^2}$..
sans-serifblue)familycolor)r   r*   nplinspaceplotfill_betweenfillr+   ylabelxlimylim)xr   r   r   create_figure5   s"   
rO   zpgf_xelatex.pdfdefault)stylec                  C   s    ddd} t j|  t  d S )NserifFfont.familypgf.rcfonts)mplrcParamsupdaterO   )
rc_xelatexr   r   r   test_xelatexP   s
   
rZ   gsz9.50Tucszneeds ucs.sty)reasonzpgf_pdflatex.pdfgffffff'@)rQ   r   c                  C   s:   t jdrtd ddddd} tj|  t  d S )NAPPVEYORzBpdflatex test does not work on appveyor due to missing LaTeX fontsrR   Fpdflatexz4\usepackage[utf8x]{inputenc}\usepackage[T1]{fontenc})rT   rU   pgf.texsystempgf.preamble)	r   environgetpytestxfailrV   rW   rX   rO   )rc_pdflatexr   r   r   test_pdflatexb   s   

rg   c               	   C   s   dddddddddd	d
ddddg} t rddgnddg}t| D ]E\}}t|4 dD ]\}}|tjd v rEt|sEtd| d q-t  t	d|d  d|| d W d    n1 saw   Y  q!d S )NrB      g?
   Fxelatex)rT   	font.sizefigure.subplot.leftlines.markersizerU   r`   	monospaceg?r?   r_   zG\usepackage[utf8x]{inputenc}\usepackage[T1]{fontenc}\usepackage{sfmath})rT   rk   rl   rm   rU   r`   ra   r   gffffff*@))sfmathro   )utf8xr\   ra   zneeds z.stypgf_rcupdater/   .pdfr   )
_old_gs_version	enumeraterV   
rc_contextrW   r   rd   skiprO   r$   )rc_setsr   irc_set	substringpkgr   r   r   test_rcupdatev   s<   r|   c                  C   s   t jd tjddd tdd\} }|d dd	gdd	g |d 	dd |d 
dd |d ddgddg |d jt jjd
ddddgd |d d | jt dd d S )Ni!N,rR   FrS   r/   r1   r   r2   g}Ô%ITi  )sizer?   iri   )binsrangelogpdfformat)rF   randomseedrV   rW   rX   r   subplotsrH   set_xlimset_ylimscatterhistnormal
set_xscaler   r   )r-   axsr   r   r   test_pathclip   s   "r   zpgf_mixedmode.pdfc                  C   sP   t jddd tjddddddf \} }t|d | d  d d S )	NrR   FrS   r/   y              D@r1   T)rV   rW   rX   rF   ogridr   pcolorset_rasterized)YXr   r   r   test_mixedmode   s    r   c                  C   st   t jddd tdd\} \}}|td |td t  | 	| j
 }tdd|id	d
 d S )NrR   FrS   r/   r1      zpgf_bbox_inches.pdfbbox_inchesr   )r    r   )rV   rW   rX   r   r   rH   r   tight_layoutget_window_extenttransformeddpi_scale_transinvertedr$   )r-   ax1ax2bboxr   r   r   test_bbox_inches   s   

r   systemlualatex)marksr_   rj   c           	      C   s  dd| d}t j| t \}}|td |  tjdd\}}|td |  tj	
td|  d}d	d
ddtjdddttdddd}t||d }|| || || | dksoJ W d    d S 1 szw   Y  d S )NrR   F)rT   rU   r`   r   )r8   r1   figsize	pdfpages_rr   meMultipage PDF with pgf	Test pagetest,pdf,multipage     r/   r   tzinfoUnknownAuthorTitleSubjectKeywordsModDateTrappedmetadatar8   )rV   rW   rX   r   r   rH   r   r   r   r   r   r   datetimetimezone	timedeltar   r   get_pagecount)	r   rf   fig1r   fig2r   r   mdr   r   r   r   test_pdf_pages   s6   	



"r   c           
      C   sn  t d}| dd tjd|i t \}}|t	d dddd	t
j
d
ddt
t
dddd}tjtd| d}t||d}|| W d    n1 sWw   Y  |j|}dd |j D }W d    n1 sww   Y  d|v r|d= d|v r|d= |d}	|	dtj ks|dkrd|	v sJ |dddtj dd	dddd d!ksJ d S )"NpikepdfSOURCE_DATE_EPOCH0r`   r   r   r   r   r   r   r   r/   r   r   Truer   pdfpages_meta_check_rr   r   c                 S   s   i | ]	\}}|t |qS r   )str).0kvr   r   r   
<dictcomp>  s    z1test_pdf_pages_metadata_check.<locals>.<dictcomp>z/PTEX.FullBannerz/PTEX.Fullbannerz	/ProducerzMatplotlib pgf backend vr   LuaTeXzD:19700101000000ZzMatplotlib vz, https://matplotlib.orgzD:19680801000000Zz/True)z/Authorz/CreationDatez/Creatorz	/Keywordsz/ModDatez/Subjectz/Titlez/Trapped)rd   importorskipsetenvrV   rW   rX   r   r   rH   r   r   r   r   r   r   r   r   r   r   Pdfopendocinfoitemspop__version__)
monkeypatchr   r   r-   axr   r   r   infoproducerr   r   r   test_pdf_pages_metadata_check   sL   

	
r   c                  C   sr   t  } | d tt | jt dd W d    n1 s!w   Y  t  } | d | jt dd d S )Nz\oopsr(   r   z
this is ok)r   r*   suptitlerd   raises
ValueErrorr   r   )r-   r   r   r   test_tex_restart_after_error%  s   

r   c                  C   s:   t  \} }|ddgddgg | jt dddd d S )	Nr   r/   r1   r8   r   r(   tight)r   backendr   )r   r   imshowr   r   )r-   r   r   r   r   test_bbox_inches_tight1  s   r   c                  C   sH   t  } t j| dddd | d t| }|d dk s"J d S )Npngr(   T)r   r   transparentr   ).r8   )r   r   r*   r   seekimreadall)buftr   r   r   test_png_transparency8  s
   

r   c                 C   sn   |  d dtjd< tddd tjt dd W d    n1 s$w   Y  dd	d
 | jD v s5J d S )NWARNINGzthis-font-does-not-existrT   r)   zhello, worldr(   r   z/Ignoring unknown font: this-font-does-not-existc                 S   s   g | ]}|  qS r   )
getMessage)r   rr   r   r   
<listcomp>H  s    z%test_unknown_font.<locals>.<listcomp>)at_levelrV   rW   r   figtextr   r   records)caplogr   r   r   test_unknown_fontB  s   
r   r   )
extensions	texsystem)r_   rj   r   c                 C   s@   t |st|d  |tjd< | ddd |ddd d S )Nz + pgf is requiredr`   r)   z$-1$u   $−1$)r   rd   rv   rV   rW   r+   )fig_testfig_refr   r   r   r   test_minus_signs_with_texL  s
   
r   c                  C   s   t jdd\} }|g  |g  |d |ddg\}|jdddd	 t }| j|d
d |	 
 }W d    n1 sBw   Y  d}||v sOJ d S )N)r8   r8   r   Fr   r/   r   rh   *   )scalelength
randomnessr(   r   aR  \pgfpathmoveto{\pgfqpoint{0.375000in}{0.300000in}}%
\pgfpathlineto{\pgfqpoint{2.700000in}{2.700000in}}%
\usepgfmodule{decorations}%
\usepgflibrary{decorations.pathmorphing}%
\pgfkeys{/pgf/decoration/.cd, segment length = 0.150000in, amplitude = 0.100000in}%
\pgfmathsetseed{42}%
\pgfdecoratecurrentpath{random steps}%
\pgfusepath{stroke}%)r   r   
set_xticks
set_yticksset_frame_onrH   set_sketch_paramsr   r   getvaluedecode)r-   r   handlefdr   baseliner   r   r   test_sketch_paramsW  s   


r  )Ar   ior   r   r   numpyrF   packaging.versionr   parse_versionrd   
matplotlibrV   matplotlib.pyplotpyplotr   matplotlib.testingr   r   matplotlib.testing.comparer   r   matplotlib.backends.backend_pgfr   r	   matplotlib.testing.decoratorsr
   r   r   matplotlib.testing._markersr   r   r   r   r   r   r$   markparametrizer'   r   r.   rO   rZ   _get_executable_infoversionrs   ExecutableNotFoundErrorskipifrg   rQ   contextr|   r   r   r   paramr   r   r   r   r   r   r   r  r   r   r   r   <module>   s    














#
2



	

