added function to compare images
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user