o
    tBhW                     @   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PIPEsphinx)   
   z4.1.3)
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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 |d'  }
|
d(d)}
|d' |
 fd*dd+D }t|  t|d&sJ d j|d, ks-J d% j|d ks;J d- j|d% ksIJ t|dsTJ t|d%s_J t|d-sjJ d j|d- ksxJ t|dsJ d S ).Nsrc	tinypages_buildhtmldoctrees-msphinx-W-b-dT )
MPLBACKENDGCOV_ERROR_FILEstdoutstderruniversal_newlinesenvc                    s    d|  d S )Nsome_plots-.png num)html_dirr   v/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/matplotlib/tests/test_sphinxext.py	plot_file%   s   z!test_tinypages.<locals>.plot_filec                    s    j d d|  d S )N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>,   s    z"test_tinypages.<locals>.<listcomp>               12_00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*   r2   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_textr4   r5   )tmpdir
source_dircmdprocouterrrange_10range_6range_4html_contentscontentsmodification_timesr   )r$   r   r%   r!   r    test_tinypages   sb   
rU   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 sGJ |d	 d }t|||ddgd ddd |	 D vsdJ d S )Nr	   ztinypages/conf.pyzconf.pyztinypages/_static_staticr   z	index.rstz#
.. plot::

    plt.plot(range(2))
r   html1z
index-1.pyc                 S      g | ]}|j qS r   namer'   pr   r   r    r)   t       z3test_plot_html_show_source_link.<locals>.<listcomp>html2z-Dzplot_html_show_source_link=0)
extra_argsc                 S   rX   r   rY   r[   r   r   r    r)   z   r]   )
r   mkdirr8   r#   r6   copyfiler7   rH   r@   iterdir)rI   rJ   r#   r$   	html_dir1	html_dir2r   r   r    test_plot_html_show_source_linke   s   
re   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sBJ d| d| d|rLt	
d|  | sRJ 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:
)r9   r:   r;   r   r   r<   r=   r?   
returncodepytestfailis_dir)rJ   r$   r   r_   rK   rL   rM   rN   r   r   r    r@   }   s    
r@   )N)__doc__rB   r<   pathlibr   r6   
subprocessr   r   r9   rh   importorskipversion_inforU   re   r@   r   r   r   r    <module>   s    T