From ce08ee4ccd183ab95c07126116551871307e3f65 Mon Sep 17 00:00:00 2001 From: brian Date: Mon, 25 Nov 2024 16:37:52 +0000 Subject: [PATCH] added function to compare images --- .../tests/integration/image_crud_test.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/shared/datastore/tests/integration/image_crud_test.py b/shared/datastore/tests/integration/image_crud_test.py index bb1589e..c9e7d40 100644 --- a/shared/datastore/tests/integration/image_crud_test.py +++ b/shared/datastore/tests/integration/image_crud_test.py @@ -1,10 +1,30 @@ """Integration tests related to image CRUD.""" +import numpy as np from PIL import Image from shared.datastore import connect_minio, get_image, put_image +def same_image( + img_a: Image.Image, + img_b: Image.Image, +) -> bool: + """Check if two images contain the same data.""" + assert isinstance(img_a, Image.Image) + assert isinstance(img_b, Image.Image) + # check if images have a comparable number of channels + if img_a.getbands() != img_b.getbands(): + return False + # calculate pixel difference between images + img_a_arr = np.asarray(img_a) + img_b_arr = np.asarray(img_b) + diff = np.subtract(img_a_arr, img_b_arr) + if np.sum(diff) != 0: + return False + return True + + def test_should_get_image( image_in_minio, ): @@ -32,7 +52,7 @@ def test_should_put_image( client=client, object_name=object_name, ) - assert received_image == image + assert same_image(received_image, image) def test_should_update_image(