1111import numpy as np
1212from numpy import ma
1313from numpy .testing import assert_array_equal
14+ from PIL import Image
1415
1516from matplotlib import (
1617 colors , image as mimage , patches , pyplot as plt , style , rcParams )
@@ -219,31 +220,24 @@ def test_imshow_zoom(fig_test, fig_ref):
219220@check_figures_equal ()
220221def test_imshow_pil (fig_test , fig_ref ):
221222 style .use ("default" )
222- PIL = pytest .importorskip ("PIL" )
223- # Pillow<=6.0 fails to open pathlib.Paths on Windows (pillow#3823), and
224- # Matplotlib's builtin png opener doesn't handle them either.
225- png_path = str (
226- Path (__file__ ).parent / "baseline_images/pngsuite/basn3p04.png" )
227- tiff_path = str (
228- Path (__file__ ).parent / "baseline_images/test_image/uint16.tif" )
223+ png_path = Path (__file__ ).parent / "baseline_images/pngsuite/basn3p04.png"
224+ tiff_path = Path (__file__ ).parent / "baseline_images/test_image/uint16.tif"
229225 axs = fig_test .subplots (2 )
230- axs [0 ].imshow (PIL . Image .open (png_path ))
231- axs [1 ].imshow (PIL . Image .open (tiff_path ))
226+ axs [0 ].imshow (Image .open (png_path ))
227+ axs [1 ].imshow (Image .open (tiff_path ))
232228 axs = fig_ref .subplots (2 )
233229 axs [0 ].imshow (plt .imread (png_path ))
234230 axs [1 ].imshow (plt .imread (tiff_path ))
235231
236232
237233def test_imread_pil_uint16 ():
238- pytest .importorskip ("PIL" )
239234 img = plt .imread (os .path .join (os .path .dirname (__file__ ),
240235 'baseline_images' , 'test_image' , 'uint16.tif' ))
241236 assert img .dtype == np .uint16
242237 assert np .sum (img ) == 134184960
243238
244239
245240def test_imread_fspath ():
246- pytest .importorskip ("PIL" )
247241 img = plt .imread (
248242 Path (__file__ ).parent / 'baseline_images/test_image/uint16.tif' )
249243 assert img .dtype == np .uint16
@@ -252,8 +246,6 @@ def test_imread_fspath():
252246
253247@pytest .mark .parametrize ("fmt" , ["png" , "jpg" , "jpeg" , "tiff" ])
254248def test_imsave (fmt ):
255- if fmt in ["jpg" , "jpeg" , "tiff" ]:
256- pytest .importorskip ("PIL" )
257249 has_alpha = fmt not in ["jpg" , "jpeg" ]
258250
259251 # The goal here is that the user can specify an output logical DPI
@@ -318,7 +310,6 @@ def test_imsave_color_alpha():
318310
319311
320312def test_imsave_pil_kwargs_png ():
321- Image = pytest .importorskip ("PIL.Image" )
322313 from PIL .PngImagePlugin import PngInfo
323314 buf = io .BytesIO ()
324315 pnginfo = PngInfo ()
@@ -330,7 +321,6 @@ def test_imsave_pil_kwargs_png():
330321
331322
332323def test_imsave_pil_kwargs_tiff ():
333- Image = pytest .importorskip ("PIL.Image" )
334324 from PIL .TiffTags import TAGS_V2 as TAGS
335325 buf = io .BytesIO ()
336326 pil_kwargs = {"description" : "test image" }
@@ -668,7 +658,6 @@ def test_nonuniformimage_setnorm():
668658
669659
670660def test_jpeg_2d ():
671- Image = pytest .importorskip ('PIL.Image' )
672661 # smoke test that mode-L pillow images work.
673662 imd = np .ones ((10 , 10 ), dtype = 'uint8' )
674663 for i in range (10 ):
@@ -680,8 +669,6 @@ def test_jpeg_2d():
680669
681670
682671def test_jpeg_alpha ():
683- Image = pytest .importorskip ('PIL.Image' )
684-
685672 plt .figure (figsize = (1 , 1 ), dpi = 300 )
686673 # Create an image that is all black, with a gradient from 0-1 in
687674 # the alpha channel from left to right.
0 commit comments