Skip to content

Commit a08f7d6

Browse files
committed
TST,FIX: Provide default env and switch to more recent name for argument.
universal_newlines is apparently the back-compatibility name; also text describes the biggest difference in the return types.
1 parent 87f9ccc commit a08f7d6

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ def setup():
5252

5353
def subprocess_run_for_testing(
5454
command: "list[str]",
55-
env: "dict[str, str]",
55+
env: "dict[str, str]" = None,
5656
timeout: float = None,
5757
stdout=None,
5858
stderr=None,
5959
check=False,
60-
universal_newlines=True,
60+
text=True,
6161
capture_output=False
6262
) -> "subprocess.Popen":
6363
"""
@@ -72,7 +72,11 @@ def subprocess_run_for_testing(
7272
timeout : float
7373
stdout, stderr
7474
check : bool
75-
universal_newlines : bool
75+
text : bool
76+
Also called `universal_newlines` in subprocess. I chose this
77+
name since the main effect is returning bytes (False) vs. str
78+
(True), though it also tries to normalize newlines across
79+
platforms.
7680
capture_output : bool
7781
Set stdout and stderr to subprocess.PIPE
7882
@@ -96,7 +100,7 @@ def subprocess_run_for_testing(
96100
command, env=env,
97101
timeout=timeout, check=check,
98102
stdout=stdout, stderr=stderr,
99-
universal_newlines=universal_newlines
103+
text=text
100104
)
101105
except BlockingIOError:
102106
if sys.platform == "cygwin":
@@ -124,15 +128,18 @@ def subprocess_run_helper(func, *args, timeout, extra_env=None):
124128
target = func.__name__
125129
module = func.__module__
126130
proc = subprocess_run_for_testing(
127-
[sys.executable,
128-
"-c",
129-
f"from {module} import {target}; {target}()",
130-
*args],
131+
[
132+
sys.executable,
133+
"-c",
134+
f"from {module} import {target}; {target}()",
135+
*args
136+
],
131137
env={**os.environ, "SOURCE_DATE_EPOCH": "0", **(extra_env or {})},
132138
timeout=timeout, check=True,
133139
stdout=subprocess.PIPE,
134140
stderr=subprocess.PIPE,
135-
universal_newlines=True)
141+
text=True
142+
)
136143
return proc
137144

138145

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):
2020
cmd = [sys.executable, '-msphinx', '-W', '-b', 'html',
2121
'-d', str(doctree_dir), str(source_dir), str(html_dir), *extra_args]
2222
proc = subprocess_run_for_testing(
23-
cmd, capture_output=True, universal_newlines=True,
23+
cmd, capture_output=True, text=True,
2424
env={**os.environ, "MPLBACKEND": ""})
2525
out = proc.stdout
2626
err = proc.stderr
@@ -47,7 +47,7 @@ def test_tinypages(tmp_path):
4747
# same name in multiple extension modules -- but we don't care about their
4848
# coverage anyways); hide them using GCOV_ERROR_FILE.
4949
proc = subprocess_run_for_testing(
50-
cmd, capture_output=True, universal_newlines=True,
50+
cmd, capture_output=True, text=True,
5151
env={**os.environ, "MPLBACKEND": "", "GCOV_ERROR_FILE": os.devnull}
5252
)
5353
out = proc.stdout

0 commit comments

Comments
 (0)