Add image_processing/tests/test_core.py
This commit is contained in:
parent
f0a70c256f
commit
8be0720aa4
1 changed files with 50 additions and 0 deletions
50
image_processing/tests/test_core.py
Normal file
50
image_processing/tests/test_core.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import os
|
||||
import numpy as np
|
||||
import pytest
|
||||
import cv2
|
||||
|
||||
from image_processing.core import process_images
|
||||
|
||||
@pytest.fixture
|
||||
def sample_image_dir(tmp_path):
|
||||
# Erzeuge ein temporäres Verzeichnis mit synthetischen Testbildern
|
||||
img_dir = tmp_path / 'data' / 'raw'
|
||||
img_dir.mkdir(parents=True, exist_ok=True)
|
||||
for i in range(5):
|
||||
img = np.full((10, 10, 3), fill_value=50 * i, dtype=np.uint8)
|
||||
file_path = img_dir / f'img_{i}.jpg'
|
||||
cv2.imwrite(str(file_path), img)
|
||||
return img_dir
|
||||
|
||||
|
||||
def test_process_images_stacking_result(sample_image_dir):
|
||||
# Normalfall: Stacking mehrerer gültiger Bilder
|
||||
images = sorted(str(p) for p in sample_image_dir.glob('*.jpg'))
|
||||
result = process_images(images)
|
||||
assert isinstance(result, np.ndarray), 'Ergebnis muss ein NumPy-Array sein.'
|
||||
assert result.ndim == 3, 'Gestacktes Bild muss eine 3D-Matrix (H, W, C) sein.'
|
||||
assert result.shape == (10, 10, 3), 'Dimensionen der Ausgabe müssen den Eingabebildern entsprechen.'
|
||||
assert np.all(result >= 0) and np.all(result <= 255), 'Pixelwerte müssen im gültigen Bereich liegen.'
|
||||
|
||||
|
||||
def test_process_images_empty_list():
|
||||
# Edge-Case: Leere Liste
|
||||
with pytest.raises((ValueError, AssertionError, FileNotFoundError)):
|
||||
_ = process_images([])
|
||||
|
||||
|
||||
def test_process_images_invalid_path(tmp_path):
|
||||
# Fehlerfall: Nicht vorhandene Datei
|
||||
fake_path = str(tmp_path / 'does_not_exist.jpg')
|
||||
with pytest.raises((ValueError, FileNotFoundError, AssertionError)):
|
||||
_ = process_images([fake_path])
|
||||
|
||||
|
||||
def test_process_images_image_consistency(sample_image_dir):
|
||||
# Prüfe, dass alle Eingabebilder gleich groß sind und Ergebnis konsistent bleibt
|
||||
img_paths = sorted(str(p) for p in sample_image_dir.glob('*.jpg'))
|
||||
sizes = [cv2.imread(p).shape for p in img_paths]
|
||||
assert len(set(sizes)) == 1, 'Alle Testbilder müssen gleiche Dimensionen haben.'
|
||||
result = process_images(img_paths)
|
||||
ref_shape = sizes[0]
|
||||
assert result.shape == ref_shape, 'Gestacktes Bild muss gleiche Dimension wie Eingabebilder haben.'
|
||||
Loading…
Reference in a new issue