Skip to content

Commit ccb1229

Browse files
committed
Refactor tests
1 parent 8fae504 commit ccb1229

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

lib/matplotlib/tests/test_sphinxext.py

+16-22
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def test_plot_html_show_source_link(tmpdir):
122122
assert "index-1.py" not in [p.name for p in html_dir2.iterdir()]
123123

124124

125-
def test_show_source_link_true(tmpdir):
125+
@pytest.mark.parametrize('plot_html_show_source_link', [0, 1])
126+
def test_show_source_link_true(tmpdir, plot_html_show_source_link):
127+
# Test that a source link is generated if :show-source-link: is true,
128+
# whether or not plot_html_show_source_link is true.
126129
source_dir = Path(tmpdir) / 'src'
127130
source_dir.mkdir()
128131
parent = Path(__file__).parent
@@ -135,19 +138,16 @@ def test_show_source_link_true(tmpdir):
135138
136139
plt.plot(range(2))
137140
""")
138-
# Make sure source scripts are created by default
139-
html_dir1 = source_dir / '_build' / 'html1'
140-
build_sphinx_html(source_dir, doctree_dir, html_dir1)
141-
assert "index-1.py" in [p.name for p in html_dir1.iterdir()]
142-
# Make sure source scripts are still created when
143-
# plot_html_show_source_link` is False
144-
html_dir2 = source_dir / '_build' / 'html2'
145-
build_sphinx_html(source_dir, doctree_dir, html_dir2,
146-
extra_args=['-D', 'plot_html_show_source_link=0'])
147-
assert "index-1.py" in [p.name for p in html_dir1.iterdir()]
141+
html_dir = source_dir / '_build' / 'html'
142+
build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=[
143+
'-D', f'plot_html_show_source_link={plot_html_show_source_link}'])
144+
assert "index-1.py" in [p.name for p in html_dir.iterdir()]
148145

149146

150-
def test_show_source_link_false(tmpdir):
147+
@pytest.mark.parametrize('plot_html_show_source_link', [0, 1])
148+
def test_show_source_link_false(tmpdir, plot_html_show_source_link):
149+
# Test that a source link is NOT generated if :show-source-link: is false,
150+
# whether or not plot_html_show_source_link is true.
151151
source_dir = Path(tmpdir) / 'src'
152152
source_dir.mkdir()
153153
parent = Path(__file__).parent
@@ -160,16 +160,10 @@ def test_show_source_link_false(tmpdir):
160160
161161
plt.plot(range(2))
162162
""")
163-
# Make sure source scripts are NOT created
164-
html_dir1 = source_dir / '_build' / 'html1'
165-
build_sphinx_html(source_dir, doctree_dir, html_dir1)
166-
assert "index-1.py" not in [p.name for p in html_dir1.iterdir()]
167-
# Make sure source scripts are still NOT created when
168-
# plot_html_show_source_link` is False
169-
html_dir2 = source_dir / '_build' / 'html2'
170-
build_sphinx_html(source_dir, doctree_dir, html_dir2,
171-
extra_args=['-D', 'plot_html_show_source_link=0'])
172-
assert "index-1.py" not in [p.name for p in html_dir2.iterdir()]
163+
html_dir = source_dir / '_build' / 'html'
164+
build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=[
165+
'-D', f'plot_html_show_source_link={plot_html_show_source_link}'])
166+
assert "index-1.py" not in [p.name for p in html_dir.iterdir()]
173167

174168

175169
def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):

0 commit comments

Comments
 (0)