From 7f55f360a3f5c1549024386e236ec4db1a26212e Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 17 May 2026 22:18:07 -0400 Subject: [PATCH] =?UTF-8?q?fix(test):=20phash=20'far'=20case=20needs=20str?= =?UTF-8?q?uctured=20images=20=E2=80=94=20solid=20colors=20phash-collapse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/test_phash_util.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/test_phash_util.py b/tests/test_phash_util.py index 11e81d1..5d61553 100644 --- a/tests/test_phash_util.py +++ b/tests/test_phash_util.py @@ -10,6 +10,18 @@ def _img(color, size=(64, 64)): return Image.new("RGB", size, color) +def _split(orient, size=64): + """A structured image (half black / half white) so it has real DCT + content — solid colors all phash-collapse to the same value.""" + im = Image.new("L", (size, size), 0) + px = im.load() + for y in range(size): + for x in range(size): + if (x if orient == "v" else y) >= size // 2: + px[x, y] = 255 + return im.convert("RGB") + + def test_compute_phash_stable_and_hex(): h1 = compute_phash(_img((10, 120, 200))) h2 = compute_phash(_img((10, 120, 200))) @@ -22,8 +34,9 @@ def test_compute_phash_none_for_non_image(): def test_find_similar_none_when_far(): - new = compute_phash(_img((0, 0, 0))) - cand = (compute_phash(_img((255, 255, 255))), 100, 100, 7) + # Vertical vs horizontal split = structurally orthogonal → far apart. + new = compute_phash(_split("v")) + cand = (compute_phash(_split("h")), 100, 100, 7) rel, mid = find_similar(new, 50, 50, [cand], threshold=2) assert rel == "none" and mid is None