U
    Fvf@                     @   s   d Z ddlZddlZddlmZ ddlZddlmZmZ ddl	Z	ddl
Z
e
jde	jdk r\dndd dd	d
Zdd Zdd Ze
jdddgdd Ze
jdddgdd ZdS )z2Tests for tinypages build using sphinx extensions.    N)Path)PopenPIPEZsphinx)   
   z4.1.3)Z
minversionc              
   C   s   |d krg n|}t jdddddt|t| t|f	|}t|ttdtjddid	}| \}}|jd
kst	d| d| d|rt
d|  | st	d S )N-msphinx-W-bhtml-dT
MPLBACKEND stdoutstderruniversal_newlinesenvr   z!sphinx build failed with stdout:
z	
stderr:

z-sphinx build emitted the following warnings:
)sys
executablestrr   r   osenvironcommunicate
returncodeAssertionErrorpytestZfailis_dir)
source_dirdoctree_dirhtml_dir
extra_argscmdprocouterr r&   C/tmp/pip-unpacked-wheel-7vhvci0g/matplotlib/tests/test_sphinxext.pybuild_sphinx_html   s&       
r(   c              
      s6  t jttjd | dd | d d }|d | d  tjdd	d
ddt tttjd t|g	}t|t	t	dt
jdt
jdd}| \}}t|  | fdd fddfddtddD \}}}t|dstt|dstt|dstt|ds&tt|ds<tt|dsRt|d  }	d|	ksltt|d stt|d  std!|	kstd"|	kstd#|	kstd$|	kst|	d%d&kstt|d'stt|d( st| d)  }
|
d*d+}
| d) |
 fd,dd-D }t|  | t|d'sjtd j|d. kstd& j|d kstd/ j|d& kstt|dstt|d&stt|d/s td j|d/ kstt|ds2td S )0NZ	tinypagesT)dirs_exist_ok_buildr
   Z_imagesdoctreesr   r   r	   r   r   )r   ZGCOV_ERROR_FILEr   c                    s    d|  d S )Nsome_plots-.pngr&   num)img_dirr&   r'   	plot_file7   s    z!test_tinypages.<locals>.plot_filec                    s    j d d|  d S )NZplot_directiver,   r-   )parentr.   )r   r&   r'   plot_directive_file:   s    z+test_tinypages.<locals>.plot_directive_filec                    s   g | ]} |qS r&   r&   .0i)r1   r&   r'   
<listcomp>>   s     z"test_tinypages.<locals>.<listcomp>               Z12_00Z12_01   zsome_plots.htmls   # Only a commentz
range4.pngzrange6_range6.pngs    This is the caption for plot 15.s    Plot 17 uses the caption option.s    This is the caption for plot 18.s&   plot-directive my-class my-other-classs#   This caption applies to both plots.      zrange6_range10.pngzincluded_plot_21.rsts   plt.plot(range(6))s   plt.plot(range(4))c                    s   g | ]} |  jqS r&   )statst_mtimer4   )r3   r&   r'   r7   f   s   )r8   r>   r   r:   r   r   )shutilcopytreer   __file__r2   r   r   r   r   r   r   r   devnullr   r(   rangefilecmpcmpr   
read_bytescountreplacewrite_bytesr@   rA   )tmp_pathr    r"   r#   r$   r%   Zrange_10Zrange_6Zrange_4Zhtml_contentscontentsZmodification_timesr&   )r   r0   r3   r1   r'   test_tinypages"   sr         
rO   c                 C   s   t tj}t|d | d  t|d | d  | d }| d d | d d	 }t| || tt	|
d
dkszt| d d }t| ||ddgd tt	|
d
dkstd S )Ntinypages/conf.pyconf.pytinypages/_static_staticr+   	index.rstz#
.. plot::

    plt.plot(range(2))
r*   Zhtml1**/index-1.pyr8   Zhtml2-Dzplot_html_show_source_link=0r!   r   r   rD   r2   rB   copyfilerC   
write_textr(   lenlistglobr   )rM   r2   r   Z	html_dir1Z	html_dir2r&   r&   r'   test_plot_html_show_source_linky   s    
r^   plot_html_show_source_linkr8   c                 C   s   t tj}t|d | d  t|d | d  | d }| d d | d d	 }t| ||d
d| gd tt	|
ddkstd S )NrP   rQ   rR   rS   r+   rT   z?
.. plot::
    :show-source-link: true

    plt.plot(range(2))
r*   r
   rV   plot_html_show_source_link=rW   rU   r8   rX   rM   r_   r2   r   r    r&   r&   r'   test_show_source_link_true   s    
 rb   c                 C   s   t tj}t|d | d  t|d | d  | d }| d d | d d	 }t| ||d
d| gd tt	|
ddkstd S )NrP   rQ   rR   rS   r+   rT   z@
.. plot::
    :show-source-link: false

    plt.plot(range(2))
r*   r
   rV   r`   rW   rU   r   rX   ra   r&   r&   r'   test_show_source_link_false   s    
 rc   )N)__doc__rG   r   pathlibr   rB   
subprocessr   r   r   r   Zimportorskipversion_infor(   rO   r^   markZparametrizerb   rc   r&   r&   r&   r'   <module>   s"   
W
