Skip to content

Commit

Permalink
Set GMT_COMPATIBILITY to 6 when pygmt session starts (#432)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
weiji14 and seisman authored May 21, 2020
1 parent 66afff5 commit e018f21
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pygmt/session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def begin():
prefix = "pygmt-session"
with Session() as lib:
lib.call_module("begin", prefix)
# pygmt relies on GMT modern mode with GMT_COMPATIBILITY at version 6
lib.call_module("set", "GMT_COMPATIBILITY 6")


def end():
Expand Down
30 changes: 30 additions & 0 deletions pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,33 @@ def test_begin_end():
begin() # Restart the global session
assert os.path.exists("pygmt-session.pdf")
os.remove("pygmt-session.pdf")


def test_gmt_compat_6_is_applied(capsys):
"""
Ensure that users with old gmt.conf files won't get pygmt-session [ERROR]:
GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
"""
end() # Kill the global session
try:
with Session() as lib:
# pretend that gmt.conf has GMT_COMPATIBILITY = 5
lib.call_module("gmtset", "GMT_COMPATIBILITY 5")
begin()
with Session() as lib:
lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba")
out, err = capsys.readouterr() # capture stdout and stderr
assert out == ""
assert err != (
"pygmt-session [ERROR]: GMT_COMPATIBILITY:"
" Expects values from 6 to 6; reset to 6.\n"
)
assert err == "" # double check that there are no other errors
finally:
with Session() as lib:
# revert gmt.conf back to GMT_COMPATIBILITY = 6
lib.call_module("set", "GMT_COMPATIBILITY 6")
end()
begin() # Restart the global session
assert os.path.exists("pygmt-session.pdf")
os.remove("pygmt-session.pdf")

0 comments on commit e018f21

Please sign in to comment.