test: 100% coverage on core modules with headless CI support
Some checks failed
SonarQube Code Quality Scan / SonarQube Scan (push) Failing after 1m20s
Some checks failed
SonarQube Code Quality Scan / SonarQube Scan (push) Failing after 1m20s
- Fix dead exception handler in discord_rpc.py (unreachable DiscordNotFound) - Replace QMediaPlayer=None stub with proper _StubQMediaPlayer in player.py - Make AudioVisualizer color stops Qt-free (raw tuples instead of QColor) - Add conftest QApplication creation check for headless CI detection - Add test_gui_widgets.py _qt_available() guard for headless environments - Add test_main.py (30 tests) for main.py entry point and env vars - Add test_import_fallbacks.py (14 tests) for Qt import fallback paths - Extend test_gui_helpers.py with _css, _get_thumbnail_nam, _cached_thumb_path tests - Extend test_discord_rpc.py with direct _connect() test for DiscordNotFound - Extend test_player_helpers.py with SearchWorker test-mode tests - Ensure import fallback tests clean up sys.modules to avoid cross-test pollution 100% coverage achieved on: config.py, discord_rpc.py, main.py, music_db.py
This commit is contained in:
@@ -176,12 +176,25 @@ def _install_stubs() -> None:
|
||||
|
||||
_QT_AVAILABLE = False
|
||||
try:
|
||||
# Attempt real import — this will fail in headless CI.
|
||||
# Step 1: Try to import PySide6 modules. These can succeed even in
|
||||
# headless CI because no display is needed to import the Python bindings.
|
||||
import PySide6 # noqa: F401
|
||||
import PySide6.QtCore # noqa: F401
|
||||
import PySide6.QtMultimedia # noqa: F401
|
||||
|
||||
# Step 2: Verify that a QApplication can actually be created.
|
||||
# In headless CI without QT_QPA_PLATFORM=offscreen this will raise
|
||||
# a RuntimeError ("Cannot create a QWidget without a QApplication")
|
||||
# or OSError ("Could not connect to display").
|
||||
from PySide6.QtWidgets import QApplication
|
||||
_existing_app = QApplication.instance()
|
||||
if _existing_app is None:
|
||||
_test_app = QApplication([])
|
||||
_test_app.quit()
|
||||
del _test_app
|
||||
|
||||
_QT_AVAILABLE = True
|
||||
except (ImportError, OSError):
|
||||
except (ImportError, OSError, RuntimeError):
|
||||
pass
|
||||
|
||||
if not _QT_AVAILABLE:
|
||||
|
||||
Reference in New Issue
Block a user