from pathlib import Path from logimage.domain.ports.image_source import ImageSource from logimage.domain.ports.image_converter import ImageConverter from logimage.domain.ports.pdf_exporter import PdfExporter from logimage.domain.value_objects.image_data import ImageData from logimage.domain.value_objects.grid import Grid from logimage.domain.entities.puzzle import NonogramPuzzle _MINIMAL_CELLS = [[i % 2 == 0] * 5 for i in range(5)] MINIMAL_GRID = Grid.from_list(_MINIMAL_CELLS) class FakeImageSource(ImageSource): def __init__( self, content: bytes = b"fake", title: str = "Fake Puzzle", ) -> None: self._content = content self._title = title self.fetch_calls: list[str | None] = [] def fetch(self, theme: str | None = None) -> ImageData: self.fetch_calls.append(theme) return ImageData(content=self._content, title=self._title) class FakeImageConverter(ImageConverter): def __init__(self, grid: Grid = MINIMAL_GRID) -> None: self._grid = grid def to_grid(self, image_bytes: bytes, width: int, height: int) -> Grid: return self._grid class FakePdfExporter(PdfExporter): def __init__(self) -> None: self.exported_puzzles: list[NonogramPuzzle] = [] self.last_path: Path | None = None self.last_with_solution: bool = False def export( self, puzzles: list[NonogramPuzzle], path: Path, with_solution: bool = False, ) -> None: self.exported_puzzles = list(puzzles) self.last_path = path self.last_with_solution = with_solution