From 566e751f68e835afb6a37c704cd3e0a4b02c0e91 Mon Sep 17 00:00:00 2001 From: Mika Date: Sun, 15 Mar 2026 03:07:39 +0000 Subject: [PATCH] Add photo_stitcher/tests/test_core.py --- photo_stitcher/tests/test_core.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 photo_stitcher/tests/test_core.py diff --git a/photo_stitcher/tests/test_core.py b/photo_stitcher/tests/test_core.py new file mode 100644 index 0000000..ea41358 --- /dev/null +++ b/photo_stitcher/tests/test_core.py @@ -0,0 +1,47 @@ +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)) \ No newline at end of file