From e57b4deac8728384f250fe7263f3fe7bfef574d4 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 14 Jun 2021 01:29:10 -0400 Subject: [PATCH] Let Figure.savefig support filenames with spaces (#1116) Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/figure.py | 2 ++ pygmt/tests/test_figure.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pygmt/figure.py b/pygmt/figure.py index 043f56174ca..59fa4cf79ce 100644 --- a/pygmt/figure.py +++ b/pygmt/figure.py @@ -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)) diff --git a/pygmt/tests/test_figure.py b/pygmt/tests/test_figure.py index ba43b0b6288..4ac5d4f0592 100644 --- a/pygmt/tests/test_figure.py +++ b/pygmt/tests/test_figure.py @@ -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(): @@ -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.