o
    li)                     @   s  d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZ d dl
Zd dlm Z d dlm Z! d dl"m#Z$ e	j%j&d
de	j%'dddge	j%j'dddi fddddifddddifddddifddi fddddifddddifgg dddd Z(dd Z)eedd  Z*ed!gd"d# Z+eed!gd$d% Z,d&d' Z-ed(d) Z.ed*d+ Z/ed,d- Z0ed.gd/d0 Z1ed1gd2d3 Z2ed4gd5d6 Z3edgd7d8d9 Z4ed:d; Z5ed<gd=d>d?d@ Z6e	j%'dAdBdCgdDdE Z7dFdG Z8dHdI Z9dJdK Z:edLgdMdNdOdP Z;edQgdRdNdSdT Z<edUgdVdW Z=edXgdYdZid=d[d\d] Z>dS )^    )Counter)PathN)cbookpathpatheffectsfont_manager)MatplotlibDeprecationWarning)Figure)Ellipse)needs_ghostscriptneeds_usetex)check_figures_equalimage_comparison   )rerunsorientationportrait	landscapezformat, use_log, rcParamspsFps.usedistillerghostscriptxpdftext.usetexTeps	ps.useafm)r   zps with distiller=ghostscriptzps with distiller=xpdfzps with usetexr   zeps afmzeps with usetex)idsc                 C   s  t j| t \}}t }t }|r|d |	ddgddg d}t jd s2|d7 }|
| g }	|drD|	t j |drN|	t |drX|	t z|j|| |d	 |j|| |d	 W n t|	y }
 ztt|
 W Y d }
~
nd }
~
ww |jrJ |jrJ | d
}| }tdd|}tdd|}||ddksJ W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nlog      u	   Déjà vur   u    −€r   r   )formatr   asciis   (?<=
%%CreationDate: ).*    s   
   
)mplrcParamsupdatepltsubplotsioStringIOBytesIO
set_yscaleplot	set_titlegetappendExecutableNotFoundErrorRuntimeErrorr   savefigtuplepytestskipstrclosedgetvalueencoderesubreplace)r   use_logr$   r   figaxs_bufb_buftitleallowable_exceptionsexcs_valb_val rG   ^/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/matplotlib/tests/test_backend_ps.pytest_savefig_to_stringio   s@   









PrI   c                  C   sl   t jdddgtjd< t \} }|g d t }| j	|dd W d    d S 1 s/w   Y  d S )N   w)	linewidth
foregroundzpath.effects)r   r   r   r   r   )
r   
withStroker#   r$   r&   r'   r,   r(   r*   r2   )r>   r?   r   rG   rG   rH   test_patheffectsT   s   

"rP   c                 C   s~   t | d}|  tjtt|d# dtjd< t	g d t
d tj|d dd	 W d    d S 1 s8w   Y  d S )
Nzshort-1)tempdirTr   )r   r   r   rJ   z\textbf{time} (s)ztex_demo.epsr   rN   )r   mkdirr   _setattr_cmtempfiler6   r#   r$   r&   r,   xlabelr2   )tmpdirbase_tempdirrG   rG   rH   test_tilde_in_tempfilename]   s   


"rX   z	empty.epsc                  C   s@   t  \} }|  |jddgddd |jdddddd d S )Nr   r   rcoloralpha      ?foo)r&   r'   set_axis_offr,   textr>   r?   rG   rG   rH   test_transparencyp   s   rb   c                  C   sJ   dt jd< t \} }|  |jddgddd |jdddddd d S )	NTr   r   r   rY   rZ   r]   r^   )r#   r$   r&   r'   r_   r,   r`   ra   rG   rG   rH   test_transparency_texx   s
   
rc   c                  C   s   t  \} }t }| j|dd | }W d    n1 s w   Y  td|tj}|s1J td|tj}|s=J t	ddD ]}d|
|vsMJ t|
|tt|
|dksaJ qBd S )Nr   rN   s$   ^%%BoundingBox: (.+) (.+) (.+) (.+)$s)   ^%%HiResBoundingBox: (.+) (.+) (.+) (.+)$r         .)r&   r'   r(   r*   r2   r8   r:   search	MULTILINErangegroupintr4   approxfloat)r>   r?   bufbbhibbirG   rG   rH   	test_bbox   s   

*rq   c                   C   sV   dt jd< td tt tjt	 dd W d   dS 1 s$w   Y  dS )z"Test failing latex subprocess callTr   z$22_2_2$r   rN   N)
r#   r$   r&   rU   r4   raisesr1   r2   r(   r*   rG   rG   rG   rH   test_failing_latex   s
   

"rs   c                 C   s\   |  d tjddddd tjddddd tjt dd	 | j\}d
| v s,J d S )NWARNING皙?r^   T)usetex皙?barr   rN   zas if usetex=False)	set_levelr&   figtextr2   r(   r*   records
getMessage)caplogrecordrG   rG   rH   test_partial_usetex   s   
r   c                 C   s6   t jddd tddd tjt dd d S )NTz$\usepackage{color,graphicx,textcomp})r   ztext.latex.preambler]   r^   r   rN   )r#   r$   r%   r&   rz   r2   r(   r*   )r}   rG   rG   rH   test_usetex_preamble   s   r   z
useafm.epsc                  C   s:   dt jd< t \} }|  |d |ddd d S )NTr   r]   qk)r#   r$   r&   r'   r_   axhliner`   ra   rG   rG   rH   test_useafm   s
   

