8000 MNT: privatize testing helper function · matplotlib/matplotlib@f2b11b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2b11b5

Browse files
committed
MNT: privatize testing helper function
1 parent 496888c commit f2b11b5

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
minversion=None if sys.version_info < (3, 10) else '4.1.3')
1515

1616

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}\nstderr:\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+
1734
def test_tinypages(tmp_path):
1835
shutil.copytree(Path(__file__).parent / 'tinypages', tmp_path,
1936
dirs_exist_ok=True)
@@ -33,7 +50,7 @@ def test_tinypages(tmp_path):
3350
out, err = proc.communicate()
3451

3552
# 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)
3754

3855
def plot_file(num):
3956
return img_dir / f'some_plots-{num}.png'
@@ -82,7 +99,7 @@ def plot_directive_file(num):
8299
# Build the pages again and check that the modified file was updated
83100
modification_times = [plot_directive_file(i).stat().st_mtime
84101
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)
86103
assert filecmp.cmp(range_4, plot_file(17))
87104
# Check that the plots in the plot_directive folder weren't changed.
88105
# (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):
111128
""")
112129
# Make sure source scripts are created by default
113130
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)
115132
assert len(list(html_dir1.glob("**/index-1.py"))) == 1
116133
# Make sure source scripts are NOT created when
117134
# plot_html_show_source_link` is False
118135
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'])
121138
assert len(list(html_dir2.glob("**/index-1.py"))) == 0
122139

123140

@@ -136,7 +153,7 @@ def test_show_source_link_true(tmp_path, plot_html_show_source_link):
136153
plt.plot(range(2))
137154
""")
138155
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=[
140157
'-D', f'plot_html_show_source_link={plot_html_show_source_link}'])
141158
assert len(list(html_dir.glob("**/index-1.py"))) == 1
142159

@@ -156,23 +173,6 @@ def test_show_source_link_false(tmp_path, plot_html_show_source_link):
156173
plt.plot(range(2))
157174
""")
158175
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=[
160177
'-D', f'plot_html_show_source_link={plot_html_show_source_link}'])
161178
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}\nstderr:\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

Comments
 (0)
0