@@ -292,31 +292,25 @@ def mock_psconvert(*args, **kwargs): # pylint: disable=unused-argument
292
292
}
293
293
294
294
295
- @pytest .mark .parametrize ("fmt" , [".bmp" , ".jpg" , ".pdf" , ".png" , ".tif" ])
296
- def test_figure_savefig_worldfile (fmt ):
295
+ def test_figure_savefig_worldfile ():
297
296
"""
298
- Check if a world file is created when requested.
297
+ Check if a world file is created for supported formats and raise an error
298
+ for unsupported formats.
299
299
"""
300
300
fig = Figure ()
301
301
fig .basemap (region = [0 , 1 , 0 , 1 ], projection = "X1c/1c" , frame = True )
302
- with GMTTempFile (prefix = "pygmt-worldfile" , suffix = fmt ) as imgfile :
303
- fig .savefig (fname = imgfile .name , worldfile = True )
304
- assert Path (imgfile .name ).stat ().st_size > 0
305
- worldfile_suffix = "." + fmt [1 ] + fmt [3 ] + "w"
306
- assert Path (imgfile .name ).with_suffix (worldfile_suffix ).stat ().st_size > 0
307
-
308
-
309
- @pytest .mark .parametrize ("fmt" , [".tiff" , ".kml" ])
310
- def test_figure_savefig_worldfile_unsupported_format (fmt ):
311
- """
312
- Figure.savefig should raise an error when a world file is requested for an
313
- unsupported format.
314
- """
315
- fig = Figure ()
316
- fig .basemap (region = [0 , 1 , 0 , 1 ], projection = "X1c/1c" , frame = True )
317
- with GMTTempFile (prefix = "pygmt-worldfile" , suffix = fmt ) as imgfile :
318
- with pytest .raises (GMTInvalidInput ):
302
+ # supported formats
303
+ for fmt in [".bmp" , ".jpg" , ".png" , ".tif" ]:
304
+ with GMTTempFile (prefix = "pygmt-worldfile" , suffix = fmt ) as imgfile :
319
305
fig .savefig (fname = imgfile .name , worldfile = True )
306
+ assert Path (imgfile .name ).stat ().st_size > 0
307
+ worldfile_suffix = "." + fmt [1 ] + fmt [3 ] + "w"
308
+ assert Path (imgfile .name ).with_suffix (worldfile_suffix ).stat ().st_size > 0
309
+ # unsupported formats
310
+ for fmt in [".eps" , ".kml" , ".pdf" , ".tiff" ]:
311
+ with GMTTempFile (prefix = "pygmt-worldfile" , suffix = fmt ) as imgfile :
312
+ with pytest .raises (GMTInvalidInput ):
313
+ fig .savefig (fname = imgfile .name , worldfile = True )
320
314
321
315
322
316
@pytest .mark .skipif (IPython is None , reason = "run when IPython is installed" )
0 commit comments