2323import pytest
2424
2525
26- try :
27- from PIL import Image
28- HAS_PIL = True
29- except ImportError :
30- HAS_PIL = False
31- needs_pillow = pytest .mark .xfail (not HAS_PIL , reason = 'Test requires Pillow' )
32-
33-
3426@image_comparison (baseline_images = ['image_interps' ], style = 'mpl20' )
3527def test_image_interps ():
3628 'make the basic nearest, bilinear and bicubic interps'
@@ -113,17 +105,17 @@ def test_image_python_io():
113105 plt .imread (buffer )
114106
115107
116- @needs_pillow
117108def test_imread_pil_uint16 ():
109+ pytest .importorskip ("PIL" )
118110 img = plt .imread (os .path .join (os .path .dirname (__file__ ),
119111 'baseline_images' , 'test_image' , 'uint16.tif' ))
120112 assert (img .dtype == np .uint16 )
121113 assert np .sum (img ) == 134184960
122114
123115
124116@pytest .mark .skipif (sys .version_info < (3 , 6 ), reason = "requires Python 3.6+" )
125- @needs_pillow
126117def test_imread_fspath ():
118+ pytest .importorskip ("PIL" )
127119 from pathlib import Path
128120 img = plt .imread (
129121 Path (__file__ ).parent / 'baseline_images/test_image/uint16.tif' )
@@ -497,8 +489,8 @@ def test_nonuniformimage_setnorm():
497489 im .set_norm (plt .Normalize ())
498490
499491
500- @needs_pillow
501492def test_jpeg_2d ():
493+ Image = pytest .importorskip ('PIL.Image' )
502494 # smoke test that mode-L pillow images work.
503495 imd = np .ones ((10 , 10 ), dtype = 'uint8' )
504496 for i in range (10 ):
@@ -509,8 +501,9 @@ def test_jpeg_2d():
509501 ax .imshow (im )
510502
511503
512- @needs_pillow
513504def test_jpeg_alpha ():
505+ Image = pytest .importorskip ('PIL.Image' )
506+
514507 plt .figure (figsize = (1 , 1 ), dpi = 300 )
515508 # Create an image that is all black, with a gradient from 0-1 in
516509 # the alpha channel from left to right.
0 commit comments