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
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
32 changes: 32 additions & 0 deletions pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,35 @@ 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("gmt.conf")
os.remove("gmt.conf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a "gmt.conf" file in the current directory. It should be in the temporary gmt session directory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda agree, but wouldn't the assertion fail if there isn't a gmt.conf file? 😕 Things got really confusing for me when I was designing this test with gmt.conf files all over the place, one kept popping up in my pygmt folder with GMT_COMPATIBILITY 5 for some reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you're right, it's in "/home/.../pygmt/tmp-test-dir-with-unique-name/gmt.conf". I'll remove these lines once the tests on Windows pass in the other PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand why the test works, but since the test pass, OK to merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a complicated test. but removing the line at

lib.call_module("set", "GMT_COMPATIBILITY 6")
should fail this test, as encountered by Mark.

assert os.path.exists("pygmt-session.pdf")
os.remove("pygmt-session.pdf")