Skip to content

Commit

Permalink
Add GMTInvalidInput Error for Figure.coast (GenericMappingTools#787)
Browse files Browse the repository at this point in the history
* 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 <23487320+weiji14@users.noreply.github.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
  • Loading branch information
3 people authored and Josh Sixsmith committed Dec 21, 2022
1 parent 1df5765 commit 034881f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pygmt.clib import Session
from pygmt.exceptions import GMTError, GMTInvalidInput
from pygmt.helpers import (
args_in_kwargs,
build_arg_string,
data_kind,
dummy_context,
Expand Down Expand Up @@ -167,6 +168,11 @@ def coast(self, **kwargs):
"""
kwargs = self._preprocess(**kwargs)
if not args_in_kwargs(args=["C", "G", "S", "I", "N", "Q", "W"], kwargs=kwargs):
raise GMTInvalidInput(
"""At least one of the following arguments must be specified:
lakes, land, water, rivers, borders, Q, or shorelines"""
)
with Session() as lib:
lib.call_module("coast", build_arg_string(kwargs))

Expand Down
8 changes: 8 additions & 0 deletions pygmt/tests/test_coast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import pytest
from pygmt import Figure
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers.testing import check_figures_equal


Expand Down Expand Up @@ -97,6 +98,13 @@ def test_coast_world_mercator():
return fig


def test_coast_required_args():
"Test if fig.coast fails when not given required arguments"
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.coast(region="EG")


@check_figures_equal()
def test_coast_dcw_single():
"Test passing a single country code to dcw"
Expand Down

0 comments on commit 034881f

Please sign in to comment.