Skip to content

Commit 0fd514e

Browse files
seismanweiji14
andauthored
Improve the error message for loading a old version of the GMT library (#925)
Co-authored-by: Wei Ji <[email protected]>
1 parent be38d78 commit 0fd514e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pygmt/clib/loading.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,11 @@ def check_libgmt(libgmt):
151151
functions = ["Create_Session", "Get_Enum", "Call_Module", "Destroy_Session"]
152152
for func in functions:
153153
if not hasattr(libgmt, "GMT_" + func):
154-
msg = f"Error loading libgmt. Couldn't access function GMT_{func}."
154+
# pylint: disable=protected-access
155+
msg = (
156+
f"Error loading '{libgmt._name}'. Couldn't access function GMT_{func}. "
157+
"Ensure that you have installed an up-to-date GMT version 6 library. "
158+
"Please set the environment variable 'GMT_LIBRARY_PATH' to the "
159+
"directory of the GMT 6 library."
160+
)
155161
raise GMTCLibError(msg)

pygmt/tests/test_clib_loading.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,21 @@ def test_check_libgmt():
1313
"""
1414
Make sure check_libgmt fails when given a bogus library.
1515
"""
16-
with pytest.raises(GMTCLibError):
17-
check_libgmt(dict())
16+
# create a fake library with a "_name" property
17+
def libgmt():
18+
pass
19+
20+
libgmt._name = "/path/to/libgmt.so" # pylint: disable=protected-access
21+
msg = (
22+
# pylint: disable=protected-access
23+
f"Error loading '{libgmt._name}'. "
24+
"Couldn't access function GMT_Create_Session. "
25+
"Ensure that you have installed an up-to-date GMT version 6 library. "
26+
"Please set the environment variable 'GMT_LIBRARY_PATH' to the "
27+
"directory of the GMT 6 library."
28+
)
29+
with pytest.raises(GMTCLibError, match=msg):
30+
check_libgmt(libgmt)
1831

1932

2033
def test_load_libgmt():

0 commit comments

Comments
 (0)