Skip to content

Commit 97bbe05

Browse files
committed
Merge branch 'main' into api/virtualfile-from-stringio
2 parents 49fa805 + be8c450 commit 97bbe05

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

pygmt/figure.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -354,41 +354,38 @@ def savefig( # noqa: PLR0912
354354
prefix, suffix = fname.with_suffix("").as_posix(), fname.suffix
355355
ext = suffix[1:].lower() # Remove the . and normalize to lowercase
356356

357-
if ext == "jpeg": # Alias jpeg to jpg
358-
ext = "jpg"
359-
elif ext == "tiff": # GeoTIFF
360-
kwargs["W"] = "+g"
361-
elif ext == "kml": # KML
362-
kwargs["W"] = "+k"
363-
364-
if ext not in fmts:
365-
if ext == "ps":
366-
raise GMTInvalidInput(
367-
"Extension '.ps' is not supported. "
368-
"Please use '.eps' or '.pdf' instead."
369-
)
370-
raise GMTInvalidInput(f"Unknown extension '.{ext}'.")
357+
match ext:
358+
case "jpeg": # Alias jpeg to jpg
359+
ext = "jpg"
360+
case "tiff": # GeoTIFF
361+
kwargs["W"] = "+g"
362+
case "kml": # KML
363+
kwargs["W"] = "+k"
364+
case "ps":
365+
msg = "Extension '.ps' is not supported. Use '.eps' or '.pdf' instead."
366+
raise GMTInvalidInput(msg)
367+
case ext if ext not in fmts:
368+
raise GMTInvalidInput(f"Unknown extension '.{ext}'.")
369+
371370
fmt = fmts[ext]
372371
if transparent:
373372
if fmt != "g":
374-
raise GMTInvalidInput(
375-
f"Transparency unavailable for '{ext}', only for png."
376-
)
373+
msg = f"Transparency unavailable for '{ext}', only for png."
374+
raise GMTInvalidInput(msg)
377375
fmt = fmt.upper()
378376
if anti_alias:
379377
kwargs["Qt"] = 2
380378
kwargs["Qg"] = 2
381379

382380
if worldfile:
383381
if ext in {"eps", "kml", "pdf", "tiff"}:
384-
raise GMTInvalidInput(
385-
f"Saving a world file is not supported for '{ext}' format."
386-
)
382+
msg = f"Saving a world file is not supported for '{ext}' format."
383+
raise GMTInvalidInput(msg)
387384
kwargs["W"] = True
388385

389386
self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
390387

391-
# Remove the .pgw world file if exists
388+
# Remove the .pgw world file if exists.
392389
# Not necessary after GMT 6.5.0.
393390
# See upstream fix https://github.com/GenericMappingTools/gmt/pull/7865
394391
if ext == "tiff":

pygmt/helpers/testing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def wrapper(*args, ext="png", request=None, **kwargs):
8989
file_name = "".join(c for c in request.node.name if c in allowed_chars)
9090
except AttributeError: # 'NoneType' object has no attribute 'node'
9191
file_name = func.__name__
92+
93+
fig_ref, fig_test = None, None
9294
try:
9395
fig_ref, fig_test = func(*args, **kwargs)
9496
ref_image_path = Path(result_dir) / f"{file_name}-expected.{ext}"

pygmt/tests/test_show_versions.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,43 @@
55
import io
66

77
import pygmt
8+
import pytest
89

910

1011
def test_show_versions():
1112
"""
12-
Check that pygmt.show_versions() reports version information from PyGMT, the
13-
operating system, dependencies and the GMT library.
13+
Check that pygmt.show_versions reports version information of PyGMT, the operating
14+
system, dependencies and the GMT library.
1415
"""
1516
buf = io.StringIO()
1617
pygmt.show_versions(file=buf)
17-
assert "PyGMT information:" in buf.getvalue()
18-
assert "System information:" in buf.getvalue()
19-
assert "Dependency information:" in buf.getvalue()
20-
assert "GMT library information:" in buf.getvalue()
18+
output = buf.getvalue()
19+
20+
assert "PyGMT information:" in output
21+
assert "System information:" in output
22+
assert "Dependency information:" in output
23+
assert "GMT library information:" in output
24+
assert "WARNING:" not in output # No GMT-Ghostscript incompatibility warnings.
25+
26+
27+
@pytest.mark.parametrize(
28+
("gs_version", "gmt_version"),
29+
[
30+
("9.52", "6.4.0"),
31+
("10.01", "6.4.0"),
32+
("10.02", "6.4.0"),
33+
(None, "6.5.0"),
34+
],
35+
)
36+
def test_show_versions_ghostscript_warnings(gs_version, gmt_version, monkeypatch):
37+
"""
38+
Check that pygmt.show_versions reports warnings for GMT-Ghostscript incompatibility.
39+
"""
40+
monkeypatch.setattr("pygmt._show_versions.__gmt_version__", gmt_version)
41+
monkeypatch.setattr(
42+
"pygmt._show_versions._get_ghostscript_version", lambda: gs_version
43+
)
44+
45+
buf = io.StringIO()
46+
pygmt.show_versions(file=buf)
47+
assert "WARNING:" in buf.getvalue()

0 commit comments

Comments
 (0)