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

TST: always set a (long) timeout for subprocess and always use our wrapper#27726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
greglucas merged 3 commits intomatplotlib:mainfromtacaswell:tst/finite_tests
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionlib/matplotlib/testing/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
stderr=None,check=False,text=True,
stderr=None,check=True,text=True,

Since this is used for testing it seems like we should setcheck=True by default. It looks like you currently set this in many of the calls. Are there even more tests without setting check?

capture_output=False):
"""
Expand Down
8 changes: 5 additions & 3 deletionslib/matplotlib/tests/test_backend_nbagg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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')
Expand All@@ -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)

Expand Down
7 changes: 3 additions & 4 deletionslib/matplotlib/tests/test_backend_webagg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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"])
Expand All@@ -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():
Expand Down
8 changes: 5 additions & 3 deletionslib/matplotlib/tests/test_basic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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
Expand DownExpand Up@@ -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)
11 changes: 6 additions & 5 deletionslib/matplotlib/tests/test_determinism.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@
"""

import os
import subprocess
import sys

import pytest
Expand All@@ -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):
Expand DownExpand Up@@ -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:]:
Expand DownExpand Up@@ -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
14 changes: 4 additions & 10 deletionslib/matplotlib/tests/test_font_manager.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,6 @@
from pathlib import Path
from PIL import Image
import shutil
import subprocess
import sys
import warnings

Expand All@@ -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

Expand DownExpand Up@@ -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():
Expand Down
11 changes: 7 additions & 4 deletionslib/matplotlib/tests/test_matplotlib.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
import pytest

import matplotlib
from matplotlib.testing import subprocess_run_for_testing


@pytest.mark.parametrize('version_str, version_tuple', [
Expand All@@ -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)
Expand All@@ -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"],
Expand DownExpand Up@@ -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
)
7 changes: 4 additions & 3 deletionslib/matplotlib/tests/test_rcparams.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@
validate_sketch,
_validate_linestyle,
_listify_validator)
from matplotlib.testing import subprocess_run_for_testing


def test_rcparams(tmp_path):
Expand DownExpand Up@@ -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');"
Expand All@@ -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; "
Expand All@@ -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"
Expand Down
11 changes: 6 additions & 5 deletionslib/matplotlib/tests/test_texmanager.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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 importTexManager
from matplotlib.testing importsubprocess_run_for_testing
from matplotlib.testing._markers import needs_usetex
importpytest
from matplotlib.texmanagerimportTexManager


def test_fontconfig_preamble():
Expand DownExpand Up@@ -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 == ""

[8]ページ先頭

©2009-2025 Movatter.jp