test: add firmware capture fixtures and stdlib-level unit tests for parsers, intents, running apps
This commit is contained in:
1 parent
f829ef7a40
commit
a2f1948a88
7 files changed
+198
No files matched your search
@@ -0,0 +1,40 @@
|
||||
"""Tests for the running-apps list builder (recent tasks + media sessions)."""
|
||||
|
||||
from ha_adb_common.running_apps import running_apps_from_tasks
|
||||
|
||||
|
||||
def _session(package: str, playing: bool = False, title: str | None = None):
|
||||
from ha_adb_common.media_session import MediaSessionInfo
|
||||
|
||||
s = MediaSessionInfo(package=package)
|
||||
s.playing = playing
|
||||
s.paused = not playing
|
||||
s.title = title
|
||||
return s
|
||||
|
||||
|
||||
def test_returns_none_for_fewer_than_two_tasks():
|
||||
assert running_apps_from_tasks([]) is None
|
||||
assert running_apps_from_tasks([{"package": "app.a"}]) is None
|
||||
|
||||
|
||||
def test_marks_foreground_and_defaults_to_running():
|
||||
tasks = [{"package": "app.a"}, {"package": "app.b"}]
|
||||
apps = running_apps_from_tasks(tasks, [], foreground_package="app.b")
|
||||
assert apps is not None
|
||||
assert len(apps) == 2
|
||||
by_pkg = {a["package"]: a for a in apps}
|
||||
assert "foreground" not in by_pkg["app.a"]
|
||||
assert by_pkg["app.b"]["foreground"] is True
|
||||
assert by_pkg["app.a"]["state"] == "running"
|
||||
|
||||
|
||||
def test_enriches_with_media_session_state():
|
||||
tasks = [{"package": "app.a"}, {"package": "app.b"}]
|
||||
sessions = [_session("app.a", playing=True, title="Song")]
|
||||
apps = running_apps_from_tasks(tasks, sessions)
|
||||
assert apps is not None
|
||||
by_pkg = {a["package"]: a for a in apps}
|
||||
assert by_pkg["app.a"]["state"] == "playing"
|
||||
assert by_pkg["app.a"]["title"] == "Song"
|
||||
assert by_pkg["app.b"]["state"] == "running"
|
||||
Reference in new issue
Block a user