mirror of
https://github.com/darkzoul5/YoutubePlaylistSync.git
synced 2026-11-04 15:38:14 +02:00
Add more tests for PlaylistDownloader functionality
This commit is contained in:
1 parent
1d99fd2b10
commit
4a56c03b62
5 files changed
+199
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
import subprocess
|
||||
from types import SimpleNamespace
|
||||
|
||||
import ytplaylist.cli as cli_mod
|
||||
|
||||
|
||||
class DummyCompleted(SimpleNamespace):
|
||||
pass
|
||||
|
||||
|
||||
def test_update_yt_dlp_success(monkeypatch, caplog):
|
||||
called = {"count": 0}
|
||||
|
||||
def fake_run(args, check=True, **kw):
|
||||
called["count"] += 1
|
||||
return DummyCompleted(returncode=0)
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
|
||||
caplog.set_level(logging.INFO)
|
||||
cli_mod.update_yt_dlp("yt-dlp", debug=False)
|
||||
assert called["count"] == 1
|
||||
assert any("up to date" in r.message.lower() for r in caplog.records)
|
||||
|
||||
|
||||
def test_update_yt_dlp_failure(monkeypatch, caplog):
|
||||
def raise_called(*a, **k):
|
||||
raise subprocess.CalledProcessError(1, cmd=a[0])
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", raise_called)
|
||||
caplog.set_level(logging.WARNING)
|
||||
cli_mod.update_yt_dlp("yt-dlp", debug=False)
|
||||
assert any("could not update yt-dlp" in r.message.lower() or "could not update" in r.message.lower() for r in caplog.records)
|
||||
|
||||
|
||||
def test_configure_logging_sets_levels():
|
||||
# ensure calling configure_logging flips global root logger level
|
||||
cli_mod.configure_logging(True)
|
||||
assert logging.getLogger().level == logging.DEBUG
|
||||
cli_mod.configure_logging(False)
|
||||
assert logging.getLogger().level == logging.INFO
|
||||
Reference in new issue
Block a user