Skip to content

Commit e018f21

Browse files
weiji14seisman
andauthored
Set GMT_COMPATIBILITY to 6 when pygmt session starts (#432)
To prevent users getting "pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6". Added test to ensure GMT_COMPATIBILITY = 6 is set, to prevent regression errors. Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
1 parent 66afff5 commit e018f21

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pygmt/session_management.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def begin():
1515
prefix = "pygmt-session"
1616
with Session() as lib:
1717
lib.call_module("begin", prefix)
18+
# pygmt relies on GMT modern mode with GMT_COMPATIBILITY at version 6
19+
lib.call_module("set", "GMT_COMPATIBILITY 6")
1820

1921

2022
def end():

pygmt/tests/test_session_management.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,33 @@ def test_begin_end():
2020
begin() # Restart the global session
2121
assert os.path.exists("pygmt-session.pdf")
2222
os.remove("pygmt-session.pdf")
23+
24+
25+
def test_gmt_compat_6_is_applied(capsys):
26+
"""
27+
Ensure that users with old gmt.conf files won't get pygmt-session [ERROR]:
28+
GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
29+
"""
30+
end() # Kill the global session
31+
try:
32+
with Session() as lib:
33+
# pretend that gmt.conf has GMT_COMPATIBILITY = 5
34+
lib.call_module("gmtset", "GMT_COMPATIBILITY 5")
35+
begin()
36+
with Session() as lib:
37+
lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba")
38+
out, err = capsys.readouterr() # capture stdout and stderr
39+
assert out == ""
40+
assert err != (
41+
"pygmt-session [ERROR]: GMT_COMPATIBILITY:"
42+
" Expects values from 6 to 6; reset to 6.\n"
43+
)
44+
assert err == "" # double check that there are no other errors
45+
finally:
46+
with Session() as lib:
47+
# revert gmt.conf back to GMT_COMPATIBILITY = 6
48+
lib.call_module("set", "GMT_COMPATIBILITY 6")
49+
end()
50+
begin() # Restart the global session
51+
assert os.path.exists("pygmt-session.pdf")
52+
os.remove("pygmt-session.pdf")

0 commit comments

Comments
 (0)