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

View File

@@ -340,3 +340,50 @@ class TestTmpDir:
"""Calling _tmp_dir multiple times returns the same path."""
fn = self._import()
assert fn() == fn()
# ── SearchWorker (TEST_MODE) ─────────────────────────────────────────────────
class TestSearchWorkerTestMode:
"""Tests for SearchWorker.run() with TEST_MODE enabled."""
def test_returns_dummy_results_in_test_mode(self, monkeypatch):
"""With TEST_MODE=True, SearchWorker returns 5 dummy songs."""
monkeypatch.setattr("player.TEST_MODE", True)
from player import SearchWorker
results = []
worker = SearchWorker("test query")
worker.results_ready.connect(results.append)
worker.run()
assert len(results) == 1
data = results[0]
assert "songs" in data
assert "videos" in data
assert len(data["songs"]) == 5
assert data["videos"] == []
assert data["songs"][0]["title"] == "Test Song 0"
def test_dummy_results_have_required_keys(self, monkeypatch):
"""Each dummy song dict has all expected keys."""
monkeypatch.setattr("player.TEST_MODE", True)
from player import SearchWorker
results = []
worker = SearchWorker("test query")
worker.results_ready.connect(lambda r: results.append(r))
worker.run()
song = results[0]["songs"][0]
assert "videoId" in song
assert "title" in song
assert "artists" in song
assert len(song["artists"]) == 1
assert song["artists"][0]["name"] == "Artist 0"
def test_sets_query_correctly(self):
"""SearchWorker stores the query."""
from player import SearchWorker
worker = SearchWorker("my search query")
assert worker._query == "my search query"