"""テスト用のダミーデータ(conftest の fixture)の前提を確かめる."""
import hashlib
from pathlib import Path
from conftest import TONGUE_COLOR_FOLDERS, write_dummy_png
from PIL import Image
def test_tongue_color_folders_has_nine_entries() -> None:
assert len(TONGUE_COLOR_FOLDERS) == 9
labels = {label for label, _ in TONGUE_COLOR_FOLDERS.values()}
assert labels == {"light_red", "dark_red", "purple", "red", "pale"}
# normal は light_red だけ(SPEC_02 の組み合わせの制約)
for label, severity in TONGUE_COLOR_FOLDERS.values():
assert (severity == "normal") == (label == "light_red")
def test_tongue_color_source_layout(tongue_color_source) -> None:
root: Path = tongue_color_source.root
folders = sorted(p.name for p in root.iterdir())
assert folders == sorted(TONGUE_COLOR_FOLDERS)
for folder in TONGUE_COLOR_FOLDERS:
assert len(list((root / folder).iterdir())) == 2
images = tongue_color_source.images
assert len(images) == 18
assert [img.number for img in images] == list(range(1, 19))
for img in images:
assert img.path == root / img.folder / f"{img.number}.png"
assert img.path.is_file()
assert (img.label, img.severity) == TONGUE_COLOR_FOLDERS[img.folder]
def test_tongue_color_source_images_are_distinct_valid_pngs(tongue_color_source) -> None:
hashes = set()
for img in tongue_color_source.images:
hashes.add(hashlib.sha256(img.path.read_bytes()).hexdigest())
with Image.open(img.path) as opened:
assert opened.format == "PNG"
assert len(hashes) == 18
def test_write_dummy_png_is_deterministic_and_unique(tmp_path: Path) -> None:
a = write_dummy_png(tmp_path / "a" / "1.png", seed=300).read_bytes()
b = write_dummy_png(tmp_path / "b" / "1.png", seed=300).read_bytes()
c = write_dummy_png(tmp_path / "c" / "1.png", seed=300 + 256).read_bytes()
assert a == b
assert a != c
def test_store_dir_exists_and_is_empty(store_dir: Path) -> None:
assert store_dir.is_dir()
assert store_dir.name == "store"
assert list(store_dir.iterdir()) == []