o
    j&                     @   s   d 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	Z	e	j
d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d ZdS )z2Tests for tinypages build using sphinx extensions.    N)Path)subprocess_run_for_testingZsphinxz4.1.3)Z
minversionc              
   C   s   |d u rg n|}t jdddddt|t| t|g	|}t|ddi tjddid	}|j}|j}|jd
ksAJ d| d| d|rKt	
d|  | sQJ d S )N-msphinx-W-bhtml-dT
MPLBACKEND capture_outputtextenvr   z!sphinx build failed with stdout:
z	
stderr:

z-sphinx build emitted the following warnings:
)sys
executablestrr   osenvironstdoutstderr
returncodepytestZfailis_dir)
source_dirdoctree_dirhtml_dir
extra_argscmdprocouterr r"   `/var/www/html/Deteccion_Ine/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|ddi t	j
dt	jdd}|j}|j}t|  | fdd fddfddtddD \}}}t|dstJ t|ds~J t|dsJ t|dsJ t|dsJ t|dsJ |d jdd}	d |	v sJ t|d! sJ t|d" sJ d#|	v sJ d$|	v sJ d%|	v sJ d&|	v sJ d'|	v sJ |	d(d)ksJ t|d*sJ t|d+ sJ | d,  }
|
d-d.}
| d, |
 fd/d0d1D }t|  | t|d*s1J d j|d2 ks?J d) j|d ksMJ d3 j|d) ks[J t|dsfJ t|d)sqJ t|d3s|J d j|d3 ksJ t|dsJ d S )4N	tinypagesTdirs_exist_ok_buildr   _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_file:   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                 3   s    | ]} |V  qd S Nr"   .0i)r2   r"   r#   	<genexpr>A   s    z!test_tinypages.<locals>.<genexpr>               Z12_00Z12_01   some_plots.htmlutf-8encodingz# Only a commentz
range4.pngzrange6_range6.pngz This is the caption for plot 15.z7Plot 17 uses the caption option,
with multi-line input.z3Plot 17 uses the alt option, with multi-line input.z This is the caption for plot 18.z&plot-directive my-class my-other-classz#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_mtimer6   )r4   r"   r#   
<listcomp>l   s    z"test_tinypages.<locals>.<listcomp>)r:   rD      r<   r   rI   )shutilcopytreer   __file__r3   r   r   r   r   r   r   devnullr   r   r$   rangefilecmpcmp	read_textcount
read_bytesreplacewrite_bytesrF   rG   )tmp_pathr   r   r   r    r!   Zrange_10Zrange_6Zrange_4Zhtml_contentscontentsZmodification_timesr"   )r   r1   r4   r2   r#   test_tinypages#   sl   
rX   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(   Zhtml1**/index-1.pyr:   Zhtml2-Dzplot_html_show_source_link=0r   r   r   rL   r3   rJ   copyfilerK   
write_textr$   lenlistglob)rV   r3   r   Z	html_dir1Z	html_dir2r"   r"   r#   test_plot_html_show_source_link   s   
rg   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 )NrY   rZ   r[   r\   r*   r]   z?
.. plot::
    :show-source-link: true

    plt.plot(range(2))
r(   r   r_   plot_html_show_source_link=r`   r^   r:   ra   rV   rh   r3   r   r   r"   r"   r#   test_show_source_link_true      

rl   c                 C   ri   )NrY   rZ   r[   r\   r*   r]   z@
.. plot::
    :show-source-link: false

    plt.plot(range(2))
r(   r   r_   rj   r`   r^   r   ra   rk   r"   r"   r#   test_show_source_link_false   rm   rn   c                    sZ  t jttjd | dd | d d }|d  | d }t| ||dd	gd
 d! fdd	}dD ]}|| s8J ||dd sBJ q. d  sKJ  d  sSJ  d  s[J  d  scJ  d  skJ  d  ssJ  d  s{J  d  sJ d|d jddv sJ d}||d jddv sJ d}||d  jddv sJ d S )"Nr%   Tr&   r(   r   r)   r*   r_   zplot_srcset=2xr`   r
   c                    s    d|  | d S r+   r"   )r/   suffr0   r"   r#   r2      s   z&test_srcset_version.<locals>.plot_file)	r:   rD   rI   r<   r=   r>   r?      rE   z.2x)ro   znestedpage-index-1.pngznestedpage-index-1.2x.pngznestedpage-index-2.pngznestedpage-index-2.2x.pngznestedpage2-index-1.pngznestedpage2-index-1.2x.pngznestedpage2-index-2.pngznestedpage2-index-2.2x.pngzDsrcset="_images/some_plots-1.png, _images/some_plots-1.2x.png 2.00x"r@   rA   rB   zVsrcset="../_images/nestedpage-index-1.png, ../_images/nestedpage-index-1.2x.png 2.00x"znestedpage/index.htmlzXsrcset="../_images/nestedpage2-index-2.png, ../_images/nestedpage2-index-2.2x.png 2.00x"znestedpage2/index.html)r
   )rJ   rK   r   rL   r3   r$   existsrQ   )rV   r   r   r2   indstr"   r0   r#   test_srcset_version   s8   rt   r5   )__doc__rO   r   pathlibr   rJ   r   Zmatplotlib.testingr   r   Zimportorskipr$   rX   rg   markZparametrizerl   rn   rt   r"   r"   r"   r#   <module>   s"    
\

