import json import os import tempfile from src.session_history import HistoryEntry, SessionHistory from src.image_tagger import _to_pil_image def test_history_toggle_like_persists_to_disk(): fd, path = tempfile.mkstemp(suffix='.json') os.close(fd) try: hist = SessionHistory(file_path=path) hist.add(HistoryEntry('prompt', ['one', 'two'])) assert hist.toggle_like(0, 1) is True with open(path, encoding='utf-8') as f: data = json.load(f) assert data[0]['liked_indices'] == [1] finally: if os.path.exists(path): os.remove(path) def test_to_pil_image_accepts_rgba_numpy(): import numpy as np rgba = np.zeros((4, 4, 4), dtype=np.uint8) rgba[..., 0] = 255 rgba[..., 3] = 255 img = _to_pil_image(rgba) assert img.mode == 'RGB' assert img.size == (4, 4) def test_to_pil_image_accepts_grayscale_numpy(): import numpy as np gray = np.ones((3, 5), dtype=np.uint8) * 127 img = _to_pil_image(gray) assert img.mode == 'RGB' assert img.size == (5, 3)