Skip to content

Commit 5760573

Browse files
committed
Add tests for WebP format
1 parent 145984f commit 5760573

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/matplotlib/tests/test_agg.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ def test_pil_kwargs_tiff():
248248
tags = {TiffTags.TAGS_V2[k].name: v for k, v in im.tag_v2.items()}
249249
assert tags["ImageDescription"] == "test image"
250250

251+
def test_pil_kwargs_webp():
252+
plt.plot([0, 1, 2], [0, 1, 0])
253+
buf_small = io.BytesIO()
254+
pil_kwargs_low = {"quality": 1}
255+
plt.savefig(buf_small, format="webp", pil_kwargs=pil_kwargs_low)
256+
buf_large = io.BytesIO()
257+
pil_kwargs_high = {"quality": 100}
258+
plt.savefig(buf_large, format="webp", pil_kwargs=pil_kwargs_high)
259+
assert buf_large.getbuffer().nbytes > buf_small.getbuffer().nbytes
260+
261+
def test_webp_alpha():
262+
plt.plot([0, 1, 2], [0, 1, 0])
263+
buf = io.BytesIO()
264+
plt.savefig(buf, format="webp", transparent=True)
265+
im = Image.open(buf)
266+
assert im.mode == "RGBA"
267+
268+
251269

252270
def test_draw_path_collection_error_handling():
253271
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)