diff --git a/lib/matplotlib/testing/__init__.py b/lib/matplotlib/testing/__init__.py index d740b625b7c1..685b98cd99ec 100644 --- a/lib/matplotlib/testing/__init__.py +++ b/lib/matplotlib/testing/__init__.py @@ -50,7 +50,7 @@ def setup(): set_reproducibility_for_testing() -def subprocess_run_for_testing(command, env=None, timeout=None, stdout=None, +def subprocess_run_for_testing(command, env=None, timeout=60, stdout=None, stderr=None, check=False, text=True, capture_output=False): """ diff --git a/lib/matplotlib/tests/test_backend_nbagg.py b/lib/matplotlib/tests/test_backend_nbagg.py index 4ebf3e1f56d1..40bee8f85c43 100644 --- a/lib/matplotlib/tests/test_backend_nbagg.py +++ b/lib/matplotlib/tests/test_backend_nbagg.py @@ -1,10 +1,11 @@ import os from pathlib import Path -import subprocess from tempfile import TemporaryDirectory import pytest +from matplotlib.testing import subprocess_run_for_testing + nbformat = pytest.importorskip('nbformat') pytest.importorskip('nbconvert') pytest.importorskip('ipykernel') @@ -17,11 +18,12 @@ def test_ipynb(): with TemporaryDirectory() as tmpdir: out_path = Path(tmpdir, "out.ipynb") - subprocess.check_call( + subprocess_run_for_testing( ["jupyter", "nbconvert", "--to", "notebook", "--execute", "--ExecutePreprocessor.timeout=500", "--output", str(out_path), str(nb_path)], - env={**os.environ, "IPYTHONDIR": tmpdir}) + env={**os.environ, "IPYTHONDIR": tmpdir}, + check=True) with out_path.open() as out: nb = nbformat.read(out, nbformat.current_nbformat) diff --git a/lib/matplotlib/tests/test_backend_webagg.py b/lib/matplotlib/tests/test_backend_webagg.py index 237a279c6352..1d6769494ef9 100644 --- a/lib/matplotlib/tests/test_backend_webagg.py +++ b/lib/matplotlib/tests/test_backend_webagg.py @@ -1,8 +1,9 @@ -import subprocess import os import sys import pytest + import matplotlib.backends.backend_webagg_core +from matplotlib.testing import subprocess_run_for_testing @pytest.mark.parametrize("backend", ["webagg", "nbagg"]) @@ -23,9 +24,7 @@ def test_webagg_fallback(backend): + "print(plt.get_backend());" f"assert '{backend}' == plt.get_backend().lower();" ) - ret = subprocess.call([sys.executable, "-c", test_code], env=env) - - assert ret == 0 + subprocess_run_for_testing([sys.executable, "-c", test_code], env=env, check=True) def test_webagg_core_no_toolbar(): diff --git a/lib/matplotlib/tests/test_basic.py b/lib/matplotlib/tests/test_basic.py index 6fad2bacaf3f..6bd417876857 100644 --- a/lib/matplotlib/tests/test_basic.py +++ b/lib/matplotlib/tests/test_basic.py @@ -1,9 +1,10 @@ import builtins import os -import subprocess import sys import textwrap +from matplotlib.testing import subprocess_run_for_testing + def test_simple(): assert 1 + 1 == 2 @@ -41,6 +42,7 @@ def test_lazy_imports(): assert 'urllib.request' not in sys.modules """) - subprocess.check_call( + subprocess_run_for_testing( [sys.executable, '-c', source], - env={**os.environ, "MPLBACKEND": "", "MATPLOTLIBRC": os.devnull}) + env={**os.environ, "MPLBACKEND": "", "MATPLOTLIBRC": os.devnull}, + check=True) diff --git a/lib/matplotlib/tests/test_determinism.py b/lib/matplotlib/tests/test_determinism.py index fe0fb34e128a..3865dbc7fa43 100644 --- a/lib/matplotlib/tests/test_determinism.py +++ b/lib/matplotlib/tests/test_determinism.py @@ -3,7 +3,6 @@ """ import os -import subprocess import sys import pytest @@ -12,6 +11,7 @@ import matplotlib.testing.compare from matplotlib import pyplot as plt from matplotlib.testing._markers import needs_ghostscript, needs_usetex +from matplotlib.testing import subprocess_run_for_testing def _save_figure(objects='mhi', fmt="pdf", usetex=False): @@ -89,12 +89,13 @@ def test_determinism_check(objects, fmt, usetex): Output format. """ plots = [ - subprocess.check_output( + subprocess_run_for_testing( [sys.executable, "-R", "-c", f"from matplotlib.tests.test_determinism import _save_figure;" f"_save_figure({objects!r}, {fmt!r}, {usetex})"], env={**os.environ, "SOURCE_DATE_EPOCH": "946684800", - "MPLBACKEND": "Agg"}) + "MPLBACKEND": "Agg"}, + text=False, capture_output=True, check=True).stdout for _ in range(3) ] for p in plots[1:]: @@ -129,10 +130,10 @@ def test_determinism_source_date_epoch(fmt, string): string : bytes Timestamp string for 2000-01-01 00:00 UTC. """ - buf = subprocess.check_output( + buf = subprocess_run_for_testing( [sys.executable, "-R", "-c", f"from matplotlib.tests.test_determinism import _save_figure; " f"_save_figure('', {fmt!r})"], env={**os.environ, "SOURCE_DATE_EPOCH": "946684800", - "MPLBACKEND": "Agg"}) + "MPLBACKEND": "Agg"}, capture_output=True, text=False, check=True).stdout assert string in buf diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 79121a794d12..9563e4bf0869 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -5,7 +5,6 @@ from pathlib import Path from PIL import Image import shutil -import subprocess import sys import warnings @@ -17,6 +16,8 @@ json_dump, json_load, get_font, is_opentype_cff_font, MSUserFontDirectories, _get_fontconfig_fonts, ttfFontProperty) from matplotlib import cbook, ft2font, pyplot as plt, rc_context, figure as mfigure +from matplotlib.testing import subprocess_run_helper + has_fclist = shutil.which('fc-list') is not None @@ -275,15 +276,8 @@ def bad_idea(n): def test_fontcache_thread_safe(): pytest.importorskip('threading') - import inspect - - proc = subprocess.run( - [sys.executable, "-c", - inspect.getsource(_test_threading) + '\n_test_threading()'] - ) - if proc.returncode: - pytest.fail("The subprocess returned with non-zero exit status " - f"{proc.returncode}.") + + subprocess_run_helper(_test_threading, timeout=10) def test_fontentry_dataclass(): diff --git a/lib/matplotlib/tests/test_matplotlib.py b/lib/matplotlib/tests/test_matplotlib.py index 9ed8c46615bf..a1aa4ec212d6 100644 --- a/lib/matplotlib/tests/test_matplotlib.py +++ b/lib/matplotlib/tests/test_matplotlib.py @@ -5,6 +5,7 @@ import pytest import matplotlib +from matplotlib.testing import subprocess_run_for_testing @pytest.mark.parametrize('version_str, version_tuple', [ @@ -26,7 +27,7 @@ def test_tmpconfigdir_warning(tmp_path): mode = os.stat(tmp_path).st_mode try: os.chmod(tmp_path, 0) - proc = subprocess.run( + proc = subprocess_run_for_testing( [sys.executable, "-c", "import matplotlib"], env={**os.environ, "MPLCONFIGDIR": str(tmp_path)}, stderr=subprocess.PIPE, text=True, check=True) @@ -36,7 +37,7 @@ def test_tmpconfigdir_warning(tmp_path): def test_importable_with_no_home(tmp_path): - subprocess.run( + subprocess_run_for_testing( [sys.executable, "-c", "import pathlib; pathlib.Path.home = lambda *args: 1/0; " "import matplotlib.pyplot"], @@ -73,5 +74,7 @@ def test_importable_with__OO(): "import matplotlib.cbook as cbook; " "import matplotlib.patches as mpatches" ) - cmd = [sys.executable, "-OO", "-c", program] - assert subprocess.call(cmd, env={**os.environ, "MPLBACKEND": ""}) == 0 + subprocess_run_for_testing( + [sys.executable, "-OO", "-c", program], + env={**os.environ, "MPLBACKEND": ""}, check=True + ) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 782c390c9462..4823df0ce250 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -29,6 +29,7 @@ validate_sketch, _validate_linestyle, _listify_validator) +from matplotlib.testing import subprocess_run_for_testing def test_rcparams(tmp_path): @@ -524,7 +525,7 @@ def test_backend_fallback_headless(tmp_path): "DISPLAY": "", "WAYLAND_DISPLAY": "", "MPLBACKEND": "", "MPLCONFIGDIR": str(tmp_path)} with pytest.raises(subprocess.CalledProcessError): - subprocess.run( + subprocess_run_for_testing( [sys.executable, "-c", "import matplotlib;" "matplotlib.use('tkagg');" @@ -540,7 +541,7 @@ def test_backend_fallback_headless(tmp_path): def test_backend_fallback_headful(tmp_path): pytest.importorskip("tkinter") env = {**os.environ, "MPLBACKEND": "", "MPLCONFIGDIR": str(tmp_path)} - backend = subprocess.check_output( + backend = subprocess_run_for_testing( [sys.executable, "-c", "import matplotlib as mpl; " "sentinel = mpl.rcsetup._auto_backend_sentinel; " @@ -549,7 +550,7 @@ def test_backend_fallback_headful(tmp_path): "assert mpl.rcParams._get('backend') == sentinel; " "import matplotlib.pyplot; " "print(matplotlib.get_backend())"], - env=env, text=True) + env=env, text=True, check=True, capture_output=True).stdout # The actual backend will depend on what's installed, but at least tkagg is # present. assert backend.strip().lower() != "agg" diff --git a/lib/matplotlib/tests/test_texmanager.py b/lib/matplotlib/tests/test_texmanager.py index fbff21144e60..64dcbf46456d 100644 --- a/lib/matplotlib/tests/test_texmanager.py +++ b/lib/matplotlib/tests/test_texmanager.py @@ -1,13 +1,14 @@ import os from pathlib import Path import re -import subprocess import sys +import pytest + import matplotlib.pyplot as plt -from matplotlib.texmanager import TexManager +from matplotlib.testing import subprocess_run_for_testing from matplotlib.testing._markers import needs_usetex -import pytest +from matplotlib.texmanager import TexManager def test_fontconfig_preamble(): @@ -64,11 +65,11 @@ def test_unicode_characters(): @needs_usetex def test_openin_any_paranoid(): - completed = subprocess.run( + completed = subprocess_run_for_testing( [sys.executable, "-c", 'import matplotlib.pyplot as plt;' 'plt.rcParams.update({"text.usetex": True});' 'plt.title("paranoid");' 'plt.show(block=False);'], env={**os.environ, 'openin_any': 'p'}, check=True, capture_output=True) - assert completed.stderr == b"" + assert completed.stderr == "" 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