GUI rework to Qt6
This commit is contained in:
@@ -1,62 +1,76 @@
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from src.ui.utils import load_icon
|
||||
from PIL import Image, ImageTk
|
||||
import tkinter as tk
|
||||
# Skip all tests if no display is available (CI environment)
|
||||
pytestmark = pytest.mark.skipif(
|
||||
os.environ.get("DISPLAY") is None and os.environ.get("WAYLAND_DISPLAY") is None,
|
||||
reason="No display available for GUI tests"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def tk_root():
|
||||
"""Fixture pro inicializaci Tkinteru (nutné pro ImageTk)."""
|
||||
root = tk.Tk()
|
||||
yield root
|
||||
root.destroy()
|
||||
def qapp():
|
||||
"""Fixture to initialize QApplication for Qt tests."""
|
||||
from PySide6.QtWidgets import QApplication
|
||||
app = QApplication.instance()
|
||||
if app is None:
|
||||
app = QApplication([])
|
||||
yield app
|
||||
|
||||
|
||||
def test_load_icon_returns_photoimage(tk_root):
|
||||
"""Test že load_icon vrací PhotoImage"""
|
||||
# vytvoříme dočasný obrázek
|
||||
def test_load_icon_returns_qicon(qapp):
|
||||
"""Test that load_icon returns QIcon"""
|
||||
from src.ui.utils import load_icon
|
||||
from PySide6.QtGui import QIcon
|
||||
from PIL import Image
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
||||
tmp_path = Path(tmp.name)
|
||||
try:
|
||||
# vytvoříme 100x100 červený obrázek
|
||||
# Create 100x100 red image
|
||||
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
|
||||
# Must be QIcon
|
||||
assert isinstance(icon, QIcon)
|
||||
# Icon should not be null
|
||||
assert not icon.isNull()
|
||||
finally:
|
||||
tmp_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_load_icon_resizes_image(tk_root):
|
||||
"""Test že load_icon správně změní velikost obrázku"""
|
||||
def test_load_icon_custom_size(qapp):
|
||||
"""Test that load_icon respects custom size parameter"""
|
||||
from src.ui.utils import load_icon
|
||||
from PIL import Image
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
||||
tmp_path = Path(tmp.name)
|
||||
try:
|
||||
# vytvoříme velký obrázek 500x500
|
||||
img = Image.new("RGB", (500, 500), color="blue")
|
||||
img.save(tmp_path)
|
||||
|
||||
icon = load_icon(tmp_path)
|
||||
icon = load_icon(tmp_path, size=32)
|
||||
|
||||
# i velký obrázek by měl být zmenšen na 16x16
|
||||
assert icon.width() == 16
|
||||
assert icon.height() == 16
|
||||
# Icon should be created successfully
|
||||
assert not icon.isNull()
|
||||
# Available sizes should include the requested size
|
||||
sizes = icon.availableSizes()
|
||||
assert len(sizes) > 0
|
||||
finally:
|
||||
tmp_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_load_icon_different_formats(tk_root):
|
||||
"""Test načítání různých formátů obrázků"""
|
||||
def test_load_icon_different_formats(qapp):
|
||||
"""Test loading different image formats"""
|
||||
from src.ui.utils import load_icon
|
||||
from PySide6.QtGui import QIcon
|
||||
from PIL import Image
|
||||
|
||||
formats = [".png", ".jpg", ".bmp"]
|
||||
|
||||
for fmt in formats:
|
||||
@@ -68,8 +82,7 @@ def test_load_icon_different_formats(tk_root):
|
||||
|
||||
icon = load_icon(tmp_path)
|
||||
|
||||
assert isinstance(icon, ImageTk.PhotoImage)
|
||||
assert icon.width() == 16
|
||||
assert icon.height() == 16
|
||||
assert isinstance(icon, QIcon)
|
||||
assert not icon.isNull()
|
||||
finally:
|
||||
tmp_path.unlink(missing_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user