Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f011be

Browse files
committed
Remove source_dir
1 parent02f27cc commit3f011be

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

‎lib/matplotlib/tests/test_sphinxext.py

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616

1717
deftest_tinypages(tmp_path):
18-
source_dir=tmp_path/'src'
19-
shutil.copytree(Path(__file__).parent/'tinypages',source_dir)
20-
html_dir=source_dir/'_build'/'html'
21-
doctree_dir=source_dir/'doctrees'
18+
shutil.copytree(Path(__file__).parent/'tinypages',tmp_path,
19+
dirs_exist_ok=True)
20+
html_dir=tmp_path/'_build'/'html'
21+
doctree_dir=tmp_path/'doctrees'
2222
# Build the pages with warnings turned into errors
2323
cmd= [sys.executable,'-msphinx','-W','-b','html',
2424
'-d',str(doctree_dir),
@@ -32,7 +32,7 @@ def test_tinypages(tmp_path):
3232
out,err=proc.communicate()
3333

3434
# Build the pages with warnings turned into errors
35-
build_sphinx_html(source_dir,doctree_dir,html_dir)
35+
build_sphinx_html(tmp_path,doctree_dir,html_dir)
3636

3737
defplot_file(num):
3838
returnhtml_dir/f'some_plots-{num}.png'
@@ -75,13 +75,13 @@ def plot_directive_file(num):
7575
assertfilecmp.cmp(range_6,plot_file(17))
7676

7777
# Modify the included plot
78-
contents= (source_dir/'included_plot_21.rst').read_bytes()
78+
contents= (tmp_path/'included_plot_21.rst').read_bytes()
7979
contents=contents.replace(b'plt.plot(range(6))',b'plt.plot(range(4))')
80-
(source_dir/'included_plot_21.rst').write_bytes(contents)
80+
(tmp_path/'included_plot_21.rst').write_bytes(contents)
8181
# Build the pages again and check that the modified file was updated
8282
modification_times= [plot_directive_file(i).stat().st_mtime
8383
foriin (1,2,3,5)]
84-
build_sphinx_html(source_dir,doctree_dir,html_dir)
84+
build_sphinx_html(tmp_path,doctree_dir,html_dir)
8585
assertfilecmp.cmp(range_4,plot_file(17))
8686
# Check that the plots in the plot_directive folder weren't changed.
8787
# (plot_directive_file(1) won't be modified, but it will be copied to html/
@@ -99,25 +99,23 @@ def plot_directive_file(num):
9999

100100

101101
deftest_plot_html_show_source_link(tmp_path):
102-
source_dir=tmp_path/'src'
103-
source_dir.mkdir()
104102
parent=Path(__file__).parent
105-
shutil.copyfile(parent/'tinypages/conf.py',source_dir/'conf.py')
106-
shutil.copytree(parent/'tinypages/_static',source_dir/'_static')
107-
doctree_dir=source_dir/'doctrees'
108-
(source_dir/'index.rst').write_text("""
103+
shutil.copyfile(parent/'tinypages/conf.py',tmp_path/'conf.py')
104+
shutil.copytree(parent/'tinypages/_static',tmp_path/'_static')
105+
doctree_dir=tmp_path/'doctrees'
106+
(tmp_path/'index.rst').write_text("""
109107
.. plot::
110108
111109
plt.plot(range(2))
112110
""")
113111
# Make sure source scripts are created by default
114-
html_dir1=source_dir/'_build'/'html1'
115-
build_sphinx_html(source_dir,doctree_dir,html_dir1)
112+
html_dir1=tmp_path/'_build'/'html1'
113+
build_sphinx_html(tmp_path,doctree_dir,html_dir1)
116114
assert"index-1.py"in [p.nameforpinhtml_dir1.iterdir()]
117115
# Make sure source scripts are NOT created when
118116
# plot_html_show_source_link` is False
119-
html_dir2=source_dir/'_build'/'html2'
120-
build_sphinx_html(source_dir,doctree_dir,html_dir2,
117+
html_dir2=tmp_path/'_build'/'html2'
118+
build_sphinx_html(tmp_path,doctree_dir,html_dir2,
121119
extra_args=['-D','plot_html_show_source_link=0'])
122120
assert"index-1.py"notin [p.nameforpinhtml_dir2.iterdir()]
123121

@@ -126,20 +124,18 @@ def test_plot_html_show_source_link(tmp_path):
126124
deftest_show_source_link_true(tmp_path,plot_html_show_source_link):
127125
# Test that a source link is generated if :show-source-link: is true,
128126
# whether or not plot_html_show_source_link is true.
129-
source_dir=tmp_path/'src'
130-
source_dir.mkdir()
131127
parent=Path(__file__).parent
132-
shutil.copyfile(parent/'tinypages/conf.py',source_dir/'conf.py')
133-
shutil.copytree(parent/'tinypages/_static',source_dir/'_static')
134-
doctree_dir=source_dir/'doctrees'
135-
(source_dir/'index.rst').write_text("""
128+
shutil.copyfile(parent/'tinypages/conf.py',tmp_path/'conf.py')
129+
shutil.copytree(parent/'tinypages/_static',tmp_path/'_static')
130+
doctree_dir=tmp_path/'doctrees'
131+
(tmp_path/'index.rst').write_text("""
136132
.. plot::
137133
:show-source-link: true
138134
139135
plt.plot(range(2))
140136
""")
141-
html_dir=source_dir/'_build'/'html'
142-
build_sphinx_html(source_dir,doctree_dir,html_dir,extra_args=[
137+
html_dir=tmp_path/'_build'/'html'
138+
build_sphinx_html(tmp_path,doctree_dir,html_dir,extra_args=[
143139
'-D',f'plot_html_show_source_link={plot_html_show_source_link}'])
144140
assert"index-1.py"in [p.nameforpinhtml_dir.iterdir()]
145141

@@ -148,29 +144,27 @@ def test_show_source_link_true(tmp_path, plot_html_show_source_link):
148144
deftest_show_source_link_false(tmp_path,plot_html_show_source_link):
149145
# Test that a source link is NOT generated if :show-source-link: is false,
150146
# whether or not plot_html_show_source_link is true.
151-
source_dir=tmp_path/'src'
152-
source_dir.mkdir()
153147
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("""
148+
shutil.copyfile(parent/'tinypages/conf.py',tmp_path/'conf.py')
149+
shutil.copytree(parent/'tinypages/_static',tmp_path/'_static')
150+
doctree_dir=tmp_path/'doctrees'
151+
(tmp_path/'index.rst').write_text("""
158152
.. plot::
159153
:show-source-link: false
160154
161155
plt.plot(range(2))
162156
""")
163-
html_dir=source_dir/'_build'/'html'
164-
build_sphinx_html(source_dir,doctree_dir,html_dir,extra_args=[
157+
html_dir=tmp_path/'_build'/'html'
158+
build_sphinx_html(tmp_path,doctree_dir,html_dir,extra_args=[
165159
'-D',f'plot_html_show_source_link={plot_html_show_source_link}'])
166160
assert"index-1.py"notin [p.nameforpinhtml_dir.iterdir()]
167161

168162

169-
defbuild_sphinx_html(source_dir,doctree_dir,html_dir,extra_args=None):
163+
defbuild_sphinx_html(tmp_path,doctree_dir,html_dir,extra_args=None):
170164
# Build the pages with warnings turned into errors
171165
extra_args= []ifextra_argsisNoneelseextra_args
172166
cmd= [sys.executable,'-msphinx','-W','-b','html',
173-
'-d',str(doctree_dir),str(source_dir),str(html_dir),*extra_args]
167+
'-d',str(doctree_dir),str(tmp_path),str(html_dir),*extra_args]
174168
proc=Popen(cmd,stdout=PIPE,stderr=PIPE,universal_newlines=True,
175169
env={**os.environ,"MPLBACKEND":""})
176170
out,err=proc.communicate()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp