import sys, os import tempfile from pathlib import Path import pytest # přidáme src do sys.path (pokud nespouštíš pytest s -m nebo PYTHONPATH=src) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src"))) from core.media_utils import load_icon from PIL import Image, ImageTk import tkinter as tk @pytest.fixture(scope="module") def tk_root(): """Fixture pro inicializaci Tkinteru (nutné pro ImageTk).""" root = tk.Tk() yield root root.destroy() def test_load_icon_returns_photoimage(tk_root): # vytvoříme dočasný obrázek with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp: tmp_path = Path(tmp.name) try: # vytvoříme 100x100 červený obrázek img = Image.new("RGB", (100, 100), color="red") img.save(tmp_path) icon = load_icon(tmp_path) # musí být PhotoImage assert isinstance(icon, ImageTk.PhotoImage) # ověříme velikost 16x16 assert icon.width() == 16 assert icon.height() == 16 finally: tmp_path.unlink(missing_ok=True)