Skip to content

Commit 9a5858f

Browse files
willschlitzerweiji14seisman
authored
Add GMTInvalidInput Error for Figure.coast (#787)
* Add error raising to coast function in base_plotting.py. Error previously returned a GMtClibError that specified GMT arguments; added GMTInvalidInput to use PyGMT arguments * Add test for updated error in test_coast.py Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]>
1 parent e3efe39 commit 9a5858f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pygmt/base_plotting.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pygmt.clib import Session
1010
from pygmt.exceptions import GMTError, GMTInvalidInput
1111
from pygmt.helpers import (
12+
args_in_kwargs,
1213
build_arg_string,
1314
data_kind,
1415
dummy_context,
@@ -167,6 +168,11 @@ def coast(self, **kwargs):
167168
168169
"""
169170
kwargs = self._preprocess(**kwargs)
171+
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "Q", "W"], kwargs=kwargs):
172+
raise GMTInvalidInput(
173+
"""At least one of the following arguments must be specified:
174+
lakes, land, water, rivers, borders, Q, or shorelines"""
175+
)
170176
with Session() as lib:
171177
lib.call_module("coast", build_arg_string(kwargs))
172178

pygmt/tests/test_coast.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import pytest
55
from pygmt import Figure
6+
from pygmt.exceptions import GMTInvalidInput
67
from pygmt.helpers.testing import check_figures_equal
78

89

@@ -97,6 +98,13 @@ def test_coast_world_mercator():
9798
return fig
9899

99100

101+
def test_coast_required_args():
102+
"Test if fig.coast fails when not given required arguments"
103+
fig = Figure()
104+
with pytest.raises(GMTInvalidInput):
105+
fig.coast(region="EG")
106+
107+
100108
@check_figures_equal()
101109
def test_coast_dcw_single():
102110
"Test passing a single country code to dcw"

0 commit comments

Comments
 (0)