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:
@@ -158,3 +158,68 @@ class TestArtistsFromJson:
|
||||
fn = self._import()
|
||||
j = json.dumps([{"name": "Real"}, 42, "str", {"name": "Also Real"}])
|
||||
assert fn(j) == "Real, Also Real"
|
||||
|
||||
|
||||
# ── _css ───────────────────────────────────────────────────────────────────
|
||||
|
||||
class TestCss:
|
||||
"""Tests for the _css helper."""
|
||||
|
||||
def _import(self):
|
||||
from gui import _css
|
||||
return _css
|
||||
|
||||
def test_joins_multiple_parts(self):
|
||||
fn = self._import()
|
||||
assert fn("color: red;", "background: blue;") == "color: red;background: blue;"
|
||||
|
||||
def test_single_part(self):
|
||||
fn = self._import()
|
||||
assert fn("color: red;") == "color: red;"
|
||||
|
||||
def test_empty_parts(self):
|
||||
fn = self._import()
|
||||
assert fn() == ""
|
||||
|
||||
|
||||
# ── _get_thumbnail_nam ────────────────────────────────────────────────────
|
||||
|
||||
class TestGetThumbnailNam:
|
||||
"""Tests for the _get_thumbnail_nam helper."""
|
||||
|
||||
def _import(self):
|
||||
from gui import _get_thumbnail_nam
|
||||
return _get_thumbnail_nam
|
||||
|
||||
def test_returns_network_access_manager(self):
|
||||
fn = self._import()
|
||||
nam = fn()
|
||||
# Should return some kind of object (QNetworkAccessManager or MagicMock)
|
||||
assert nam is not None
|
||||
|
||||
def test_is_singleton(self):
|
||||
fn = self._import()
|
||||
nam1 = fn()
|
||||
nam2 = fn()
|
||||
assert nam1 is nam2
|
||||
|
||||
|
||||
# ── _cached_thumb_path ────────────────────────────────────────────────────
|
||||
|
||||
class TestCachedThumbPath:
|
||||
"""Tests for the _cached_thumb_path helper."""
|
||||
|
||||
def _import(self):
|
||||
from gui import _cached_thumb_path, THUMB_CACHE_DIR
|
||||
return _cached_thumb_path, THUMB_CACHE_DIR
|
||||
|
||||
def test_uses_cache_dir(self):
|
||||
fn, cache_dir = self._import()
|
||||
path = fn("video123")
|
||||
assert str(path) == str(cache_dir / "video123.jpg")
|
||||
|
||||
def test_ends_with_jpg(self):
|
||||
fn, _ = self._import()
|
||||
path = fn("abc_def")
|
||||
assert path.suffix == ".jpg"
|
||||
assert "abc_def" in path.name
|
||||
|
||||
Reference in New Issue
Block a user