Skip to content

Commit

Permalink
Raise GMTInvalidInput if no prefix argument is passed to psconvert
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Mar 13, 2022
1 parent 4770396 commit 801ba01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pygmt/tests/test_psconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""
import os

import pytest
from pygmt import Figure
from pygmt.exceptions import GMTInvalidInput


def test_psconvert():
Expand Down Expand Up @@ -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")

0 comments on commit 801ba01

Please sign in to comment.