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

Commitec90d87

Browse files
committed
TST: use our subprocess helper
1 parent78657d4 commitec90d87

File tree

8 files changed

+39
-27
lines changed

8 files changed

+39
-27
lines changed

‎lib/matplotlib/tests/test_backend_nbagg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
importos
22
frompathlibimportPath
3-
importsubprocess
3+
44
fromtempfileimportTemporaryDirectory
55

66
importpytest
77

8+
frommatplotlib.testingimportsubprocess_run_for_testing
9+
810
nbformat=pytest.importorskip('nbformat')
911
pytest.importorskip('nbconvert')
1012
pytest.importorskip('ipykernel')
@@ -17,7 +19,7 @@ def test_ipynb():
1719

1820
withTemporaryDirectory()astmpdir:
1921
out_path=Path(tmpdir,"out.ipynb")
20-
subprocess.check_call(
22+
subprocess_run_for_testing(
2123
["jupyter","nbconvert","--to","notebook",
2224
"--execute","--ExecutePreprocessor.timeout=500",
2325
"--output",str(out_path),str(nb_path)],

‎lib/matplotlib/tests/test_backend_webagg.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
importsubprocess
21
importos
32
importsys
43
importpytest
54
importmatplotlib.backends.backend_webagg_core
65

6+
frommatplotlib.testingimportsubprocess_run_for_testing
7+
78

89
@pytest.mark.parametrize("backend", ["webagg","nbagg"])
910
deftest_webagg_fallback(backend):
@@ -23,9 +24,9 @@ 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(
28+
[sys.executable,"-c",test_code],env=env,check=True
29+
)
2930

3031

3132
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
importmatplotlib.testing.compare
1313
frommatplotlibimportpyplotasplt
1414
frommatplotlib.testing._markersimportneeds_ghostscript,needs_usetex
15+
frommatplotlib.testingimportsubprocess_run_for_testing
1516

1617

1718
def_save_figure(objects='mhi',fmt="pdf",usetex=False):
@@ -89,12 +90,12 @@ def test_determinism_check(objects, fmt, usetex):
8990
Output format.
9091
"""
9192
plots= [
92-
subprocess.check_output(
93+
subprocess_run_for_testing(
9394
[sys.executable,"-R","-c",
9495
f"from matplotlib.tests.test_determinism import _save_figure;"
9596
f"_save_figure({objects!r},{fmt!r},{usetex})"],
9697
env={**os.environ,"SOURCE_DATE_EPOCH":"946684800",
97-
"MPLBACKEND":"Agg"})
98+
"MPLBACKEND":"Agg"},text=False,capture_output=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"},stdout=subprocess.PIPE,text=False).stdout
138139
assertstringinbuf

‎lib/matplotlib/tests/test_font_manager.py

Lines changed: 5 additions & 5 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,11 +276,10 @@ def bad_idea(n):
275276

276277
deftest_fontcache_thread_safe():
277278
pytest.importorskip('threading')
278-
importinspect
279279

280-
proc=subprocess.run(
281-
[sys.executable,"-c",
282-
inspect.getsource(_test_threading)+'\n_test_threading()']
280+
proc=subprocess_run_helper(
281+
_test_threading,
282+
timeout=10
283283
)
284284
ifproc.returncode:
285285
pytest.fail("The subprocess returned with non-zero exit status "

‎lib/matplotlib/tests/test_matplotlib.py

Lines changed: 6 additions & 3 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"],
@@ -74,4 +75,6 @@ def test_importable_with__OO():
7475
"import matplotlib.patches as mpatches"
7576
)
7677
cmd= [sys.executable,"-OO","-c",program]
77-
assertsubprocess.call(cmd,env={**os.environ,"MPLBACKEND":""})==0
78+
subprocess_run_for_testing(
79+
cmd,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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
importos
22
frompathlibimportPath
33
importre
4-
importsubprocess
4+
55
importsys
66

77
importmatplotlib.pyplotasplt
88
frommatplotlib.texmanagerimportTexManager
99
frommatplotlib.testing._markersimportneeds_usetex
1010
importpytest
1111

12+
frommatplotlib.testingimportsubprocess_run_for_testing
13+
1214

1315
deftest_fontconfig_preamble():
1416
"""Test that the preamble is included in the source."""
@@ -64,11 +66,11 @@ def test_unicode_characters():
6466

6567
@needs_usetex
6668
deftest_openin_any_paranoid():
67-
completed=subprocess.run(
69+
completed=subprocess_run_for_testing(
6870
[sys.executable,"-c",
6971
'import matplotlib.pyplot as plt;'
7072
'plt.rcParams.update({"text.usetex": True});'
7173
'plt.title("paranoid");'
7274
'plt.show(block=False);'],
7375
env={**os.environ,'openin_any':'p'},check=True,capture_output=True)
74-
assertcompleted.stderr==b""
76+
assertcompleted.stderr==""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp