Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.psconvert: Check if the given prefix is valid #2170

Merged
merged 3 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)