a
    ëÝEbW  ã                   @   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
„ Zdd„ Zddd„ZdS )z2Tests for tinypages build using sphinx extensions.é    N)ÚPath)ÚPopenÚPIPEZsphinx)é   é
   z4.1.3)Z
minversionc              
      s$  t | ƒd }t t tƒj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ƒ¡sêJ ‚t |ˆdƒ¡sþJ ‚t |ˆdƒ¡�sJ ‚t |ˆdƒ¡�s*J ‚t |ˆdƒ¡�s@J ‚t |ˆdƒ¡�sVJ ‚ˆd  ¡ }	d|	v �spJ ‚t |ˆd ¡�s†J ‚t |ˆd ¡�sœJ ‚d |	v �sªJ ‚d!|	v �s¸J ‚d"|	v �sÆJ ‚d#|	v �sÔJ ‚|	 d$¡d%k�sèJ ‚t |ˆd&ƒ¡�sþJ ‚|d'  ¡ }
|
 d(d)¡}
|d'  |
¡ ‡fd*d„d+D ƒ}t|ˆ ˆƒ t |ˆd&ƒ¡�sXJ ‚ˆdƒ ¡ j|d, k�stJ ‚ˆd%ƒ ¡ j|d k�s�J ‚ˆd-ƒ ¡ j|d% k�s¬J ‚t |ˆdƒ¡�sÂJ ‚t |ˆd%ƒ¡�sØJ ‚t |ˆd-ƒ¡�sîJ ‚ˆdƒ ¡ j|d- k�s
J ‚t |ˆdƒ¡�s J ‚d S ).NÚsrcZ	tinypagesÚ_buildÚhtmlÚdoctreesú-msphinxú-Wú-bú-dTÚ )Ú
MPLBACKENDZGCOV_ERROR_FILE©ÚstdoutÚstderrÚuniversal_newlinesÚenvc                    s   ˆ d| › d� S )Núsome_plots-ú.png© ©Únum)Úhtml_dirr   ú_/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/matplotlib/tests/test_sphinxext.pyÚ	plot_file%   s    z!test_tinypages.<locals>.plot_filec                    s   ˆ j d d| › d� S )NZplot_directiver   r   )Úparentr   )Údoctree_dirr   r   Úplot_directive_file(   s    z+test_tinypages.<locals>.plot_directive_filec                    s   g | ]}ˆ |ƒ‘qS r   r   ©Ú.0Úi)r   r   r   Ú
<listcomp>,   ó    z"test_tinypages.<locals>.<listcomp>é   é   é   é   é   Z12_00Z12_01é   zsome_plots.htmls   # Only a commentz
range4.pngz
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included_plot_21.rstzplt.plot(range(6))zplt.plot(range(4))c                    s   g | ]}ˆ |ƒ  ¡ j‘qS r   )ÚstatÚst_mtimer!   )r    r   r   r$   R   s   ÿ)r&   r,   r   r(   r   r   )r   ÚshutilÚcopytreeÚ__file__r   ÚsysÚ
executableÚstrr   r   ÚosÚenvironÚdevnullÚcommunicateÚbuild_sphinx_htmlÚrangeÚfilecmpÚcmpÚ
read_bytesÚcountÚ	read_textÚreplaceÚ
write_textr.   r/   )ÚtmpdirÚ
source_dirÚcmdÚprocÚoutÚerrZrange_10Zrange_6Zrange_4Zhtml_contentsÚcontentsZmodification_timesr   )r   r   r    r   r   Útest_tinypages   sb    þþ
ÿrJ   c                 C   sÌ   t | ƒd }| ¡  t tƒj}t |d |d ¡ t |d |d ¡ |d }|d  d¡ |d	 d
 }t|||ƒ ddd„ | 	¡ D ƒv sŽJ ‚|d	 d }t|||ddgd� ddd„ | 	¡ D ƒvsÈJ ‚d S )Nr   ztinypages/conf.pyzconf.pyztinypages/_staticZ_staticr
   z	index.rstz#
.. plot::

    plt.plot(range(2))
r   Zhtml1z
index-1.pyc                 S   s   g | ]
}|j ‘qS r   ©Úname©r"   Úpr   r   r   r$   t   r%   z3test_plot_html_show_source_link.<locals>.<listcomp>Zhtml2z-Dzplot_html_show_source_link=0)Ú
extra_argsc                 S   s   g | ]
}|j ‘qS r   rK   rM   r   r   r   r$   z   r%   )
r   Úmkdirr2   r   r0   Úcopyfiler1   rB   r:   Úiterdir)rC   rD   r   r   Z	html_dir1Z	html_dir2r   r   r   Útest_plot_html_show_source_linke   s    
ÿrS   c              
   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s„J d|› d|› d�ƒ‚|r˜t	 
d|› �¡ | ¡ s¤J ‚d S )Nr   r   r   r	   r   Tr   r   r   r   z!sphinx build failed with stdout:
z	
stderr:
Ú
z-sphinx build emitted the following warnings:
)r3   r4   r5   r   r   r6   r7   r9   Ú
returncodeÚpytestZfailÚis_dir)rD   r   r   rO   rE   rF   rG   rH   r   r   r   r:   }   s     ÿÿ
ÿÿr:   )N)Ú__doc__r<   r6   Úpathlibr   r0   Ú
subprocessr   r   r3   rV   ZimportorskipÚversion_inforJ   rS   r:   r   r   r   r   Ú<module>   s   ÿT