Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe7a689

Browse files
committed
TST: Fix warnings from Pillow for unavailable features
If Pillow is old enough to not support a feature _at all_, then it will warn about it. If you're running the whole test suite, then something else seems to cause pytest to treat it as benign. But if you run only `test_agg.py`, then our `-Werror` setting will cause it to fail test collection.
1 parent 74aa9ab commit fe7a689

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/matplotlib/tests/test_agg.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import warnings
23

34
import numpy as np
45
from numpy.testing import assert_array_almost_equal
@@ -17,6 +18,13 @@
1718
from matplotlib.transforms import IdentityTransform
1819

1920

21+
def require_pillow_feature(name):
22+
with warnings.catch_warnings():
23+
warnings.simplefilter('ignore')
24+
available = features.check(name.lower())
25+
return pytest.mark.skipif(not available, reason=f"{name} support not available")
26+
27+
2028
def test_repeated_save_with_alpha():
2129
# We want an image which has a background color of bluish green, with an
2230
# alpha of 0.25.
@@ -249,7 +257,7 @@ def test_pil_kwargs_tiff():
249257
assert tags["ImageDescription"] == "test image"
250258

251259

252-
@pytest.mark.skipif(not features.check("webp"), reason="WebP support not available")
260+
@require_pillow_feature('WebP')
253261
def test_pil_kwargs_webp():
254262
plt.plot([0, 1, 2], [0, 1, 0])
255263
buf_small = io.BytesIO()
@@ -263,7 +271,7 @@ def test_pil_kwargs_webp():
263271
assert buf_large.getbuffer().nbytes > buf_small.getbuffer().nbytes
264272

265273

266-
@pytest.mark.skipif(not features.check("avif"), reason="AVIF support not available")
274+
@require_pillow_feature('AVIF')
267275
def test_pil_kwargs_avif():
268276
plt.plot([0, 1, 2], [0, 1, 0])
269277
buf_small = io.BytesIO()
@@ -295,7 +303,7 @@ def test_gif_alpha():
295303
assert im.info["transparency"] < len(im.palette.colors)
296304

297305

298-
@pytest.mark.skipif(not features.check("webp"), reason="WebP support not available")
306+
@require_pillow_feature('WebP')
299307
def test_webp_alpha():
300308
plt.plot([0, 1, 2], [0, 1, 0])
301309
buf = io.BytesIO()
@@ -304,7 +312,7 @@ def test_webp_alpha():
304312
assert im.mode == "RGBA"
305313

306314

307-
@pytest.mark.skipif(not features.check("avif"), reason="AVIF support not available")
315+
@require_pillow_feature('AVIF')
308316
def test_avif_alpha():
309317
plt.plot([0, 1, 2], [0, 1, 0])
310318
buf = io.BytesIO()

0 commit comments

Comments
 (0)