Skip to content

Commit

Permalink
Improve the error message for loading a old version of the GMT library (
Browse files Browse the repository at this point in the history
#925)

Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
seisman and weiji14 authored Feb 19, 2021
1 parent be38d78 commit 0fd514e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pygmt/clib/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,11 @@ def check_libgmt(libgmt):
functions = ["Create_Session", "Get_Enum", "Call_Module", "Destroy_Session"]
for func in functions:
if not hasattr(libgmt, "GMT_" + func):
msg = f"Error loading libgmt. Couldn't access function GMT_{func}."
# pylint: disable=protected-access
msg = (
f"Error loading '{libgmt._name}'. Couldn't access function GMT_{func}. "
"Ensure that you have installed an up-to-date GMT version 6 library. "
"Please set the environment variable 'GMT_LIBRARY_PATH' to the "
"directory of the GMT 6 library."
)
raise GMTCLibError(msg)
17 changes: 15 additions & 2 deletions pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ def test_check_libgmt():
"""
Make sure check_libgmt fails when given a bogus library.
"""
with pytest.raises(GMTCLibError):
check_libgmt(dict())
# create a fake library with a "_name" property
def libgmt():
pass

libgmt._name = "/path/to/libgmt.so" # pylint: disable=protected-access
msg = (
# pylint: disable=protected-access
f"Error loading '{libgmt._name}'. "
"Couldn't access function GMT_Create_Session. "
"Ensure that you have installed an up-to-date GMT version 6 library. "
"Please set the environment variable 'GMT_LIBRARY_PATH' to the "
"directory of the GMT 6 library."
)
with pytest.raises(GMTCLibError, match=msg):
check_libgmt(libgmt)


def test_load_libgmt():
Expand Down

0 comments on commit 0fd514e

Please sign in to comment.