Tags and files fuctions

This commit is contained in:
Jan Doubravský
2025-09-24 14:30:23 +02:00
parent 9ea2da0d7f
commit 531b05cd03
14 changed files with 661 additions and 169 deletions

40
tests/test_image.py Normal file
View File

@@ -0,0 +1,40 @@
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.image 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)