11""" Tests for tinypages build using sphinx extensions """
22
3+ import filecmp
4+ from os .path import join as pjoin , dirname , isdir
35import shutil
4- import tempfile
5-
6- from os .path import (join as pjoin , dirname , isdir )
7-
86from subprocess import call , Popen , PIPE
7+ import sys
8+ import tempfile
99
1010import pytest
1111
12+ from matplotlib import cbook
13+
1214
1315HERE = dirname (__file__ )
1416TINY_PAGES = pjoin (HERE , 'tinypages' )
1517
1618
1719def setup_module ():
18- """Check we have the sphinx-build command"""
19- try :
20- ret = call (['sphinx-build' , '--help' ], stdout = PIPE , stderr = PIPE )
21- except OSError :
22- pytest .skip ('Need sphinx-build on path for these tests' )
20+ """Check we have a recent enough version of sphinx installed.
21+ """
22+ ret = call ([sys .executable , '-msphinx' , '--help' ],
23+ stdout = PIPE , stderr = PIPE )
2324 if ret != 0 :
24- raise RuntimeError ('sphinx-build does not return 0' )
25+ raise RuntimeError (
26+ "'{} -msphinx' does not return 0" .format (sys .executable ))
2527
2628
29+ @cbook .deprecated ("2.1" , alternative = "filecmp.cmp" )
2730def file_same (file1 , file2 ):
2831 with open (file1 , 'rb' ) as fobj :
2932 contents1 = fobj .read ()
@@ -42,15 +45,16 @@ def setup_class(cls):
4245 cls .html_dir = pjoin (cls .page_build , 'html' )
4346 cls .doctree_dir = pjoin (cls .page_build , 'doctrees' )
4447 # Build the pages with warnings turned into errors
45- cmd = [str ( 'sphinx-build' ) , '-W' , '-b' , 'html' ,
48+ cmd = [sys . executable , '-msphinx' , '-W' , '-b' , 'html' ,
4649 '-d' , cls .doctree_dir ,
4750 TINY_PAGES ,
4851 cls .html_dir ]
4952 proc = Popen (cmd , stdout = PIPE , stderr = PIPE )
5053 out , err = proc .communicate ()
5154 if proc .returncode != 0 :
52- raise RuntimeError ('sphinx-build failed with stdout:\n '
53- '{0}\n stderr:\n {1}\n ' .format (out , err ))
55+ raise RuntimeError (
56+ "'{} -msphinx' failed with stdout:\n {}\n stderr:\n {}\n "
57+ .format (sys .executable , out , err ))
5458 except Exception as e :
5559 shutil .rmtree (cls .page_build )
5660 raise e
@@ -67,22 +71,22 @@ def plot_file(num):
6771
6872 range_10 , range_6 , range_4 = [plot_file (i ) for i in range (1 , 4 )]
6973 # Plot 5 is range(6) plot
70- assert file_same (range_6 , plot_file (5 ))
74+ assert filecmp . cmp (range_6 , plot_file (5 ))
7175 # Plot 7 is range(4) plot
72- assert file_same (range_4 , plot_file (7 ))
76+ assert filecmp . cmp (range_4 , plot_file (7 ))
7377 # Plot 11 is range(10) plot
74- assert file_same (range_10 , plot_file (11 ))
78+ assert filecmp . cmp (range_10 , plot_file (11 ))
7579 # Plot 12 uses the old range(10) figure and the new range(6) figure
76- assert file_same (range_10 , plot_file ('12_00' ))
77- assert file_same (range_6 , plot_file ('12_01' ))
80+ assert filecmp . cmp (range_10 , plot_file ('12_00' ))
81+ assert filecmp . cmp (range_6 , plot_file ('12_01' ))
7882 # Plot 13 shows close-figs in action
79- assert file_same (range_4 , plot_file (13 ))
83+ assert filecmp . cmp (range_4 , plot_file (13 ))
8084 # Plot 14 has included source
8185 with open (pjoin (self .html_dir , 'some_plots.html' ), 'rb' ) as fobj :
8286 html_contents = fobj .read ()
8387 assert b'# Only a comment' in html_contents
8488 # check plot defined in external file.
85- assert file_same (range_4 , pjoin (self .html_dir , 'range4.png' ))
86- assert file_same (range_6 , pjoin (self .html_dir , 'range6.png' ))
89+ assert filecmp . cmp (range_4 , pjoin (self .html_dir , 'range4.png' ))
90+ assert filecmp . cmp (range_6 , pjoin (self .html_dir , 'range6.png' ))
8791 # check if figure caption made it into html file
8892 assert b'This is the caption for plot 15.' in html_contents
0 commit comments