1
1
""" Tests for tinypages build using sphinx extensions """
2
2
3
+ import filecmp
4
+ from os .path import join as pjoin , dirname , isdir
3
5
import shutil
4
- import tempfile
5
-
6
- from os .path import (join as pjoin , dirname , isdir )
7
-
8
6
from subprocess import call , Popen , PIPE
7
+ import sys
8
+ import tempfile
9
9
10
10
import pytest
11
11
12
+ from matplotlib import cbook
13
+
12
14
13
15
HERE = dirname (__file__ )
14
16
TINY_PAGES = pjoin (HERE , 'tinypages' )
15
17
16
18
17
19
def 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 )
23
24
if ret != 0 :
24
- raise RuntimeError ('sphinx-build does not return 0' )
25
+ raise RuntimeError (
26
+ "'{} -msphinx' does not return 0" .format (sys .executable ))
25
27
26
28
29
+ @cbook .deprecated ("2.1" , alternative = "filecmp.cmp" )
27
30
def file_same (file1 , file2 ):
28
31
with open (file1 , 'rb' ) as fobj :
29
32
contents1 = fobj .read ()
@@ -42,15 +45,16 @@ def setup_class(cls):
42
45
cls .html_dir = pjoin (cls .page_build , 'html' )
43
46
cls .doctree_dir = pjoin (cls .page_build , 'doctrees' )
44
47
# Build the pages with warnings turned into errors
45
- cmd = [str ( 'sphinx-build' ) , '-W' , '-b' , 'html' ,
48
+ cmd = [sys . executable , '-msphinx' , '-W' , '-b' , 'html' ,
46
49
'-d' , cls .doctree_dir ,
47
50
TINY_PAGES ,
48
51
cls .html_dir ]
49
52
proc = Popen (cmd , stdout = PIPE , stderr = PIPE )
50
53
out , err = proc .communicate ()
51
54
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 ))
54
58
except Exception as e :
55
59
shutil .rmtree (cls .page_build )
56
60
raise e
@@ -67,22 +71,22 @@ def plot_file(num):
67
71
68
72
range_10 , range_6 , range_4 = [plot_file (i ) for i in range (1 , 4 )]
69
73
# Plot 5 is range(6) plot
70
- assert file_same (range_6 , plot_file (5 ))
74
+ assert filecmp . cmp (range_6 , plot_file (5 ))
71
75
# Plot 7 is range(4) plot
72
- assert file_same (range_4 , plot_file (7 ))
76
+ assert filecmp . cmp (range_4 , plot_file (7 ))
73
77
# Plot 11 is range(10) plot
74
- assert file_same (range_10 , plot_file (11 ))
78
+ assert filecmp . cmp (range_10 , plot_file (11 ))
75
79
# 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' ))
78
82
# 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 ))
80
84
# Plot 14 has included source
81
85
with open (pjoin (self .html_dir , 'some_plots.html' ), 'rb' ) as fobj :
82
86
html_contents = fobj .read ()
83
87
assert b'# Only a comment' in html_contents
84
88
# 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' ))
87
91
# check if figure caption made it into html file
88
92
assert b'This is the caption for plot 15.' in html_contents
0 commit comments