14
14
minversion = None if sys .version_info < (3 , 10 ) else '4.1.3' )
15
15
16
16
17
+ def _build_sphinx_html (source_dir , doctree_dir , html_dir , extra_args = None ):
18
+ # Build the pages with warnings turned into errors
19
+ extra_args = [] if extra_args is None else extra_args
20
+ cmd = [sys .executable , '-msphinx' , '-W' , '-b' , 'html' ,
21
+ '-d' , str (doctree_dir ), str (source_dir ), str (html_dir ), * extra_args ]
22
+ proc = Popen (cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True ,
23
+ env = {** os .environ , "MPLBACKEND" : "" })
24
+ out , err = proc .communicate ()
25
+
26
+ assert proc .returncode == 0 , \
27
+ f"sphinx build failed with stdout:\n { out } \n stderr:\n { err } \n "
28
+ if err :
29
+ pytest .fail (f"sphinx build emitted the following warnings:\n { err } " )
30
+
31
+ assert html_dir .is_dir ()
32
+
33
+
17
34
def test_tinypages (tmp_path ):
18
35
shutil .copytree (Path (__file__ ).parent / 'tinypages' , tmp_path ,
19
36
dirs_exist_ok = True )
@@ -33,7 +50,7 @@ def test_tinypages(tmp_path):
33
50
out , err = proc .communicate ()
34
51
35
52
# Build the pages with warnings turned into errors
36
- build_sphinx_html (tmp_path , doctree_dir , html_dir )
53
+ _build_sphinx_html (tmp_path , doctree_dir , html_dir )
37
54
38
55
def plot_file (num ):
39
56
return img_dir / f'some_plots-{ num } .png'
@@ -82,7 +99,7 @@ def plot_directive_file(num):
82
99
# Build the pages again and check that the modified file was updated
83
100
modification_times = [plot_directive_file (i ).stat ().st_mtime
84
101
for i in (1 , 2 , 3 , 5 )]
85
- build_sphinx_html (tmp_path , doctree_dir , html_dir )
102
+ _build_sphinx_html (tmp_path , doctree_dir , html_dir )
86
103
assert filecmp .cmp (range_4 , plot_file (17 ))
87
104
# Check that the plots in the plot_directive folder weren't changed.
88
105
# (plot_directive_file(1) won't be modified, but it will be copied to html/
@@ -111,13 +128,13 @@ def test_plot_html_show_source_link(tmp_path):
111
128
""" )
112
129
# Make sure source scripts are created by default
113
130
html_dir1 = tmp_path / '_build' / 'html1'
114
- build_sphinx_html (tmp_path , doctree_dir , html_dir1 )
131
+ _build_sphinx_html (tmp_path , doctree_dir , html_dir1 )
115
132
assert len (list (html_dir1 .glob ("**/index-1.py" ))) == 1
116
133
# Make sure source scripts are NOT created when
117
134
# plot_html_show_source_link` is False
118
135
html_dir2 = tmp_path / '_build' / 'html2'
119
- build_sphinx_html (tmp_path , doctree_dir , html_dir2 ,
120
- extra_args = ['-D' , 'plot_html_show_source_link=0' ])
136
+ _build_sphinx_html (tmp_path , doctree_dir , html_dir2 ,
137
+ extra_args = ['-D' , 'plot_html_show_source_link=0' ])
121
138
assert len (list (html_dir2 .glob ("**/index-1.py" ))) == 0
122
139
123
140
@@ -136,7 +153,7 @@ def test_show_source_link_true(tmp_path, plot_html_show_source_link):
136
153
plt.plot(range(2))
137
154
""" )
138
155
html_dir = tmp_path / '_build' / 'html'
139
- build_sphinx_html (tmp_path , doctree_dir , html_dir , extra_args = [
156
+ _build_sphinx_html (tmp_path , doctree_dir , html_dir , extra_args = [
140
157
'-D' , f'plot_html_show_source_link={ plot_html_show_source_link } ' ])
141
158
assert len (list (html_dir .glob ("**/index-1.py" ))) == 1
142
159
@@ -156,23 +173,6 @@ def test_show_source_link_false(tmp_path, plot_html_show_source_link):
156
173
plt.plot(range(2))
157
174
""" )
158
175
html_dir = tmp_path / '_build' / 'html'
159
- build_sphinx_html (tmp_path , doctree_dir , html_dir , extra_args = [
176
+ _build_sphinx_html (tmp_path , doctree_dir , html_dir , extra_args = [
160
177
'-D' , f'plot_html_show_source_link={ plot_html_show_source_link } ' ])
161
178
assert len (list (html_dir .glob ("**/index-1.py" ))) == 0
162
-
163
-
164
- def build_sphinx_html (tmp_path , doctree_dir , html_dir , extra_args = None ):
165
- # Build the pages with warnings turned into errors
166
- extra_args = [] if extra_args is None else extra_args
167
- cmd = [sys .executable , '-msphinx' , '-W' , '-b' , 'html' ,
168
- '-d' , str (doctree_dir ), str (tmp_path ), str (html_dir ), * extra_args ]
169
- proc = Popen (cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True ,
170
- env = {** os .environ , "MPLBACKEND" : "" })
171
- out , err = proc .communicate ()
172
-
173
- assert proc .returncode == 0 , \
174
- f"sphinx build failed with stdout:\n { out } \n stderr:\n { err } \n "
175
- if err :
176
- pytest .fail (f"sphinx build emitted the following warnings:\n { err } " )
177
-
178
- assert html_dir .is_dir ()
0 commit comments