Skip to content

Commit

Permalink
test for OpenCV bug #89
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 committed Jul 16, 2023
1 parent 4b85204 commit 88f8410
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/opencv_bug.py
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 12 additions & 0 deletions tests/opencv_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 88f8410

Please sign in to comment.