@@ -97,10 +97,35 @@ def plot_directive_file(num):
9797 assert filecmp .cmp (range_6 , plot_file (5 ))
9898
9999
100- def build_sphinx_html (source_dir , doctree_dir , html_dir ):
100+ def test_plot_html_show_source_link (tmpdir ):
101+ source_dir = Path (tmpdir ) / 'src'
102+ source_dir .mkdir ()
103+ parent = Path (__file__ ).parent
104+ shutil .copyfile (parent / 'tinypages/conf.py' , source_dir / 'conf.py' )
105+ shutil .copytree (parent / 'tinypages/_static' , source_dir / '_static' )
106+ doctree_dir = source_dir / 'doctrees'
107+ (source_dir / 'index.rst' ).write_text ("""
108+ .. plot::
109+
110+ plt.plot(range(2))
111+ """ )
112+ # Make sure source scripts are created by default
113+ html_dir1 = source_dir / '_build' / 'html1'
114+ build_sphinx_html (source_dir , doctree_dir , html_dir1 )
115+ assert "index-1.py" in [p .name for p in html_dir1 .iterdir ()]
116+ # Make sure source scripts are NOT created when
117+ # plot_html_show_source_link` is False
118+ html_dir2 = source_dir / '_build' / 'html2'
119+ build_sphinx_html (source_dir , doctree_dir , html_dir2 ,
120+ extra_args = ['-D' , 'plot_html_show_source_link=0' ])
121+ assert "index-1.py" not in [p .name for p in html_dir2 .iterdir ()]
122+
123+
124+ def build_sphinx_html (source_dir , doctree_dir , html_dir , extra_args = None ):
101125 # Build the pages with warnings turned into errors
126+ extra_args = [] if extra_args is None else extra_args
102127 cmd = [sys .executable , '-msphinx' , '-W' , '-b' , 'html' ,
103- '-d' , str (doctree_dir ), str (source_dir ), str (html_dir )]
128+ '-d' , str (doctree_dir ), str (source_dir ), str (html_dir ), * extra_args ]
104129 proc = Popen (cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True ,
105130 env = {** os .environ , "MPLBACKEND" : "" })
106131 out , err = proc .communicate ()
0 commit comments