Skip to content
Snippets Groups Projects

Add support for Python 3.12

Merged Eva Bardou requested to merge support-py312 into main
2 files
+ 2
2
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 18
3
@@ -2,8 +2,11 @@
# This code is licensed under CeCILL-C
import shutil
from pathlib import Path
import numpy as np
import pytest
from PIL import Image, ImageChops, ImageSequence
from dan.ocr.predict.attention import (
Level,
@@ -25,6 +28,20 @@ PREDICTION_DATA_PATH = FIXTURES / "prediction"
FONT_PATH = FIXTURES.parent.parent / "fonts/LinuxLibertine.ttf"
def _compare_gifs(reference: Path, hypothesis: Path) -> bool:
im1 = Image.open(reference)
im2 = Image.open(hypothesis)
identical = True
for ref_frame, hyp_frame in zip(
ImageSequence.Iterator(im1), ImageSequence.Iterator(im2)
):
# Allowed 3% difference
identical &= (
np.asarray(ImageChops.difference(ref_frame, hyp_frame)).mean() < 0.03 * 255
)
return identical
@pytest.mark.parametrize(
(
"text",
@@ -206,6 +223,4 @@ def test_plot_attention(
outname = image_name + "_line.gif"
assert (tmp_path / outname).read_bytes() == (
PREDICTION_DATA_PATH / outname
).read_bytes()
assert _compare_gifs(tmp_path / outname, PREDICTION_DATA_PATH / outname)
Loading