Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e69938

Browse files
committed
Fix incorrect skip check in test_backend_ps.
There was a typo in `elif rcParams.get("ps.userdistiller") == "xpdf"` which effectively always returned False (the correct spelling is "ps.usedistiller", so the get() call always returned None), which made the skip check for xpdf never run. Thus, running the test on a machine without pdftops installed would eventually result in an ExecutableNotFoundError when matplotlib actually tries to call the distiller. To avoid this kind of problems (dict.get hiding typos), directly update the test-specific settings into the main rcParams, and use normal brackets to access rcParams entries, as rcParams keys are a fixed set anyways.
1 parent e3a5cee commit 1e69938

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __init__(self, canvas, num):
147147
icon_path = str(cbook._get_data_path('images/matplotlib.pdf'))
148148
_macosx.FigureManager.set_icon(icon_path)
149149
FigureManagerBase.__init__(self, canvas, num)
150-
self._set_window_mode(mpl.rcParams.get("macosx.window_mode", "system"))
150+
self._set_window_mode(mpl.rcParams["macosx.window_mode"])
151151
if self.toolbar is not None:
152152
self.toolbar.update()
153153
if mpl.is_interactive():

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@
4040
'eps with usetex'
4141
])
4242
def test_savefig_to_stringio(format, use_log, rcParams, orientation, papersize):
43-
if rcParams.get("ps.usedistiller") == "ghostscript":
43+
mpl.rcParams.update(rcParams)
44+
if mpl.rcParams["ps.usedistiller"] == "ghostscript":
4445
try:
4546
mpl._get_executable_info("gs")
4647
except mpl.ExecutableNotFoundError as exc:
4748
pytest.skip(str(exc))
48-
elif rcParams.get("ps.userdistiller") == "xpdf":
49+
elif mpl.rcParams["ps.usedistiller"] == "xpdf":
4950
try:
5051
mpl._get_executable_info("gs") # Effectively checks for ps2pdf.
5152
mpl._get_executable_info("pdftops")
5253
except mpl.ExecutableNotFoundError as exc:
5354
pytest.skip(str(exc))
5455

55-
mpl.rcParams.update(rcParams)
56-
5756
fig, ax = plt.subplots()
5857

5958
with io.StringIO() as s_buf, io.BytesIO() as b_buf:
@@ -67,9 +66,9 @@ def test_savefig_to_stringio(format, use_log, rcParams, orientation, papersize):
6766
title += " \N{MINUS SIGN}\N{EURO SIGN}"
6867
ax.set_title(title)
6968
allowable_exceptions = []
70-
if rcParams.get("text.usetex"):
69+
if mpl.rcParams["text.usetex"]:
7170
allowable_exceptions.append(RuntimeError)
72-
if rcParams.get("ps.useafm"):
71+
if mpl.rcParams["ps.useafm"]:
7372
allowable_exceptions.append(mpl.MatplotlibDeprecationWarning)
7473
try:
7574
fig.savefig(s_buf, format=format, orientation=orientation,
@@ -87,14 +86,14 @@ def test_savefig_to_stringio(format, use_log, rcParams, orientation, papersize):
8786
if format == 'ps':
8887
# Default figsize = (8, 6) inches = (576, 432) points = (203.2, 152.4) mm.
8988
# Landscape orientation will swap dimensions.
90-
if rcParams.get("ps.usedistiller") == "xpdf":
89+
if mpl.rcParams["ps.usedistiller"] == "xpdf":
9190
# Some versions specifically show letter/203x152, but not all,
9291
# so we can only use this simpler test.
9392
if papersize == 'figure':
9493
assert b'letter' not in s_val.lower()
9594
else:
9695
assert b'letter' in s_val.lower()
97-
elif rcParams.get("ps.usedistiller") or rcParams.get("text.usetex"):
96+
elif mpl.rcParams["ps.usedistiller"] or mpl.rcParams["text.usetex"]:
9897
width = b'432.0' if orientation == 'landscape' else b'576.0'
9998
wanted = (b'-dDEVICEWIDTHPOINTS=' + width if papersize == 'figure'
10099
else b'-sPAPERSIZE')

0 commit comments

Comments
 (0)