
    %Wh&                        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Zd	 Zd
 Ze	j                  j                  dddg      d        Ze	j                  j                  dddg      d        Zd Zy)z2Tests for tinypages build using sphinx extensions.    N)Path)subprocess_run_for_testingsphinxz4.1.3)
minversionc                    |g n|}t         j                  dddddt        |      t        |       t        |      g	|}t        |ddi t        j
                  ddi	      }|j                  }|j                  }|j                  d
k(  sJ d| d| d       |rt        j                  d|        |j                         sJ y )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pytestfailis_dir)
source_dirdoctree_dirhtml_dir
extra_argscmdprocouterrs           Y/var/www/html/jupyter_env/lib/python3.12/site-packages/matplotlib/tests/test_sphinxext.pybuild_sphinx_htmlr(      s    !)zJ>>:tT6[!3z?CMPDNPC%Dt,rzz,<,.D ++C
++C??a E
,SESEDE
DSEJK??    c                 b   t        j                  t        t              j                  dz  | d       | dz  dz  }|dz  | dz  t
        j                  dd	d
ddt              t        t        t              j                  dz        t        |      g	}t        |ddi t        j                  dt        j                  d      }|j                  }|j                  }t        | |       fdfd}fdt        dd      D        \  }}}	t!        j"                  | d            sJ t!        j"                  |	 d            sJ t!        j"                  | d            sJ t!        j"                  | d            sJ t!        j"                  | d            sJ t!        j"                  |	 d            sJ |dz  j%                  d      }
d|
v sJ t!        j"                  |	dz        sJ t!        j"                  |dz        sJ d |
v sJ d!|
v sJ d"|
v sJ d#|
v sJ d$|
v sJ |
j'                  d%      d&k(  sJ t!        j"                  | d'            sJ t!        j"                  |d(z        sJ | d)z  j)                         }|j+                  d*d+      }| d)z  j-                  |       d,D cg c]"  } ||      j/                         j0                  $ }}t        | |       t!        j"                  |	 d'            sJ  |d      j/                         j0                  |d-   k(  sJ  |d&      j/                         j0                  |d   k(  sJ  |d.      j/                         j0                  |d&   k(  sJ t!        j"                  | d            sJ t!        j"                  | d&            sJ t!        j"                  |	 d.            sJ  |d      j/                         j0                  |d.   kD  sJ t!        j"                  | d            sJ y c c}w )/N	tinypagesTdirs_exist_ok_buildr   _imagesdoctreesr   r	   r
   r   r   )r   GCOV_ERROR_FILEr   c                     d|  dz  S Nsome_plots-.png )numimg_dirs    r'   	plot_filez!test_tinypages.<locals>.plot_file:   s    ;se4000r)   c                 0    j                   dz  d|  dz  S )Nplot_directiver4   r5   )parent)r7   r    s    r'   plot_directive_filez+test_tinypages.<locals>.plot_directive_file=   s#    !!$44SE7NNNr)   c              3   .   K   | ]  } |        y wNr6   ).0ir9   s     r'   	<genexpr>z!test_tinypages.<locals>.<genexpr>A   s     !D1)A,!Ds                  12_00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)))rC   rO      rE   r   rQ   )shutilcopytreer   __file__r<   r   r   r   r   r   r   devnullr   r   r(   rangefilecmpcmp	read_textcount
read_bytesreplacewrite_bytesstatst_mtime)tmp_pathr!   r#   r$   r%   r&   r=   range_10range_6range_4html_contentscontentsrA   modification_timesr    r8   r9   s                 @@@r'   test_tinypagesrg   #   s   
OODN))K7"&(("V+H"GZ'K>>:tT6[!tH~$${23S]DC &DtKrzzK

