Skip to content

Commit

Permalink
Let Figure.savefig support filenames with spaces (#1116)
Browse files Browse the repository at this point in the history
Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
seisman and weiji14 committed Jun 14, 2021
1 parent 223032d commit 64a34d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def psconvert(self, **kwargs):
# Default cropping the figure to True
if "A" not in kwargs:
kwargs["A"] = ""
# allow for spaces in figure name
kwargs["F"] = f'"{kwargs.get("F")}"' if kwargs.get("F") else None
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 @@ -10,6 +10,7 @@
import pytest
from pygmt import Figure, set_display
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile


def test_figure_region():
Expand Down Expand Up @@ -107,6 +108,17 @@ 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)
with GMTTempFile(prefix="pygmt-filename with spaces", suffix=".png") as imgfile:
fig.savefig(imgfile.name)
assert os.path.exists(imgfile.name)


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

0 comments on commit 64a34d2

Please sign in to comment.