r   z	type3.epsc                   C   s   t ddd d S )Nr]   zI/J)r&   rz   rG   rG   rG   rH   test_type3_font   s   r   zcoloredhatcheszerolw.epsc                  C   sh   t  } | tdddddddd | tdd	d	d
dddd | tdddddddd |   d S )N)r   r   r   /nonerY   r   )hatch	facecolor	edgecolorrL   )r]   r]   r]   +grw   )r   r   g333333?g?\b)r&   gca	add_patchr
   r_   )r?   rG   rG   rH   !test_colored_hatch_zero_linewidth   s   r   )
extensionsc                 C   s*   |   }|jddd| jdd |   d S )Nr   helloT)	transformclip_on)add_subplotr`   transFigure)fig_testfig_refr?   rG   rG   rH   test_text_clip   s   r   c                 C   s>   t  }|ddd | d }|| tjjj|dd d S )Nr]   defztest.epsF)cache)r&   figurer`   r2   r#   testingcompareconvert)tmp_pathr>   outrG   rG   rH   test_d_glyph   s
   
r   ztype42_without_prep.epsmpl20)stylec                   C   s&   dt jd< dt jd< tddd d S )N*   ps.fonttypestixzmathtext.fontsetr]   zMass $m$)r#   r$   r&   rz   rG   rG   rG   rH   test_type42_font_without_prep   s   

r   fonttype342c                 C   sl   | t jd< t \}}|ddd t }|j|dd dt|  dd	 d
 }t	
|| t	js4J d S )Nr   g      ?r]   z&Forty-two is the answer to everything!r   rN   s
   /FontType zutf-8)encodings    def)r#   r$   r&   r'   r`   r(   r*   r2   bytesr:   rf   r8   rg   )r   r>   r?   rm   testrG   rG   rH   test_fonttype   s   
r   c                  C   sH   t  \} }|jddgdd t }| j|dd | dks"J dS )z-Test that dashed lines do not break PS outputr   r   z--)	linestyler   rN   N)r&   r'   r,   r(   r*   r2   tell)r>   r?   rm   rG   rG   rH   test_linedash   s
   r   c                  C   s<   t  } | ddd t }| j|dd | j|dd d S )Nr]   z
foo

r   rN   r   )r	   r`   r(   r*   r2   )r   rm   rG   rG   rH   test_empty_line  s
   r   c                  C   s   t  } | jddtddd}|jD ]}|jg g d |ddg q| d t }| j	|d	d
 |
d dd | D }tt| dksLJ d S )NrJ   polar)
projection)
subplot_kw)xticksyticksr   r   zhello, worldr   rN   r   c                 S   s$   g | ]}| d r|dd qS )r    r   )
startswith	partition).0lnrG   rG   rH   
<listcomp>  s    z0test_no_duplicate_definition.<locals>.<listcomp>)r	   r'   dictflatsetr,   suptitler(   r)   r2   seek	readlinesmaxr   values)r>   axsr?   rm   wdsrG   rG   rH   test_no_duplicate_definition  s   


r   zmulti_font_type3.epsgRQ?)tolc                  C   h   t jdgd} tt | jdkrtd tjdddgdd tjd	d
d t	 }|
ddd d S )NWenQuanYi Zen Heifamilywqy-zenhei.ttcFont may be missingfontDejaVu Sans   r   sizer   r   r   333333?ffffff?"   There are 几个汉字 in between!fmFontPropertiesr   findfontnamer4   r5   r&   rcr   r`   fpr>   rG   rG   rH   test_multi_font_type3!     
r   zmulti_font_type42.epsg?c                  C   r   )Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rG   rG   rH   test_multi_font_type42.  r   r   zscatter.epsc            	      C   s   t jd} | ddd}| ddd}| ddd}t \}}|j|||g ddd	 |  d
d tddD }| ddd	dd}ddg}t
j||dd|d}|| |dd d S )Ni!N,r   r   
      d   )g?rw   ru   <)r   markerc                 S   s   g | ]}t j|qS rG   )r   r   unit_regular_polygon)r   rp   rG   rG   rH   r   D  s    z(test_path_collection.<locals>.<listcomp>r            r   g{Gz?g{Gz?yellow)zorder
facecolorsoffsets)nprandomdefault_rnguniformr&   r'   scatterr_   rh   reshapemcollectionsPathCollectionadd_collectionset_xlim)	rngxvalsyvalssizesr>   r?   pathsr   pcrG   rG   rH   test_path_collection;  s   

r  zcolorbar_shift.epsbbox_inchestight)savefig_kwargr   c                 C   sL   t g d}t g d|j}tjddgddgddg||d t  d S )N)rY   r   r   )r   g      r]   r   r   r   )ccmapnorm)mcolorsListedColormapBoundaryNormNr&   r   colorbar)r   r  r	  rG   rG   rH   test_colorbar_shiftM  s    r  )?collectionsr   pathlibr   r(   r:   rT   numpyr   r4   
matplotlibr   r   r   r   r   matplotlib._apir   matplotlib.figurer	   matplotlib.patchesr
   matplotlib.testing._markersr   r   matplotlib.testing.decoratorsr   r   r#   matplotlib.collectionsr   matplotlib.colorscolorsr
  matplotlib.pyplotpyplotr&   markflakyparametrizerI   rP   rX   rb   rc   rq   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  rG   rG   rG   rH   <module>   s    *	

	
	










	


