
    G8c[                         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	 Zd
 ZddZy)z2Tests for tinypages build using sphinx extensions.    N)Path)PopenPIPEsphinx)   
   z4.1.3)
minversionc                 P   t        |       dz  }t        j                  t        t              j                  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        |t        t        d
i t        j                  dt        j                  d      }|j                         \  }}t        |       fd}fd}t        dd      D cg c]
  } ||       c}\  }	}
}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|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 |j'                  d       d!k(  sJ t!        j"                  |
 |d"            sJ |d#z  j%                         }|j)                  d$d%      }|d#z  j+                  |       d&D cg c]"  } ||      j-                         j.                  $ }}t        |       t!        j"                  | |d"            sJ  |d      j-                         j.                  |d'   k(  sJ  |d!      j-                         j.                  |d   k(  sJ  |d(      j-                         j.                  |d!   k(  sJ t!        j"                  |	 |d            sJ t!        j"                  |
 |d!            sJ t!        j"                  | |d(            sJ  |d      j-                         j.                  |d(   kD  sJ t!        j"                  |
 |d            sJ y c c}w c c}w ))Nsrc	tinypages_buildhtmldoctrees-msphinx-W-b-dT )
MPLBACKENDGCOV_ERROR_FILEstdoutstderruniversal_newlinesenvc                     d|  dz  S )Nsome_plots-.png )numhtml_dirs    A/usr/lib/python3/dist-packages/matplotlib/tests/test_sphinxext.py	plot_filez!test_tinypages.<locals>.plot_file%   s    KuD111    c                 0    j                   dz  d|  dz  S )Nplot_directiver   r   )parent)r    doctree_dirs    r"   plot_directive_filez+test_tinypages.<locals>.plot_directive_file(   s#    !!$44SE7NNNr$                  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.rsts   plt.plot(range(6))s   plt.plot(range(4)))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replacewrite_bytesstatst_mtime)tmpdir
source_dircmdprocouterrr#   r)   irange_10range_6range_4html_contentscontentsmodification_timesr(   r!   s                  @@r"   test_tinypagesrU      s   f%J
OODN))K7DH$v-Hz)K>>:tT6[!tH~$${23S]DC D$KrzzK

KMD !HC j+x82O 9>a!D1)A,!DHgw;;w	!---;;w	!---;;x2///;;x7!3444;;w	' 2333;;w	"... 11==?M-///;;w< 7888;;w< 7888.-???.-???.-???4EEEEF!KKK ;;w	"... 33??AH 57LMH((55h? $01 .a0557@@ 1 1j+x8;;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	!---m "EL1s   P1'P#c                 4   t        |       dz  }|j                          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|j                         D cg c]  }|j                   c}v sJ |d	z  dz  }t        |||ddg       d|j                         D cg c]  }|j                   c}vsJ y c c}w c c}w )Nr   ztinypages/conf.pyzconf.pyztinypages/_static_staticr   z	index.rstz#
.. plot::

    plt.plot(range(2))
r   html1z
index-1.pyhtml2z-Dzplot_html_show_source_link=0)
extra_args)r   mkdirr6   r'   r4   copyfiler5   
write_textr>   iterdirname)rH   rI   r'   r(   	html_dir1p	html_dir2s          r"   test_plot_html_show_source_linkrc   e   s   f%J(^""F
OOF00*y2HI
OOF00*y2HIz)K+)) +  X%/Ij+y9I,=,=,?@qAFF@@@@ X%/Ij+y"&(F!GI	0A0A0CD1DDDD A  Es   1D6Dc                    |g n|}t         j                  dddddt        |      t        |       t        |      g	|}t        |t        t        di t
        j                  ddi	      }|j                         \  }}|j                  d
k(  sJ d| d| d       |rt        j                  d|        |j                         sJ y )Nr   r   r   r   r   Tr   r   r   r   z!sphinx build failed with stdout:
z	
stderr:

z-sphinx build emitted the following warnings:
)r7   r8   r9   r   r   r:   r;   r=   
returncodepytestfailis_dir)rI   r(   r!   rZ   rJ   rK   rL   rM   s           r"   r>   r>   }   s    !)zJ>>:tT6[!3z?CMPDNPCT$45

5L"57D!HC??a E
,SESEDE
DSEJK??r$   )N)__doc__r@   r:   pathlibr   r4   
subprocessr   r   r7   rg   importorskipversion_inforU   rc   r>   r   r$   r"   <module>ro      sV    8  	   " 
    H'*'7'7''AtwPQ.hE0r$   