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

Set GMT_COMPATIBILITY to 6 when pygmt session starts #432

Merged
merged 8 commits into from
May 21, 2020
Merged
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():
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
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 != (
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
"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")