2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
from pathlib import Path
|
|
|
|
|
2020-02-18 15:30:56 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2014-01-21 01:05:30 +04:00
|
|
|
from PIL import Image
|
|
|
|
|
2020-02-18 16:50:34 +03:00
|
|
|
from .helper import assert_image_equal, hopper
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2024-08-13 12:03:14 +03:00
|
|
|
pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
2020-02-18 16:50:34 +03:00
|
|
|
RGB_MODE = "RGB"
|
2017-10-02 01:23:18 +03:00
|
|
|
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_write_lossless_rgb(tmp_path: Path) -> None:
|
2020-02-18 16:50:34 +03:00
|
|
|
temp_file = str(tmp_path / "temp.webp")
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2020-02-18 16:50:34 +03:00
|
|
|
hopper(RGB_MODE).save(temp_file, lossless=True)
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2020-02-18 16:50:34 +03:00
|
|
|
with Image.open(temp_file) as image:
|
|
|
|
image.load()
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2020-02-18 16:50:34 +03:00
|
|
|
assert image.mode == RGB_MODE
|
|
|
|
assert image.size == (128, 128)
|
|
|
|
assert image.format == "WEBP"
|
|
|
|
image.load()
|
|
|
|
image.getdata()
|
2014-01-21 01:05:30 +04:00
|
|
|
|
2020-02-18 16:50:34 +03:00
|
|
|
assert_image_equal(image, hopper(RGB_MODE))
|