- Переименован Python-пакет: headset_companion → lgcompanion - Переименованы исполняемые файлы: headset-companion → lgcompanion, headset-companion-gui → lgcompanion-gui - Переименованы сервис, desktop-файл, иконка, каталог конфигурации - Обновлены все импорты, docstrings и пользовательские строки - Обновлено описание в README.md и AGENTS.md: программа теперь позиционируется как универсальный компаньон для USB-гарнитур, из коробки поддерживаются SteelSeries Arctis - Убраны привязки к Arctis 7 в defaults/placeholders GUI и CLI - Обновлены ссылки репозитория на git.linux-gaming.ru
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
"""Smoke tests for Qt Style Sheets used by the GUI."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.skipif(
|
|
os.environ.get("LGCOMPANION_SKIP_GUI_TESTS") == "1",
|
|
reason="GUI tests disabled by environment variable",
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def _qt_app() -> Any:
|
|
"""Create a single QApplication for all GUI style tests."""
|
|
# Offscreen platform keeps CI headless but still exercises QSS parsing.
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication([])
|
|
return app
|
|
|
|
|
|
def test_qss_for_all_themes_does_not_emit_warnings(_qt_app: Any) -> None:
|
|
"""Loading the generated QSS must not produce Qt runtime warnings.
|
|
|
|
Python linters cannot validate Qt Style Sheets because QSS is just a
|
|
string. Qt reports malformed declarations (``Unknown property ...``,
|
|
``Could not parse ...``) only at runtime. This smoke-test installs a
|
|
message handler, applies every theme, and fails if any warning appears.
|
|
"""
|
|
from PySide6.QtCore import QtMsgType, qInstallMessageHandler
|
|
from PySide6.QtWidgets import QWidget
|
|
|
|
from lgcompanion.gui.styles import get_main_style_qss
|
|
|
|
warnings: list[str] = []
|
|
|
|
def _message_handler(
|
|
mode: QtMsgType,
|
|
context: Any,
|
|
message: str,
|
|
/,
|
|
) -> None:
|
|
if mode in (QtMsgType.QtWarningMsg, QtMsgType.QtCriticalMsg):
|
|
warnings.append(message)
|
|
|
|
previous_handler: Callable[..., None] | None = qInstallMessageHandler(
|
|
_message_handler
|
|
)
|
|
try:
|
|
for theme in ("auto", "dark", "light"):
|
|
qss = get_main_style_qss(theme)
|
|
assert qss.strip(), f"QSS for theme {theme!r} is empty"
|
|
|
|
widget = QWidget()
|
|
widget.setStyleSheet(qss)
|
|
widget.ensurePolished()
|
|
widget.deleteLater()
|
|
finally:
|
|
qInstallMessageHandler(previous_handler)
|
|
|
|
qss_warnings = [w for w in warnings if "QCss" in w or "Style" in w]
|
|
assert not qss_warnings, f"QSS produced Qt warnings: {qss_warnings}"
|