Skip to content

Commit

Permalink
Combine two tests into a single one
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Oct 26, 2023
1 parent da5c6d2 commit a863132
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,25 @@ def mock_psconvert(*args, **kwargs): # pylint: disable=unused-argument
}


@pytest.mark.parametrize("fmt", [".bmp", ".jpg", ".pdf", ".png", ".tif"])
def test_figure_savefig_worldfile(fmt):
def test_figure_savefig_worldfile():
"""
Check if a world file is created when requested.
Check if a world file is created for supported formats and raise an error
for unsupported formats.
"""
fig = Figure()
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
with GMTTempFile(prefix="pygmt-worldfile", suffix=fmt) as imgfile:
fig.savefig(fname=imgfile.name, worldfile=True)
assert Path(imgfile.name).stat().st_size > 0
worldfile_suffix = "." + fmt[1] + fmt[3] + "w"
assert Path(imgfile.name).with_suffix(worldfile_suffix).stat().st_size > 0


@pytest.mark.parametrize("fmt", [".tiff", ".kml"])
def test_figure_savefig_worldfile_unsupported_format(fmt):
"""
Figure.savefig should raise an error when a world file is requested for an
unsupported format.
"""
fig = Figure()
fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True)
with GMTTempFile(prefix="pygmt-worldfile", suffix=fmt) as imgfile:
with pytest.raises(GMTInvalidInput):
# supported formats
for fmt in [".bmp", ".jpg", ".png", ".tif"]:
with GMTTempFile(prefix="pygmt-worldfile", suffix=fmt) as imgfile:
fig.savefig(fname=imgfile.name, worldfile=True)
assert Path(imgfile.name).stat().st_size > 0
worldfile_suffix = "." + fmt[1] + fmt[3] + "w"
assert Path(imgfile.name).with_suffix(worldfile_suffix).stat().st_size > 0
# unsupported formats
for fmt in [".eps", ".kml", ".pdf", ".tiff"]:
with GMTTempFile(prefix="pygmt-worldfile", suffix=fmt) as imgfile:
with pytest.raises(GMTInvalidInput):
fig.savefig(fname=imgfile.name, worldfile=True)


@pytest.mark.skipif(IPython is None, reason="run when IPython is installed")
Expand Down

0 comments on commit a863132

Please sign in to comment.