@@ -122,7 +122,10 @@ def test_plot_html_show_source_link(tmpdir):
122
122
assert "index-1.py" not in [p .name for p in html_dir2 .iterdir ()]
123
123
124
124
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.
126
129
source_dir = Path (tmpdir ) / 'src'
127
130
source_dir .mkdir ()
128
131
parent = Path (__file__ ).parent
@@ -135,19 +138,16 @@ def test_show_source_link_true(tmpdir):
135
138
136
139
plt.plot(range(2))
137
140
""" )
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 ()]
148
145
149
146
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.
151
151
source_dir = Path (tmpdir ) / 'src'
152
152
source_dir .mkdir ()
153
153
parent = Path (__file__ ).parent
@@ -160,16 +160,10 @@ def test_show_source_link_false(tmpdir):
160
160
161
161
plt.plot(range(2))
162
162
""" )
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 ()]
173
167
174
168
175
169
def build_sphinx_html (source_dir , doctree_dir , html_dir , extra_args = None ):
0 commit comments