diff --git a/pygmt/figure.py b/pygmt/figure.py index 9739826f8aa..b922705d752 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -239,10 +239,13 @@ def psconvert(self, icc_gray=False, **kwargs): # Manually handle prefix -F argument so spaces aren't converted to \040 # by build_arg_string function. For more information, see # https://github.com/GenericMappingTools/pygmt/pull/1487 - prefix = kwargs.pop("F") + try: + prefix_arg = f'-F"{kwargs.pop("F")}"' + except KeyError as err: + raise GMTInvalidInput("The 'prefix' must be specified.") from err with Session() as lib: - lib.call_module("psconvert", f'-F"{prefix}" {build_arg_string(kwargs)}') + lib.call_module("psconvert", f"{prefix_arg} {build_arg_string(kwargs)}") def savefig( self, fname, transparent=False, crop=True, anti_alias=True, show=False, **kwargs diff --git a/pygmt/tests/test_psconvert.py b/pygmt/tests/test_psconvert.py index af610cf86bb..a18b14883f2 100644 --- a/pygmt/tests/test_psconvert.py +++ b/pygmt/tests/test_psconvert.py @@ -3,7 +3,9 @@ """ import os +import pytest from pygmt import Figure +from pygmt.exceptions import GMTInvalidInput def test_psconvert(): @@ -36,3 +38,12 @@ def test_psconvert_twice(): fname = prefix + ".png" assert os.path.exists(fname) os.remove(fname) + + +def test_psconvert_without_prefix(): + """ + Call psconvert without the 'prefix' option. + """ + fig = Figure() + with pytest.raises(GMTInvalidInput): + fig.psconvert(fmt="g")