openmv/scripts/unittest/tests/copy.py
iabdalkader 4b1837f72e scripts: Update unit tests.
Co-authored-by: Kwabena W Agyeman <kwagyeman@users.noreply.github.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-10-18 17:14:36 +02:00

39 lines
927 B
Python

def unittest(data_path, temp_path):
import image
# Create original image
img = image.Image(50, 50, image.GRAYSCALE)
# Fill with value 100
for y in range(50):
for x in range(50):
img.set_pixel(x, y, 100)
# Create a copy
img_copy = img.copy()
# Verify copy has same dimensions and values
if img_copy.width() != 50 or img_copy.height() != 50:
return False
stats = img_copy.get_statistics()
if stats.mean() != 100:
return False
# Modify original image
for y in range(50):
for x in range(50):
img.set_pixel(x, y, 200)
# Verify copy is independent (still has value 100)
stats_copy = img_copy.get_statistics()
if stats_copy.mean() != 100:
return False
# Verify original changed to 200
stats_orig = img.get_statistics()
if stats_orig.mean() != 200:
return False
return True