@@ -122,6 +122,56 @@ 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 ):
126
+ source_dir = Path (tmpdir ) / 'src'
127
+ source_dir .mkdir ()
128
+ parent = Path (__file__ ).parent
129
+ shutil .copyfile (parent / 'tinypages/conf.py' , source_dir / 'conf.py' )
130
+ shutil .copytree (parent / 'tinypages/_static' , source_dir / '_static' )
131
+ doctree_dir = source_dir / 'doctrees'
132
+ (source_dir / 'index.rst' ).write_text ("""
133
+ .. plot::
134
+ :show-source-link: true
135
+
136
+ plt.plot(range(2))
137
+ """ )
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 ()]
148
+
149
+
150
+ def test_show_source_link_false (tmpdir ):
151
+ source_dir = Path (tmpdir ) / 'src'
152
+ source_dir .mkdir ()
153
+ parent = Path (__file__ ).parent
154
+ shutil .copyfile (parent / 'tinypages/conf.py' , source_dir / 'conf.py' )
155
+ shutil .copytree (parent / 'tinypages/_static' , source_dir / '_static' )
156
+ doctree_dir = source_dir / 'doctrees'
157
+ (source_dir / 'index.rst' ).write_text ("""
158
+ .. plot::
159
+ :show-source-link: false
160
+
161
+ plt.plot(range(2))
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 ()]
173
+
174
+
125
175
def build_sphinx_html (source_dir , doctree_dir , html_dir , extra_args = None ):
126
176
# Build the pages with warnings turned into errors
127
177
extra_args = [] if extra_args is None else extra_args
0 commit comments