Skip to content

Commit 801ba01

Browse files
committed
Raise GMTInvalidInput if no prefix argument is passed to psconvert
1 parent 4770396 commit 801ba01

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pygmt/figure.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,13 @@ def psconvert(self, icc_gray=False, **kwargs):
239239
# Manually handle prefix -F argument so spaces aren't converted to \040
240240
# by build_arg_string function. For more information, see
241241
# https://github.com/GenericMappingTools/pygmt/pull/1487
242-
prefix = kwargs.pop("F")
242+
try:
243+
prefix_arg = f'-F"{kwargs.pop("F")}"'
244+
except KeyError as err:
245+
raise GMTInvalidInput("The 'prefix' must be specified.") from err
243246

244247
with Session() as lib:
245-
lib.call_module("psconvert", f'-F"{prefix}" {build_arg_string(kwargs)}')
248+
lib.call_module("psconvert", f"{prefix_arg} {build_arg_string(kwargs)}")
246249

247250
def savefig(
248251
self, fname, transparent=False, crop=True, anti_alias=True, show=False, **kwargs

pygmt/tests/test_psconvert.py

+11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"""
44
import os
55

6+
import pytest
67
from pygmt import Figure
8+
from pygmt.exceptions import GMTInvalidInput
79

810

911
def test_psconvert():
@@ -36,3 +38,12 @@ def test_psconvert_twice():
3638
fname = prefix + ".png"
3739
assert os.path.exists(fname)
3840
os.remove(fname)
41+
42+
43+
def test_psconvert_without_prefix():
44+
"""
45+
Call psconvert without the 'prefix' option.
46+
"""
47+
fig = Figure()
48+
with pytest.raises(GMTInvalidInput):
49+
fig.psconvert(fmt="g")

0 commit comments

Comments
 (0)