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

Let Figure.savefig support filenames with spaces #1116

Merged
merged 9 commits into from
Jun 14, 2021
Next Next commit
Let Figure.savefig support filenames with spaces
  • Loading branch information
seisman committed Mar 24, 2021
commit 551b824c983c69eefa874c1236945e4d461980eb
3 changes: 3 additions & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def psconvert(self, **kwargs):
# Default cropping the figure to True
if "A" not in kwargs:
kwargs["A"] = ""
# allow for spaces in figure name
if kwargs.get("F"):
kwargs["F"] = f'"{kwargs.get("F")}"'
seisman marked this conversation as resolved.
Show resolved Hide resolved
with Session() as lib:
lib.call_module("psconvert", build_arg_string(kwargs))

Expand Down
12 changes: 12 additions & 0 deletions pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def test_figure_savefig_transparent():
os.remove(fname)


def test_figure_savefig_filename_with_spaces():
"""
Check if savefig (or psconvert) supports filenames with spaces.
"""
fig = Figure()
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
fname = "test_figure_savefig filename with spaces.png"
fig.savefig(fname)
assert os.path.exists(fname)
os.remove(fname)
weiji14 marked this conversation as resolved.
Show resolved Hide resolved


def test_figure_savefig():
"""
Check if the arguments being passed to psconvert are correct.
Expand Down