Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error message for loading an old version of the GMT library #925

Merged
merged 2 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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