36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import pytest
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
from logimage.infrastructure.image.local_file_source import LocalFileImageSource
|
|
from logimage.domain.value_objects.image_data import ImageData
|
|
|
|
|
|
def test_fetch_returns_image_data(tmp_path: Path) -> None:
|
|
img = Image.new("RGB", (50, 50), color=(100, 150, 200))
|
|
path = tmp_path / "test_icon.png"
|
|
img.save(path, format="PNG")
|
|
|
|
source = LocalFileImageSource(path)
|
|
result = source.fetch()
|
|
|
|
assert isinstance(result, ImageData)
|
|
assert result.content == path.read_bytes()
|
|
assert result.title == "test_icon"
|
|
|
|
|
|
def test_fetch_title_is_stem(tmp_path: Path) -> None:
|
|
img = Image.new("RGB", (10, 10))
|
|
path = tmp_path / "my_cool_image.jpg"
|
|
img.save(path, format="JPEG")
|
|
|
|
source = LocalFileImageSource(path)
|
|
result = source.fetch()
|
|
|
|
assert result.title == "my_cool_image"
|
|
|
|
|
|
def test_fetch_raises_if_file_not_found() -> None:
|
|
source = LocalFileImageSource(Path("/nonexistent/image.png"))
|
|
with pytest.raises(FileNotFoundError):
|
|
source.fetch()
|