Skip to content

Commit efa6715

Browse files
committed
Use the new exception
1 parent 5de77a1 commit efa6715

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pygmt/figure.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import numpy as np
2222
from pygmt.clib import Session
23-
from pygmt.exceptions import GMTInvalidInput
23+
from pygmt.exceptions import GMTInvalidInput, GMTValueError
2424
from pygmt.helpers import launch_external_viewer, unique_name
2525

2626

@@ -358,11 +358,11 @@ def show(
358358
case "none":
359359
pass # Do nothing
360360
case _:
361-
msg = (
362-
f"Invalid display method '{method}'. "
363-
"Valid values are 'external', 'notebook', 'none' or None."
361+
raise GMTValueError(
362+
name="method",
363+
value=method,
364+
choices=["external", "notebook", "none", None],
364365
)
365-
raise GMTInvalidInput(msg)
366366

367367
@overload
368368
def _preview(
@@ -494,8 +494,8 @@ def set_display(method: Literal["external", "notebook", "none", None] = None) ->
494494
case None:
495495
SHOW_CONFIG["method"] = _get_default_display_method()
496496
case _:
497-
msg = (
498-
f"Invalid display method '{method}'. "
499-
"Valid values are 'external', 'notebook', 'none' or None."
497+
raise GMTValueError(
498+
name="method",
499+
value=method,
500+
choices=["external", "notebook", "none", None],
500501
)
501-
raise GMTInvalidInput(msg)

pygmt/tests/test_figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy.testing as npt
1313
import pytest
1414
from pygmt import Figure, set_display
15-
from pygmt.exceptions import GMTInvalidInput
15+
from pygmt.exceptions import GMTInvalidInput, GMTValueError
1616
from pygmt.figure import SHOW_CONFIG, _get_default_display_method
1717
from pygmt.helpers import GMTTempFile
1818

@@ -313,7 +313,7 @@ def test_figure_show_invalid_method():
313313
"""
314314
fig = Figure()
315315
fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af")
316-
with pytest.raises(GMTInvalidInput):
316+
with pytest.raises(GMTValueError):
317317
fig.show(method="test")
318318

319319

@@ -398,7 +398,7 @@ def test_invalid_method(self):
398398
"""
399399
Test if an error is raised when an invalid method is passed.
400400
"""
401-
with pytest.raises(GMTInvalidInput):
401+
with pytest.raises(GMTValueError):
402402
set_display(method="invalid")
403403

404404

0 commit comments

Comments
 (0)