U
    jg                     @   s>  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m	Z	 d dl
mZmZ d dlmZ d dlmZ eZedgdd	gd
ddd Ze dd Ze dd Zdd Zedgdd Zejddddgdd Zejdddgdd  Zejd!d"d#gd$d% Zd&d' Zejjd(d)ejd*dd+gd,d- ZdS ).    )TemporaryFileN)dviread)_has_tex_package)check_figures_equalimage_comparison)needs_usetextest_usetexZpdfZpngmpl20)Zbaseline_images
extensionsstylec                  C   s   dt jd< t \} }ddtddddd	}|jd| |jd| |jd| |jd| |jd| dd |jD D ]}|| qxdd |jD D ]}|| q|	  d S )NTtext.usetexZbaseline   r   knone)padZ	edgecolorZ	facecolor)verticalalignmentsizeZbbox皙?ffffff?O\LaTeX\ $\left[\int\limits_e^{2e}\sqrt\frac{\log^3 x}{x}\,\mathrm{d}x \right\}$333333?lg皙?$\frac{1}{2}\pi$333333?	$p^{3^A}$皙?	$p_{3_2}$c                 S   s   h | ]}|  d  qS )r   get_position.0t r#   @/tmp/pip-unpacked-wheel-g2o_nghe/matplotlib/tests/test_usetex.py	<setcomp>%   s     ztest_usetex.<locals>.<setcomp>c                 S   s   h | ]}|  d  qS    r   r    r#   r#   r$   r%   '   s     )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )
mplrcParamspltsubplotsdicttextZtextsZaxvlineZaxhlineZset_axis_off)figaxkwargsxyr#   r#   r$   r      s&    
 c                 C   s   dt jd< | ddd d S )NTr         ?z% a commentr(   r)   r-   Zfig_testZfig_refr#   r#   r$   
test_empty,   s    
r6   c                 C   s*   dt jd< | ddd |ddd d S )NTr   r3   z$-$u   −r4   r5   r#   r#   r$   test_unicode_minus2   s    
r7   c                  C   s:   dt jd< t  } |  dd dtjd< | j  d S )NTzaxes.formatter.use_mathtextr'   r   )r*   r)   figureZadd_subplotZset_xlimr(   canvasdraw)r.   r#   r#   r$   test_mathdefault9   s
    

r<   zeqnarray.pngc                  C   s*   d} t jdd}|jdd| dddd d S )Nz/\begin{eqnarray*}foo\\bar\\baz\\\end{eqnarray*})r'   r'   )Zfigsizer3   Tcenter)usetexZhorizontalalignmentr   )r*   r9   r-   )r-   r.   r#   r#   r$   test_multiline_eqnarrayC   s     r?   fontsize   
      c                 C   s   t jd | t jd< i }t }dD ]b}|  |D ]}|jddd| ddd q6|j	  t
|j d d	kjd
d ||< q&t| d
kstd S )Nr	   z	font.size)r&   )r8   )r8   r'   r3   $Tr>   ).r      r'   )Zaxis)r(   r   Zuser)   r*   r9   clearr-   r:   r;   nparrayZbuffer_rgbaanysumlenvaluesAssertionError)r@   Zheightsr.   valsr1   r#   r#   r$   test_minus_no_descentR   s    

rP   pkgZxcolorZchemformulac                 C   s   t | st|  d dtjd< t }|ddd}|j	  d|  tjd< t }|ddd}|j	  t
j| |  d S )Nz is not availableTr   r3   zSome text 0123456789z8\PassOptionsToPackage{dvipsnames}{xcolor}\usepackage{%s}text.latex.preamble)r   pytestskipr(   r)   r*   r9   r-   r:   r;   rH   ZtestingZassert_array_equalZget_window_extent)rQ   r.   r-   Ztext2r#   r#   r$   test_usetex_packagesf   s    


rU   preamblez\usepackage[full]{textcomp}z\usepackage{underscore}c                 C   s2   | t jd< t  }|jddddd |j  d S )NrR   r3   zhello, worldTrE   )r*   r)   r9   r-   r:   r;   )rV   r.   r#   r#   r$   test_latex_pkg_already_loadedy   s    
rW   c                  C   sh   dt jd< tdd d d tdd} t  \}}|jdd| d |  |jd	d	d
dd t   d S )NTr      r8   )a_bcrZ   rY   )datar   Zfoo_barrE   )r*   r)   ranger+   ZplotZlegendr-   r;   )Zdfr.   r/   r#   r#   r$   test_usetex_with_underscore   s    
r]      )Zrerunsfmtsvgc              
   C   sr   | tjddd  dtjd< t \}}|ddd t *}t	
t |j|| d W 5 Q R X W 5 Q R X d	S )
z:An error is raised if a TeX font lacks a Type-1 equivalent__getitem__c                 S   s   t jddd d d dS )Ns   texfonts	   Some Font)ZtexnameZpsnameZeffectsencodingfilename)r   ZPsFont)selfr   r#   r#   r$   <lambda>   s      z%test_missing_psfont.<locals>.<lambda>Tr   r3   Zhello)formatN)setattrr   Z
PsfontsMapr(   r)   r*   r+   r-   r   rS   Zraises
ValueErrorZsavefig)r_   Zmonkeypatchr.   r/   Ztmpfiler#   r#   r$   test_missing_psfont   s     
ri   ) tempfiler   ZnumpyrH   rS   Z
matplotlibr(   r   Zmatplotlib.testingr   Zmatplotlib.testing.decoratorsr   r   Zmatplotlib.testing._markersr   Zmatplotlib.pyplotZpyplotr*   Z
pytestmarkr   r6   r7   r<   r?   markZparametrizerP   rU   rW   r]   Zflakyri   r#   r#   r#   r$   <module>   sF   