KD ++C
++C hX61O "Ea!DHgw;;w	!---;;w	!---;;x2///;;x7!3444;;w	' 2333;;w	"... 11<<g<NM...;;w, 6777;;w*= =>>>->>> FVVV@MQQQ->>>3}DDDDEJJJ ;;w	"...;;x+?!?@@@ 11==?H 57LMH&&33H= $01 .a0557@@ 1 1hX6;;w	"... q!&&(115G5JJJJq!&&(115G5JJJJq!&&(115G5JJJJ;;x1...;;w	!---;;w	!--- q!&&(114Fq4IIII;;w	!---!1s   ?'P,c                    t        t              j                  }t        j                  |dz  | dz         t        j
                  |dz  | dz         | dz  }| dz  j                  d       | dz  d	z  }t        | ||       t        t        |j                  d
                  dk(  sJ | dz  dz  }t        | ||ddg       t        t        |j                  d
                  dk(  sJ y )Ntinypages/conf.pyconf.pytinypages/_static_staticr0   	index.rstz#
.. plot::

    plt.plot(range(2))
r.   html1**/index-1.pyrC   html2-Dzplot_html_show_source_link=0r"   r   r   rT   r<   rR   copyfilerS   
write_textr(   lenlistglob)r`   r<   r    	html_dir1	html_dir2s        r'   test_plot_html_show_source_linkr{      s    (^""F
OOF00(Y2FG
OOF00(Y2FGZ'K'' )  8#g-IhY7tINN?345::: 8#g-IhY"&(F!GItINN?345:::r)   plot_html_show_source_linkrC   c                 `   t        t              j                  }t        j                  |dz  | dz         t        j
                  |dz  | dz         | dz  }| dz  j                  d       | dz  d	z  }t        | ||d
d| g       t        t        |j                  d                  dk(  sJ y )Nri   rj   rk   rl   r0   rm   z?
.. plot::
    :show-source-link: true

    plt.plot(range(2))
r.   r   rq   plot_html_show_source_link=rr   ro   rC   rs   r`   r|   r<   r    r!   s        r'   test_show_source_link_truer           (^""F
OOF00(Y2FG
OOF00(Y2FGZ'K'' )  ("V+HhX+,F+GHCJ KtHMM/234999r)   c                 `   t        t              j                  }t        j                  |dz  | dz         t        j
                  |dz  | dz         | dz  }| dz  j                  d       | dz  d	z  }t        | ||d
d| g       t        t        |j                  d                  dk(  sJ y )Nri   rj   rk   rl   r0   rm   z@
.. plot::
    :show-source-link: false

    plt.plot(range(2))
r.   r   rq   r~   rr   ro   r   rs   r   s        r'   test_show_source_link_falser      r   r)   c                    t        j                  t        t              j                  dz  | d       | dz  dz  }|dz  | dz  }t        | ||dd	g
       dfd	}dD ]4  } ||      j                         sJ  ||d      j                         r4J  dz  j                         sJ dz  j                         sJ dz  j                         sJ dz  j                         sJ dz  j                         sJ dz  j                         sJ dz  j                         sJ dz  j                         sJ d|dz  j                  d      v sJ d}||dz  j                  d      v sJ d}||dz  j                  d      v sJ y ) Nr+   Tr,   r.   r   r/   r0   rq   zplot_srcset=2xrr   c                     d|  | dz  S r3   r6   )r7   suffr8   s     r'   r9   z&test_srcset_version.<locals>.plot_file   s    ;seD6666r)   )	rC   rO   rQ   rE   rF   rG   rJ      rP   z.2x)r   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"rK   rL   rM   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   )rR   rS   r   rT   r<   r(   existsrY   )r`   r!   r    r9   indstr8   s         @r'   test_srcset_versionr      s   
OODN))K7"&(("V+H"GZ'KhXC  !7 / 3~$$&&&5)002223 ..668881199;;;..668881199;;;//7799922::<<<//7799922::<<< S,,777IJ K J8B(44???QQQQ9B(55@@'@RRRRr)   r?   )__doc__rW   r   pathlibr   rR   r   matplotlib.testingr   r   importorskipr(   rg   r{   markparametrizer   r   r   r6   r)   r'   <module>r      s    8  	   
 9    H 1&Y.x;, 51v>: ?:& 51v>: ?:&&Sr)   