diff --git a/pygmt/figure.py b/pygmt/figure.py index f3e299e1b58..c3159b5d79f 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -244,10 +244,12 @@ 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 - try: - prefix_arg = f'-F"{kwargs.pop("F")}"' - except KeyError as err: - raise GMTInvalidInput("The 'prefix' must be specified.") from err + prefix = kwargs.pop("F", None) + if prefix in ["", None, False, True]: + raise GMTInvalidInput( + "The 'prefix' parameter must be specified with a valid value." + ) + prefix_arg = f'-F"{prefix}"' with Session() as lib: lib.call_module( diff --git a/pygmt/tests/test_psconvert.py b/pygmt/tests/test_psconvert.py index a18b14883f2..28db5133e61 100644 --- a/pygmt/tests/test_psconvert.py +++ b/pygmt/tests/test_psconvert.py @@ -42,8 +42,18 @@ def test_psconvert_twice(): def test_psconvert_without_prefix(): """ - Call psconvert without the 'prefix' option. + Call psconvert without the 'prefix' parameter. """ fig = Figure() with pytest.raises(GMTInvalidInput): fig.psconvert(fmt="g") + + +@pytest.mark.parametrize("prefix", ["", None, False, True]) +def test_psconvert_invalid_prefix(): + """ + Call psconvert with a invalid 'prefix' argument. + """ + fig = Figure() + with pytest.raises(GMTInvalidInput): + fig.psconvert(fmt="g", prefix=prefix)