/
/
/
1"""Shared helpers for the Chromecast player tests."""
2
3from __future__ import annotations
4
5from functools import partial
6from typing import cast
7from unittest.mock import MagicMock
8
9from music_assistant.providers.chromecast.player import ChromecastPlayer
10
11# Private helpers that _handle_media_status delegates its work to. The handler is
12# driven with a MagicMock as 'self', which would answer these calls itself instead of
13# updating the player state, so they are bound to the real implementation.
14# Extend this when the handler gains a helper, or its part is silently skipped.
15MEDIA_STATUS_HELPERS = (
16 "_reset_to_idle",
17 "_report_media_error",
18 "_update_playback_state",
19 "_update_elapsed_time",
20 "_update_active_source",
21 "_update_current_media",
22 "_update_multichannel_group_members",
23)
24
25
26def bind_media_status_helpers(fake: MagicMock) -> MagicMock:
27 """
28 Let a fake Cast player run the real media-status helpers, and return it.
29
30 :param fake: MagicMock standing in for a ChromecastPlayer.
31 """
32 for name in MEDIA_STATUS_HELPERS:
33 setattr(
34 fake, name, partial(getattr(ChromecastPlayer, name), cast("ChromecastPlayer", fake))
35 )
36 return fake
37