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

Appearance settings

Commit 4d7c309

Browse filesBrowse files
authored
Merge pull request #23110 from anntzer/srh
Tweak subprocess_run_helper.
2 parents 79f28ec + 031093e commit 4d7c309
Copy full SHA for 4d7c309

File tree

Expand file treeCollapse file tree

3 files changed

+16
-32
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-32
lines changed

‎lib/matplotlib/testing/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/__init__.py
+7-18Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,28 @@ def setup():
5050
set_reproducibility_for_testing()
5151

5252

53-
def subprocess_run_helper(func, *args, timeout, **extra_env):
53+
def subprocess_run_helper(func, *args, timeout, extra_env=None):
5454
"""
55-
Run a function in a sub-process
55+
Run a function in a sub-process.
5656
5757
Parameters
5858
----------
5959
func : function
6060
The function to be run. It must be in a module that is importable.
61-
6261
*args : str
6362
Any additional command line arguments to be passed in
64-
the first argument to subprocess.run
65-
66-
**extra_env : Dict[str, str]
67-
Any additional environment variables to be set for
68-
the subprocess.
69-
63+
the first argument to ``subprocess.run``.
64+
extra_env : dict[str, str]
65+
Any additional environment variables to be set for the subprocess.
7066
"""
7167
target = func.__name__
7268
module = func.__module__
7369
proc = subprocess.run(
7470
[sys.executable,
7571
"-c",
76-
f"""
77-
from {module} import {target}
78-
{target}()
79-
""",
72+
f"from {module} import {target}; {target}()",
8073
*args],
81-
env={
82-
**os.environ,
83-
"SOURCE_DATE_EPOCH": "0",
84-
**extra_env
85-
},
74+
env={**os.environ, "SOURCE_DATE_EPOCH": "0", **(extra_env or {})},
8675
timeout=timeout, check=True,
8776
stdout=subprocess.PIPE,
8877
stderr=subprocess.PIPE,

‎lib/matplotlib/tests/test_backend_tk.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_tk.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ def test_func():
4848
pytest.importorskip('tkinter')
4949
try:
5050
proc = subprocess_run_helper(
51-
func, timeout=_test_timeout,
52-
MPLBACKEND="TkAgg",
53-
MPL_TEST_ESCAPE_HATCH="1"
54-
)
51+
func, timeout=_test_timeout, extra_env=dict(
52+
MPLBACKEND="TkAgg", MPL_TEST_ESCAPE_HATCH="1"))
5553
except subprocess.TimeoutExpired:
5654
pytest.fail("Subprocess timed out")
5755
except subprocess.CalledProcessError as e:

‎lib/matplotlib/tests/test_backends_interactive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backends_interactive.py
+7-10Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_interactive_backend(env, toolbar):
175175
proc = _run_helper(_test_interactive_impl,
176176
json.dumps({"toolbar": toolbar}),
177177
timeout=_test_timeout,
178-
**env)
178+
extra_env=env)
179179

180180
assert proc.stdout.count("CloseEvent") == 1
181181

@@ -247,8 +247,7 @@ def _test_thread_impl():
247247
@pytest.mark.parametrize("env", _thread_safe_backends)
248248
@pytest.mark.flaky(reruns=3)
249249
def test_interactive_thread_safety(env):
250-
proc = _run_helper(_test_thread_impl,
251-
timeout=_test_timeout, **env)
250+
proc = _run_helper(_test_thread_impl, timeout=_test_timeout, extra_env=env)
252251
assert proc.stdout.count("CloseEvent") == 1
253252

254253

@@ -447,7 +446,7 @@ def test_lazy_linux_headless(env):
447446
_lazy_headless,
448447
env.pop('MPLBACKEND'), env.pop("BACKEND_DEPS"),
449448
timeout=_test_timeout,
450-
**{**env, 'DISPLAY': '', 'WAYLAND_DISPLAY': ''}
449+
extra_env={**env, 'DISPLAY': '', 'WAYLAND_DISPLAY': ''}
451450
)
452451

453452

@@ -526,10 +525,8 @@ def _test_number_of_draws_script():
526525
# subprocesses can struggle to get the display, so rerun a few times
527526
@pytest.mark.flaky(reruns=4)
528527
def test_blitting_events(env):
529-
proc = _run_helper(_test_number_of_draws_script,
530-
timeout=_test_timeout,
531-
**env)
532-
528+
proc = _run_helper(
529+
_test_number_of_draws_script, timeout=_test_timeout, extra_env=env)
533530
# Count the number of draw_events we got. We could count some initial
534531
# canvas draws (which vary in number by backend), but the critical
535532
# check here is that it isn't 10 draws, which would be called if
@@ -585,8 +582,8 @@ def test_figure_leak_20490(env, time_mem):
585582
acceptable_memory_leakage += 11_000_000
586583

587584
result = _run_helper(
588-
_test_figure_leak, str(pause_time), timeout=_test_timeout, **env
589-
)
585+
_test_figure_leak, str(pause_time),
586+
timeout=_test_timeout, extra_env=env)
590587

591588
growth = int(result.stdout)
592589
assert growth <= acceptable_memory_leakage

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.