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

Commit27c3dc9

Browse files
authored
Merge pull request#27726 from tacaswell/tst/finite_tests
TST: always set a (long) timeout for subprocess and always use our wrapper
2 parentsc6fd37d +0515861 commit27c3dc9

File tree

9 files changed

+41
-38
lines changed

9 files changed

+41
-38
lines changed

‎lib/matplotlib/testing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def setup():
5050
set_reproducibility_for_testing()
5151

5252

53-
defsubprocess_run_for_testing(command,env=None,timeout=None,stdout=None,
53+
defsubprocess_run_for_testing(command,env=None,timeout=60,stdout=None,
5454
stderr=None,check=False,text=True,
5555
capture_output=False):
5656
"""

‎lib/matplotlib/tests/test_backend_nbagg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
importos
22
frompathlibimportPath
3-
importsubprocess
43
fromtempfileimportTemporaryDirectory
54

65
importpytest
76

7+
frommatplotlib.testingimportsubprocess_run_for_testing
8+
89
nbformat=pytest.importorskip('nbformat')
910
pytest.importorskip('nbconvert')
1011
pytest.importorskip('ipykernel')
@@ -17,11 +18,12 @@ def test_ipynb():
1718

1819
withTemporaryDirectory()astmpdir:
1920
out_path=Path(tmpdir,"out.ipynb")
20-
subprocess.check_call(
21+
subprocess_run_for_testing(
2122
["jupyter","nbconvert","--to","notebook",
2223
"--execute","--ExecutePreprocessor.timeout=500",
2324
"--output",str(out_path),str(nb_path)],
24-
env={**os.environ,"IPYTHONDIR":tmpdir})
25+
env={**os.environ,"IPYTHONDIR":tmpdir},
26+
check=True)
2527
without_path.open()asout:
2628
nb=nbformat.read(out,nbformat.current_nbformat)
2729

‎lib/matplotlib/tests/test_backend_webagg.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
importsubprocess
21
importos
32
importsys
43
importpytest
4+
55
importmatplotlib.backends.backend_webagg_core
6+
frommatplotlib.testingimportsubprocess_run_for_testing
67

78

89
@pytest.mark.parametrize("backend", ["webagg","nbagg"])
@@ -23,9 +24,7 @@ def test_webagg_fallback(backend):
2324
+"print(plt.get_backend());"
2425
f"assert '{backend}' == plt.get_backend().lower();"
2526
)
26-
ret=subprocess.call([sys.executable,"-c",test_code],env=env)
27-
28-
assertret==0
27+
subprocess_run_for_testing([sys.executable,"-c",test_code],env=env,check=True)
2928

3029

3130
deftest_webagg_core_no_toolbar():

‎lib/matplotlib/tests/test_basic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
importbuiltins
22
importos
3-
importsubprocess
43
importsys
54
importtextwrap
65

6+
frommatplotlib.testingimportsubprocess_run_for_testing
7+
78

89
deftest_simple():
910
assert1+1==2
@@ -41,6 +42,7 @@ def test_lazy_imports():
4142
assert 'urllib.request' not in sys.modules
4243
""")
4344

44-
subprocess.check_call(
45+
subprocess_run_for_testing(
4546
[sys.executable,'-c',source],
46-
env={**os.environ,"MPLBACKEND":"","MATPLOTLIBRC":os.devnull})
47+
env={**os.environ,"MPLBACKEND":"","MATPLOTLIBRC":os.devnull},
48+
check=True)

‎lib/matplotlib/tests/test_determinism.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
importos
6-
importsubprocess
76
importsys
87

98
importpytest
@@ -12,6 +11,7 @@
1211
importmatplotlib.testing.compare
1312
frommatplotlibimportpyplotasplt
1413
frommatplotlib.testing._markersimportneeds_ghostscript,needs_usetex
14+
frommatplotlib.testingimportsubprocess_run_for_testing
1515

1616

1717
def_save_figure(objects='mhi',fmt="pdf",usetex=False):
@@ -89,12 +89,13 @@ def test_determinism_check(objects, fmt, usetex):
8989
Output format.
9090
"""
9191
plots= [
92-
subprocess.check_output(
92+
subprocess_run_for_testing(
9393
[sys.executable,"-R","-c",
9494
f"from matplotlib.tests.test_determinism import _save_figure;"
9595
f"_save_figure({objects!r},{fmt!r},{usetex})"],
9696
env={**os.environ,"SOURCE_DATE_EPOCH":"946684800",
97-
"MPLBACKEND":"Agg"})
97+
"MPLBACKEND":"Agg"},
98+
text=False,capture_output=True,check=True).stdout
9899
for_inrange(3)
99100
]
100101
forpinplots[1:]:
@@ -129,10 +130,10 @@ def test_determinism_source_date_epoch(fmt, string):
129130
string : bytes
130131
Timestamp string for 2000-01-01 00:00 UTC.
131132
"""
132-
buf=subprocess.check_output(
133+
buf=subprocess_run_for_testing(
133134
[sys.executable,"-R","-c",
134135
f"from matplotlib.tests.test_determinism import _save_figure; "
135136
f"_save_figure('',{fmt!r})"],
136137
env={**os.environ,"SOURCE_DATE_EPOCH":"946684800",
137-
"MPLBACKEND":"Agg"})
138+
"MPLBACKEND":"Agg"},capture_output=True,text=False,check=True).stdout
138139
assertstringinbuf

‎lib/matplotlib/tests/test_font_manager.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
frompathlibimportPath
66
fromPILimportImage
77
importshutil
8-
importsubprocess
98
importsys
109
importwarnings
1110

