Skip to content

Commit 27c3dc9

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 parents c6fd37d + 0515861 commit 27c3dc9

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-
def subprocess_run_for_testing(command, env=None, timeout=None, stdout=None,
53+
def subprocess_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
import os
22
from pathlib import Path
3-
import subprocess
43
from tempfile import TemporaryDirectory
54

65
import pytest
76

7+
from matplotlib.testing import subprocess_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
with TemporaryDirectory() as tmpdir:
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
with out_path.open() as out:
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-
import subprocess
21
import os
32
import sys
43
import pytest
4+
55
import matplotlib.backends.backend_webagg_core
6+
from matplotlib.testing import subprocess_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-
assert ret == 0
27+
subprocess_run_for_testing([sys.executable, "-c", test_code], env=env, check=True)
2928

3029

3130
def test_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
import builtins
22
import os
3-
import subprocess
43
import sys
54
import textwrap
65

6+
from matplotlib.testing import subprocess_run_for_testing
7+
78

89
def test_simple():
910
assert 1 + 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
import os
6-
import subprocess
76
import sys
87

98
import pytest
@@ -12,6 +11,7 @@
1211
import matplotlib.testing.compare
1312
from matplotlib import pyplot as plt
1413
from matplotlib.testing._markers import needs_ghostscript, needs_usetex
14+
from matplotlib.testing import subprocess_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 _ in range(3)
99100
]
100101
for p in plots[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
assert string in buf

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
from pathlib import Path
66
from PIL import Image
77
import shutil
8-
import subprocess
98
import sys
109
import warnings
1110

@@ -17,6 +16,8 @@
1716
json_dump, json_load, get_font, is_opentype_cff_font,
1817
MSUserFontDirectories, _get_fontconfig_fonts, ttfFontProperty)
1918
from matplotlib import cbook, ft2font, pyplot as plt, rc_context, figure as mfigure
19+
from matplotlib.testing import subprocess_run_helper
20+
2021

2122
has_fclist = shutil.which('fc-list') is not None
2223

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

276277
def test_fontcache_thread_safe():
277278
pytest.importorskip('threading')
278-
import inspect
279-
280-
proc = subprocess.run(
281-
[sys.executable, "-c",
282-
inspect.getsource(_test_threading) + '\n_test_threading()']
283-
)
284-
if proc.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
def test_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
import pytest
66

77
import matplotlib
8+
from matplotlib.testing import subprocess_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
def test_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-
assert subprocess.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+
from matplotlib.testing import subprocess_run_for_testing
3233

3334

3435
def test_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
with pytest.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
def test_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
assert backend.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
import os
22
from pathlib import Path
33
import re
4-
import subprocess
54
import sys
65

6+
import pytest
7+
78
import matplotlib.pyplot as plt
8-
from matplotlib.texmanager import TexManager
9+
from matplotlib.testing import subprocess_run_for_testing
910
from matplotlib.testing._markers import needs_usetex
10-
import pytest
11+
from matplotlib.texmanager import TexManager
1112

1213

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

6566
@needs_usetex
6667
def test_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-
assert completed.stderr == b""
75+
assert completed.stderr == ""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy