Skip to content

Commit

Permalink
Figure.psconvert: Check if the given prefix is valid (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Oct 28, 2022
1 parent c2c7970 commit bd05e70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 11 additions & 1 deletion pygmt/tests/test_psconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(prefix):
"""
Call psconvert with an invalid 'prefix' argument.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.psconvert(fmt="g", prefix=prefix)

0 comments on commit bd05e70

Please sign in to comment.