import os import tempfile from pathlib import Path import pytest from PIL import Image from photo_stitcher import core def create_temp_image(color: tuple[int, int, int], size=(10, 10)) -> str: temp_dir = tempfile.mkdtemp() img_path = os.path.join(temp_dir, f"test_{color[0]}_{color[1]}_{color[2]}.png") img = Image.new("RGB", size, color=color) img.save(img_path) return img_path def test_combine_images_creates_output(tmp_path: Path): img1 = create_temp_image((255, 0, 0)) img2 = create_temp_image((0, 0, 255)) output_file = tmp_path / "combined.tif" core.combine_images([img1, img2], str(output_file)) assert output_file.exists(), "Output file should exist after combining." with Image.open(output_file) as result_img: assert result_img.size == (10, 10), "Output size should match input images." def test_combine_images_invalid_input_raises(tmp_path: Path): output_file = tmp_path / "fail.tif" with pytest.raises((FileNotFoundError, ValueError, OSError)): core.combine_images(["non_existent.jpg"], str(output_file)) def test_combine_images_empty_list_raises(tmp_path: Path): output_file = tmp_path / "empty.tif" with pytest.raises(ValueError): core.combine_images([], str(output_file)) def test_combine_images_with_corrupt_file(tmp_path: Path): # Create a fake broken image file broken_path = tmp_path / "broken.jpg" broken_path.write_text("not an image") output_file = tmp_path / "out.tif" with pytest.raises((OSError, ValueError)): core.combine_images([str(broken_path)], str(output_file))