diff --git a/pygmt/figure.py b/pygmt/figure.py index 9c0a7a7a763..0b2faea00d0 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -17,7 +17,7 @@ import numpy as np from pygmt.clib import Session -from pygmt.exceptions import GMTError, GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import launch_external_viewer, unique_name @@ -331,11 +331,12 @@ def show( match method: case "notebook": if not _HAS_IPYTHON: - raise GMTError( + msg = ( "Notebook display is selected, but IPython is not available. " "Make sure you have IPython installed, " "or run the script in a Jupyter notebook." ) + raise ImportError(msg) png = self._preview( fmt="png", dpi=dpi, anti_alias=True, as_bytes=True, **kwargs ) @@ -344,14 +345,15 @@ def show( pdf = self._preview( fmt="pdf", dpi=dpi, anti_alias=False, as_bytes=False, **kwargs ) - launch_external_viewer(pdf, waiting=waiting) # type: ignore[arg-type] + launch_external_viewer(pdf, waiting=waiting) case "none": pass # Do nothing case _: - raise GMTInvalidInput( - f"Invalid display method '{method}'. Valid values are 'external', " - "'notebook', 'none' or None." + msg = ( + f"Invalid display method '{method}'. " + "Valid values are 'external', 'notebook', 'none' or None." ) + raise GMTInvalidInput(msg) def _preview(self, fmt: str, dpi: int, as_bytes: bool = False, **kwargs): """ @@ -400,7 +402,7 @@ def _repr_html_(self): html = '' return html.format(image=base64_png.decode("utf-8"), width=500) - from pygmt.src import ( # type: ignore [misc] + from pygmt.src import ( # type: ignore[misc] basemap, coast, colorbar, diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index f91509dd8f2..10076b69437 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -12,7 +12,7 @@ import numpy.testing as npt import pytest from pygmt import Figure, set_display -from pygmt.exceptions import GMTError, GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput from pygmt.figure import SHOW_CONFIG, _get_default_display_method from pygmt.helpers import GMTTempFile @@ -321,7 +321,7 @@ def test_figure_show_notebook_error_without_ipython(): """ fig = Figure() fig.basemap(region=[0, 1, 2, 3], frame=True) - with pytest.raises(GMTError): + with pytest.raises(ImportError): fig.show(method="notebook") @@ -361,7 +361,7 @@ def test_set_display(self): assert mock_viewer.call_count == 0 assert mock_display.call_count == 1 else: - with pytest.raises(GMTError): + with pytest.raises(ImportError): fig.show() # Test the "external" display method