🐛 | Improve test coverage for SonarQube quality gate
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
- Restructure conftest to try real Qt first, fall back to stubs only if that fails — ensures try/except guards in player.py and gui.py are exercised in CI, improving new_coverage - Add tests for _migrate_legacy error paths (JSONDecodeError, OSError, db migration) — config.py now 100% covered - Add tests for _disconnect, _send_presence exception handlers — discord_rpc.py now 97% covered - Add tests for _cleanup_path and _tmp_dir helpers — player.py coverage bumped to 33%
This commit is contained in:
@@ -275,3 +275,69 @@ class TestBuildResolvedDict:
|
||||
assert resolved["duration"] == 99
|
||||
assert resolved["title"] == "Fallback"
|
||||
assert resolved["thumbnail"] == ""
|
||||
|
||||
|
||||
# ── _cleanup_path ───────────────────────────────────────────────────────────────
|
||||
|
||||
class TestCleanupPath:
|
||||
"""Tests for DownloadWorker._cleanup_path."""
|
||||
|
||||
def _import(self):
|
||||
from player import DownloadWorker
|
||||
return DownloadWorker._cleanup_path
|
||||
|
||||
def test_removes_existing_file(self, tmp_path):
|
||||
"""_cleanup_path removes a file that exists."""
|
||||
fn = self._import()
|
||||
path = tmp_path / "to_delete.txt"
|
||||
path.write_text("hello")
|
||||
assert path.exists()
|
||||
fn(str(path))
|
||||
assert not path.exists()
|
||||
|
||||
def test_noop_for_missing_file(self):
|
||||
"""_cleanup_path does nothing for non-existent paths."""
|
||||
fn = self._import()
|
||||
fn("/nonexistent/path/file.txt") # should not raise
|
||||
assert True
|
||||
|
||||
def test_noop_for_none(self):
|
||||
"""_cleanup_path does nothing when path is None."""
|
||||
fn = self._import()
|
||||
fn(None)
|
||||
assert True
|
||||
|
||||
def test_oserror_handled_gracefully(self, tmp_path, monkeypatch):
|
||||
"""_cleanup_path handles OSError gracefully."""
|
||||
fn = self._import()
|
||||
path = tmp_path / "locked.txt"
|
||||
path.write_text("data")
|
||||
|
||||
def _fail_unlink(p):
|
||||
raise OSError("Permission denied")
|
||||
|
||||
monkeypatch.setattr(os, "unlink", _fail_unlink)
|
||||
fn(str(path)) # should not raise
|
||||
assert True
|
||||
|
||||
|
||||
# ── _tmp_dir ───────────────────────────────────────────────────────────────────
|
||||
|
||||
class TestTmpDir:
|
||||
"""Tests for the _tmp_dir helper."""
|
||||
|
||||
def _import(self):
|
||||
from player import _tmp_dir
|
||||
return _tmp_dir
|
||||
|
||||
def test_returns_string(self):
|
||||
"""_tmp_dir returns a string path."""
|
||||
fn = self._import()
|
||||
path = fn()
|
||||
assert isinstance(path, str)
|
||||
assert "tunetti" in path
|
||||
|
||||
def test_idempotent(self):
|
||||
"""Calling _tmp_dir multiple times returns the same path."""
|
||||
fn = self._import()
|
||||
assert fn() == fn()
|
||||
|
||||
Reference in New Issue
Block a user