23
23
import pytest
24
24
25
25
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
-
34
26
@image_comparison (baseline_images = ['image_interps' ], style = 'mpl20' )
35
27
def test_image_interps ():
36
28
'make the basic nearest, bilinear and bicubic interps'
@@ -113,17 +105,17 @@ def test_image_python_io():
113
105
plt .imread (buffer )
114
106
115
107
116
- @needs_pillow
117
108
def test_imread_pil_uint16 ():
109
+ pytest .importorskip ("PIL" )
118
110
img = plt .imread (os .path .join (os .path .dirname (__file__ ),
119
111
'baseline_images' , 'test_image' , 'uint16.tif' ))
120
112
assert (img .dtype == np .uint16 )
121
113
assert np .sum (img ) == 134184960
122
114
123
115
124
116
@pytest .mark .skipif (sys .version_info < (3 , 6 ), reason = "requires Python 3.6+" )
125
- @needs_pillow
126
117
def test_imread_fspath ():
118
+ pytest .importorskip ("PIL" )
127
119
from pathlib import Path
128
120
img = plt .imread (
129
121
Path (__file__ ).parent / 'baseline_images/test_image/uint16.tif' )
@@ -497,8 +489,8 @@ def test_nonuniformimage_setnorm():
497
489
im .set_norm (plt .Normalize ())
498
490
499
491
500
- @needs_pillow
501
492
def test_jpeg_2d ():
493
+ Image = pytest .importorskip ('PIL.Image' )
502
494
# smoke test that mode-L pillow images work.
503
495
imd = np .ones ((10 , 10 ), dtype = 'uint8' )
504
496
for i in range (10 ):
@@ -509,8 +501,9 @@ def test_jpeg_2d():
509
501
ax .imshow (im )
510
502
511
503
512
- @needs_pillow
513
504
def test_jpeg_alpha ():
505
+ Image = pytest .importorskip ('PIL.Image' )
506
+
514
507
plt .figure (figsize = (1 , 1 ), dpi = 300 )
515
508
# Create an image that is all black, with a gradient from 0-1 in
516
509
# the alpha channel from left to right.
0 commit comments