@@ -95,16 +95,28 @@ def plot_directive_file(num):
9595 # contents are the same)
9696 assert plot_directive_file (5 ).stat ().st_mtime > modification_times [3 ]
9797 assert filecmp .cmp (range_6 , plot_file (5 ))
98- # Make sure that source scripts are generated by default
99- assert "some_plots-1.py" in [p .name for p in html_dir .iterdir ()]
100- # Make sure that source scripts are NOT generated when
101- # `plot_html_show_source_link` is set to False
102- html_dir = source_dir / '_build' / 'html_no_source'
103- # `plot_html_show_source_link=0` is equivalent to
104- # `plot_html_show_source_link=False`
105- build_sphinx_html (source_dir , doctree_dir , html_dir ,
98+
99+
100+ def test_plot_html_show_source_link (tmpdir ):
101+ source_dir = Path (tmpdir ) / 'src'
102+ source_dir .mkdir ()
103+ shutil .copyfile (Path (__file__ ).parent / 'tinypages' / "conf.py" , source_dir / "conf.py" )
104+ shutil .copytree (Path (__file__ ).parent / 'tinypages' / "_static" , source_dir / "_static" )
105+ doctree_dir = source_dir / 'doctrees'
106+ (source_dir / 'index.rst' ).write_text ("""
107+ .. plot::
108+
109+ plt.plot(range(4))
110+ """ )
111+ # Make sure source scripts are created by default
112+ html_dir1 = source_dir / '_build' / 'html1'
113+ build_sphinx_html (source_dir , doctree_dir , html_dir1 )
114+ assert "index-1.py" in [p .name for p in html_dir1 .iterdir ()]
115+ # Make sure source scripts are NOT created when `plot_html_show_source_link` is False
116+ html_dir2 = source_dir / '_build' / 'html2'
117+ build_sphinx_html (source_dir , doctree_dir , html_dir2 ,
106118 extra_args = ["-D" , "plot_html_show_source_link=0" ])
107- assert "some_plots -1.py" not in [p .name for p in html_dir .iterdir ()]
119+ assert "index -1.py" not in [p .name for p in html_dir2 .iterdir ()]
108120
109121
110122def build_sphinx_html (source_dir , doctree_dir , html_dir , extra_args = None ):
0 commit comments