import pytest import cv2 import numpy as np from pipeline_b import star_detector def test_file_exists_and_is_an_image(tmp_path): file = tmp_path / "image.jpg" tableau_image = np.random.randint(0, 256, (64, 64), dtype=np.uint8) cv2.imwrite(str(file), tableau_image) assert isinstance(star_detector.reading_picture(file), np.ndarray) def test_file_exists_not_an_image(tmp_path): file = tmp_path / "file.txt" file.write_text("Not an image.") with pytest.raises(ValueError): star_detector.reading_picture(file) def test_file_does_not_exists(tmp_path): with pytest.raises(FileNotFoundError): star_detector.reading_picture(tmp_path/"do_I_exist.txt") def test_blob_detector_actually_detects_a_blob(): tableau_image = np.zeros((64,64), dtype=np.uint8) cv2.circle(tableau_image, center=(23, 31), radius = 5, color= 255, thickness=-1) assertion = (star_detector.blob_detector(tableau_image) != []) for star in star_detector.blob_detector(tableau_image): if abs(star[0] - 23) > 0.001 or abs(star[1] - 31) > 0.001: assertion = False assert assertion == True