U
    Âmœd@  ã                   @   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s€t	d|› d|› d�ƒ‚|r”t
 d|› �¡ | ¡ s t	‚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&   úX/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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ƒ¡sæt‚t |ˆdƒ¡sút‚t |ˆdƒ¡�st‚t |ˆdƒ¡�s&t‚t |ˆdƒ¡�s<t‚t |ˆdƒ¡�sRt‚|d  ¡ }	d|	k�slt‚t |ˆd ¡�s‚t‚t |ˆd  ¡�s˜t‚d!|	k�s¦t‚d"|	k�s´t‚d#|	k�sÂt‚d$|	k�sÐt‚|	 d%¡d&k�sät‚t |ˆd'ƒ¡�sút‚t |ˆd( ¡�st‚| d)  ¡ }
|
 d*d+¡}
| d)  |
¡ ‡fd,d„d-D ƒ}t| ˆ |ƒ t |ˆd'ƒ¡�sjt‚ˆdƒ ¡ j|d. k�s†t‚ˆd&ƒ ¡ j|d k�s¢t‚ˆd/ƒ ¡ j|d& k�s¾t‚t |ˆdƒ¡�sÔt‚t |ˆd&ƒ¡�sêt‚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s´t‚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sˆt‚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sˆt‚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
