diff --git a/tests/common.py b/tests/common.py index c67db04e5..ce1f2848b 100644 --- a/tests/common.py +++ b/tests/common.py @@ -5,6 +5,7 @@ import functools import os import types +import typing from typing import TYPE_CHECKING from unittest import TestCase as _Base @@ -113,13 +114,14 @@ def assertNdarraysEqual(a: np.ndarray, b: np.ndarray) -> None: assert False, f"ndarrays contents differ\n{msg}" +@typing.no_type_check def assertImagesAlmostEqual(a: Image, b: Image, epsilon: float = 0.1) -> None: import PIL.ImageFilter as ImageFilter assert a.size == b.size a = a.filter(ImageFilter.BLUR).getdata() b = b.filter(ImageFilter.BLUR).getdata() - for i, ax, bx in zip(range(len(a)), a, b): # type: ignore + for i, ax, bx in zip(range(len(a)), a, b): diff = sum(abs(ac / 256 - bc / 256) for ac, bc in zip(ax, bx)) / 3 assert diff < epsilon, f"images differed by {diff} at index {i}; {ax} {bx}"