From 88f84105b5adbf2a14c6fcef4a88d7825416ec83 Mon Sep 17 00:00:00 2001 From: Alexander Piskun Date: Sun, 16 Jul 2023 17:27:56 +0300 Subject: [PATCH] test for OpenCV bug #89 Signed-off-by: Alexander Piskun --- tests/opencv_bug.py | 11 +++++++++++ tests/opencv_test.py | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/opencv_bug.py diff --git a/tests/opencv_bug.py b/tests/opencv_bug.py new file mode 100644 index 00000000..b7f40ffe --- /dev/null +++ b/tests/opencv_bug.py @@ -0,0 +1,11 @@ +# https://github.com/bigcat88/pillow_heif/issues/89 + +from io import BytesIO + +import cv2 # noqa +from PIL import Image + +from pillow_heif import from_pillow, libheif_info + +print(libheif_info()) +from_pillow(Image.linear_gradient(mode="L")).save(BytesIO(), format="HEIF") diff --git a/tests/opencv_test.py b/tests/opencv_test.py index 17c3ad6e..400aee92 100644 --- a/tests/opencv_test.py +++ b/tests/opencv_test.py @@ -1,8 +1,10 @@ # With OpenCV, we test BGR, BGRA, BGR;16 and BGRA;16 modes import os +import sys from io import BytesIO from pathlib import Path +from subprocess import CalledProcessError, run import pytest from helpers import compare_hashes, hevc_enc @@ -145,3 +147,13 @@ def test_read_8_10_12_bit(img): path_to_png = path_to_png.replace("_10_", "_16_") path_to_png = path_to_png.replace("_12_", "_16_") compare_hashes([BytesIO(img_encode), path_to_png], hash_size=16) + + +def test_opencv_crash(): + # https://github.com/bigcat88/pillow_heif/issues/89 + path_to_test_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "opencv_bug.py") + if sys.platform.lower() == "darwin": + with pytest.raises(CalledProcessError): + run([sys.executable, path_to_test_file], check=True) + else: + run([sys.executable, path_to_test_file], check=True)