o
    li@                     @   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PIPEsphinx)   
   z4.1.3)
minversionc              
   C   s   |d u rg n|}t jdddddt|t| t|g	|}t|ttdi tjddid	}| \}}|jd
ksBJ d| d| d|rLt	
d|  | sRJ 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pytestfailis_dir)
source_dirdoctree_dirhtml_dir
extra_argscmdprocouterr r(   ]/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/matplotlib/tests/test_sphinxext.pybuild_sphinx_html   s    
r*   c              
      s  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i t
jdt
jdd}| \}}t|  | fdd fddfddtddD \}}}t|dsuJ t|dsJ t|dsJ t|dsJ t|dsJ t|dsJ |d  }	d|	v sJ t|d sJ t|d  sJ d!|	v sJ d"|	v sJ d#|	v sJ d$|	v sJ |	d%d&ksJ t|d'sJ t|d( sJ | d)  }
|
d*d+}
| d) |
 fd,dd-D }t|  | t|d's)J d j|d. ks7J d& j|d ksEJ d/ j|d& ksSJ t|ds^J t|d&siJ t|d/stJ d j|d/ ksJ t|dsJ d S )0N	tinypagesT)dirs_exist_ok_buildr   _imagesdoctreesr	   r
   r   r   r   )r   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 )Nplot_directiver1   r2   )parentr3   )r!   r(   r)   plot_directive_file:   s   z+test_tinypages.<locals>.plot_directive_filec                    s   g | ]} |qS r(   r(   .0i)r6   r(   r)   
<listcomp>>   s    z"test_tinypages.<locals>.<listcomp>               12_00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_mtimer:   )r9   r(   r)   r=   f   s    )r>   rF   r   r@   r   r   )shutilcopytreer   __file__r8   r   r   r   r   r   r   r   devnullr   r*   rangefilecmpcmp
read_bytescountreplacewrite_bytesrH   rI   )tmp_pathr"   r$   r%   r&   r'   range_10range_6range_4html_contentscontentsmodification_timesr(   )r!   r5   r9   r6   r)   test_tinypages"   sh   
r\   c                 C   s   t tj}t|d | d  t|d | d  | d }| d d | d d	 }t| || tt	|
d
dks=J | d d }t| ||ddgd tt	|
d
dksZJ d S )Ntinypages/conf.pyconf.pytinypages/_static_staticr/   	index.rstz#
.. plot::

    plt.plot(range(2))
r-   html1**/index-1.pyr>   html2-Dzplot_html_show_source_link=0r#   r   r   rL   r8   rJ   copyfilerK   
write_textr*   lenlistglob)rU   r8   r!   	html_dir1	html_dir2r(   r(   r)   test_plot_html_show_source_linky   s   
ro   plot_html_show_source_linkr>   c                 C      t tj}t|d | d  t|d | d  | d }| d d | d d	 }t| ||d
d| gd tt	|
ddksDJ d S )Nr]   r^   r_   r`   r/   ra   z?
.. plot::
    :show-source-link: true

    plt.plot(range(2))
r-   r   re   plot_html_show_source_link=rf   rc   r>   rg   rU   rp   r8   r!   r"   r(   r(   r)   test_show_source_link_true      

rt   c                 C   rq   )Nr]   r^   r_   r`   r/   ra   z@
.. plot::
    :show-source-link: false

    plt.plot(range(2))
r-   r   re   rr   rf   rc   r   rg   rs   r(   r(   r)   test_show_source_link_false   ru   rv   )N)__doc__rO   r   pathlibr   rJ   
subprocessr   r   r   r   importorskipversion_infor*   r\   ro   markparametrizert   rv   r(   r(   r(   r)   <module>   s$    
W
