2121import pytest
2222
2323
24- try :
25- from PIL import Image
26- HAS_PIL = True
27- except ImportError :
28- HAS_PIL = False
29- needs_pillow = pytest .mark .xfail (not HAS_PIL , reason = 'Test requires Pillow' )
30-
31-
3224@image_comparison (baseline_images = ['image_interps' ], style = 'mpl20' )
3325def test_image_interps ():
3426 'make the basic nearest, bilinear and bicubic interps'
@@ -111,17 +103,17 @@ def test_image_python_io():
111103 plt .imread (buffer )
112104
113105
114- @needs_pillow
115106def test_imread_pil_uint16 ():
107+ pytest .importorskip ("PIL" )
116108 img = plt .imread (os .path .join (os .path .dirname (__file__ ),
117109 'baseline_images' , 'test_image' , 'uint16.tif' ))
118110 assert img .dtype == np .uint16
119111 assert np .sum (img ) == 134184960
120112
121113
122114@pytest .mark .skipif (sys .version_info < (3 , 6 ), reason = "requires Python 3.6+" )
123- @needs_pillow
124115def test_imread_fspath ():
116+ pytest .importorskip ("PIL" )
125117 from pathlib import Path
126118 img = plt .imread (
127119 Path (__file__ ).parent / 'baseline_images/test_image/uint16.tif' )
@@ -498,8 +490,8 @@ def test_nonuniformimage_setnorm():
498490 im .set_norm (plt .Normalize ())
499491
500492
501- @needs_pillow
502493def test_jpeg_2d ():
494+ Image = pytest .importorskip ('PIL.Image' )
503495 # smoke test that mode-L pillow images work.
504496 imd = np .ones ((10 , 10 ), dtype = 'uint8' )
505497 for i in range (10 ):
@@ -510,8 +502,9 @@ def test_jpeg_2d():
510502 ax .imshow (im )
511503
512504
513- @needs_pillow
514505def test_jpeg_alpha ():
506+ Image = pytest .importorskip ('PIL.Image' )
507+
515508 plt .figure (figsize = (1 , 1 ), dpi = 300 )
516509 # Create an image that is all black, with a gradient from 0-1 in
517510 # the alpha channel from left to right.
0 commit comments