test: 100% coverage on core modules with headless CI support
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:
2026-06-04 20:53:00 +03:00
parent 5ce18506c1
commit dc3c735655
9 changed files with 897 additions and 30 deletions

45
gui.py
View File

@@ -607,16 +607,19 @@ class AudioVisualizer(QWidget):
_TICK_MS = 16
# Spectral gradient colour stops (left → right / bass → treble)
SPECTRUM_COLORS = [
QColor(139, 92, 246), # 0.0 Violet (bass)
QColor(168, 85, 247), # 0.1 Purple
QColor(236, 72, 153), # 0.25 Pink
QColor(251, 146, 134), # 0.4 Rose
QColor(251, 207, 132), # 0.5 Amber (centre)
QColor(251, 207, 132), # 0.6 Amber
QColor(236, 72, 153), # 0.75 Pink
QColor(168, 85, 247), # 0.9 Purple
QColor(139, 92, 246), # 1.0 Violet (bass mirror)
# Stored as raw (R, G, B) tuples to avoid Qt dependency at class-definition
# time — needed so the module can be imported for pure-helper-function tests
# without a real PySide6 runtime.
_SPECTRUM_COLOR_STOPS = [
(139, 92, 246), # 0.0 Violet (bass)
(168, 85, 247), # 0.1 Purple
(236, 72, 153), # 0.25 Pink
(251, 146, 134), # 0.4 Rose
(251, 207, 132), # 0.5 Amber (centre)
(251, 207, 132), # 0.6 Amber
(236, 72, 153), # 0.75 Pink
(168, 85, 247), # 0.9 Purple
(139, 92, 246), # 1.0 Violet (bass mirror)
]
def __init__(self, parent=None):
@@ -887,21 +890,23 @@ class AudioVisualizer(QWidget):
@staticmethod
def _spectrum_color(t: float) -> QColor:
cols = AudioVisualizer.SPECTRUM_COLORS
"""Interpolate between colour stops and return a ``QColor``."""
stops = AudioVisualizer._SPECTRUM_COLOR_STOPS
if t <= 0.0:
return cols[0]
r, g, b = stops[0]
return QColor(r, g, b)
if t >= 1.0:
return cols[-1]
t_scaled = t * (len(cols) - 1)
r, g, b = stops[-1]
return QColor(r, g, b)
t_scaled = t * (len(stops) - 1)
idx = int(t_scaled)
frac = t_scaled - idx
c1 = cols[idx]
c2 = cols[min(idx + 1, len(cols) - 1)]
c1 = stops[idx]
c2 = stops[min(idx + 1, len(stops) - 1)]
return QColor(
int(c1.red() + (c2.red() - c1.red()) * frac),
int(c1.green() + (c2.green() - c1.green()) * frac),
int(c1.blue() + (c2.blue() - c1.blue()) * frac),
int(c1.alpha() + (c2.alpha() - c1.alpha()) * frac),
int(c1[0] + (c2[0] - c1[0]) * frac),
int(c1[1] + (c2[1] - c1[1]) * frac),
int(c1[2] + (c2[2] - c1[2]) * frac),
)