54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
"""Parser tests driven by real Shield firmware captures (Android 11, RQ1A.210105.003).
|
|
|
|
Fixtures live in tests/fixtures — see docs/RESEARCH_SHIELD.md for how each
|
|
capture was produced and which expectations it pins.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from ha_adb_common.media_session import parse_all_media_sessions, parse_media_session
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
def _fixture(name: str) -> str:
|
|
return (FIXTURES / name).read_text(encoding="utf-8")
|
|
|
|
|
|
class TestTiviMateHasNoSession:
|
|
"""TiviMate (ar.tvplayer.tv) registers no MediaSession on this firmware."""
|
|
|
|
def test_no_sessions_parsed(self):
|
|
assert parse_all_media_sessions(_fixture("media_session_tivimate.txt")) == []
|
|
|
|
def test_session_query_returns_none(self):
|
|
dump = _fixture("media_session_tivimate.txt")
|
|
assert parse_media_session(dump, "ar.tvplayer.tv") is None
|
|
|
|
def test_inactive_stale_session_is_not_surfaced(self):
|
|
"""Netflix registers an inactive, state-less session; the parser must
|
|
ignore it — an active=false block never appears in the results."""
|
|
dump = _fixture("media_session_tivimate.txt")
|
|
assert parse_media_session(dump, "com.netflix.ninja") is None
|
|
|
|
|
|
class TestWholphinSession:
|
|
"""Wholphin (com.github.damontecres.wholphin) publishes a proper session."""
|
|
|
|
def test_playing_session_parsed(self):
|
|
sessions = parse_all_media_sessions(_fixture("media_session_wholphin.txt"))
|
|
assert len(sessions) == 1
|
|
session = sessions[0]
|
|
assert session.package == "com.github.damontecres.wholphin"
|
|
assert session.playing is True
|
|
assert session.paused is False
|
|
assert session.title == "Twirlywoos"
|
|
assert session.artist is None
|
|
|
|
def test_foreground_package_is_preferred(self):
|
|
dump = _fixture("media_session_wholphin.txt")
|
|
best = parse_media_session(dump, "com.github.damontecres.wholphin")
|
|
assert best is not None
|
|
assert best.package == "com.github.damontecres.wholphin"
|
|
assert best.playing is True
|