@@ -17,6 +16,8 @@
1716
json_dump,json_load,get_font,is_opentype_cff_font,
1817
MSUserFontDirectories,_get_fontconfig_fonts,ttfFontProperty)
1918
frommatplotlibimportcbook,ft2font,pyplotasplt,rc_context,figureasmfigure
19+
frommatplotlib.testingimportsubprocess_run_helper
20+
2021

2122
has_fclist=shutil.which('fc-list')isnotNone
2223

@@ -275,15 +276,8 @@ def bad_idea(n):
275276

276277
deftest_fontcache_thread_safe():
277278
pytest.importorskip('threading')
278-
importinspect
279-
280-
proc=subprocess.run(
281-
[sys.executable,"-c",
282-
inspect.getsource(_test_threading)+'\n_test_threading()']
283-
)
284-
ifproc.returncode:
285-
pytest.fail("The subprocess returned with non-zero exit status "
286-
f"{proc.returncode}.")
279+
280+
subprocess_run_helper(_test_threading,timeout=10)
287281

288282

289283
deftest_fontentry_dataclass():

‎lib/matplotlib/tests/test_matplotlib.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
importpytest
66

77
importmatplotlib
8+
frommatplotlib.testingimportsubprocess_run_for_testing
89

910

1011
@pytest.mark.parametrize('version_str, version_tuple', [
@@ -26,7 +27,7 @@ def test_tmpconfigdir_warning(tmp_path):
2627
mode=os.stat(tmp_path).st_mode
2728
try:
2829
os.chmod(tmp_path,0)
29-
proc=subprocess.run(
30+
proc=subprocess_run_for_testing(
3031
[sys.executable,"-c","import matplotlib"],
3132
env={**os.environ,"MPLCONFIGDIR":str(tmp_path)},
3233
stderr=subprocess.PIPE,text=True,check=True)
@@ -36,7 +37,7 @@ def test_tmpconfigdir_warning(tmp_path):
3637

3738

3839
deftest_importable_with_no_home(tmp_path):
39-
subprocess.run(
40+
subprocess_run_for_testing(
4041
[sys.executable,"-c",
4142
"import pathlib; pathlib.Path.home = lambda *args: 1/0; "
4243
"import matplotlib.pyplot"],
@@ -73,5 +74,7 @@ def test_importable_with__OO():
7374
"import matplotlib.cbook as cbook; "
7475
"import matplotlib.patches as mpatches"
7576
)
76-
cmd= [sys.executable,"-OO","-c",program]
77-
assertsubprocess.call(cmd,env={**os.environ,"MPLBACKEND":""})==0
77+
subprocess_run_for_testing(
78+
[sys.executable,"-OO","-c",program],
79+
env={**os.environ,"MPLBACKEND":""},check=True
80+
)

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
validate_sketch,
3030
_validate_linestyle,
3131
_listify_validator)
32+
frommatplotlib.testingimportsubprocess_run_for_testing
3233

3334

3435
deftest_rcparams(tmp_path):
@@ -524,7 +525,7 @@ def test_backend_fallback_headless(tmp_path):
524525
"DISPLAY":"","WAYLAND_DISPLAY":"",
525526
"MPLBACKEND":"","MPLCONFIGDIR":str(tmp_path)}
526527
withpytest.raises(subprocess.CalledProcessError):
527-
subprocess.run(
528+
subprocess_run_for_testing(
528529
[sys.executable,"-c",
529530
"import matplotlib;"
530531
"matplotlib.use('tkagg');"
@@ -540,7 +541,7 @@ def test_backend_fallback_headless(tmp_path):
540541
deftest_backend_fallback_headful(tmp_path):
541542
pytest.importorskip("tkinter")
542543
env= {**os.environ,"MPLBACKEND":"","MPLCONFIGDIR":str(tmp_path)}
543-
backend=subprocess.check_output(
544+
backend=subprocess_run_for_testing(
544545
[sys.executable,"-c",
545546
"import matplotlib as mpl; "
546547
"sentinel = mpl.rcsetup._auto_backend_sentinel; "
@@ -549,7 +550,7 @@ def test_backend_fallback_headful(tmp_path):
549550
"assert mpl.rcParams._get('backend') == sentinel; "
550551
"import matplotlib.pyplot; "
551552
"print(matplotlib.get_backend())"],
552-
env=env,text=True)
553+
env=env,text=True,check=True,capture_output=True).stdout
553554
# The actual backend will depend on what's installed, but at least tkagg is
554555
# present.
555556
assertbackend.strip().lower()!="agg"

‎lib/matplotlib/tests/test_texmanager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
importos
22
frompathlibimportPath
33
importre
4-
importsubprocess
54
importsys
65

6+
importpytest
7+
78
importmatplotlib.pyplotasplt
8-
frommatplotlib.texmanagerimportTexManager
9+
frommatplotlib.testingimportsubprocess_run_for_testing
910
frommatplotlib.testing._markersimportneeds_usetex
10-
importpytest
11+
frommatplotlib.texmanagerimportTexManager
1112

1213

1314
deftest_fontconfig_preamble():
@@ -64,11 +65,11 @@ def test_unicode_characters():
6465

6566
@needs_usetex
6667
deftest_openin_any_paranoid():
67-
completed=subprocess.run(
68+
completed=subprocess_run_for_testing(
6869
[sys.executable,"-c",
6970
'import matplotlib.pyplot as plt;'
7071
'plt.rcParams.update({"text.usetex": True});'
7172
'plt.title("paranoid");'
7273
'plt.show(block=False);'],
7374
env={**os.environ,'openin_any':'p'},check=True,capture_output=True)
74-
assertcompleted.stderr==b""
75+
assertcompleted.stderr==""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp