feat: add SourceAdapter contract and fake adapters
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
from lyra_worker.adapters.fakes import FakeQobuz, FakeSoulseek, FakeYouTube, FailingAdapter
|
||||
from lyra_worker.types import MBTarget
|
||||
|
||||
TARGET = MBTarget(artist="Radiohead", album="In Rainbows", track_count=10)
|
||||
ALL_FAKES = [FakeQobuz(), FakeSoulseek(), FakeYouTube(), FailingAdapter()]
|
||||
|
||||
|
||||
def _noop(_pct: float) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def test_adapters_expose_name_and_tier():
|
||||
assert FakeQobuz().name == "qobuz" and FakeQobuz().tier == 0
|
||||
assert FakeSoulseek().name == "soulseek" and FakeSoulseek().tier == 1
|
||||
assert FakeYouTube().name == "youtube" and FakeYouTube().tier == 2
|
||||
|
||||
|
||||
def test_search_returns_wellformed_candidates():
|
||||
for adapter in ALL_FAKES:
|
||||
for c in adapter.search(TARGET):
|
||||
assert c.source == adapter.name
|
||||
assert c.matched_artist and c.matched_album
|
||||
assert c.track_count > 0
|
||||
assert c.source_ref
|
||||
|
||||
|
||||
def test_matches_false_yields_no_candidates():
|
||||
assert FakeQobuz(matches=False).search(TARGET) == []
|
||||
|
||||
|
||||
def test_successful_download_reports_progress_and_ok():
|
||||
seen = []
|
||||
result = FakeQobuz().download(FakeQobuz().search(TARGET)[0], "/tmp/x", seen.append)
|
||||
assert result.ok is True
|
||||
assert result.track_count > 0
|
||||
assert seen and seen[-1] == 1.0 # progress reaches 100%
|
||||
|
||||
|
||||
def test_failing_adapter_download_fails():
|
||||
fa = FailingAdapter()
|
||||
result = fa.download(fa.search(TARGET)[0], "/tmp/x", _noop)
|
||||
assert result.ok is False
|
||||
assert result.error
|
||||
Reference in New Issue
Block a user