/
/
/
1"""
2Test that guards the media-status test setup itself.
3
4The media-status tests drive the handler with a MagicMock as ``self``, so a helper
5that is not bound to its real implementation answers as a mock and its part of the
6handler is skipped without any test failing.
7"""
8
9from __future__ import annotations
10
11import ast
12import inspect
13import textwrap
14
15from music_assistant.providers.chromecast.player import ChromecastPlayer
16from tests.providers.chromecast.helpers import MEDIA_STATUS_HELPERS
17
18# helpers the tests deliberately keep mocked, to drive the handler down a chosen path
19MOCKED_SEAMS = {"_flow_stream_underrun"}
20
21
22def _private_methods_called_by_handler() -> set[str]:
23 """Return the names of the private ChromecastPlayer methods _handle_media_status calls."""
24 source = textwrap.dedent(inspect.getsource(ChromecastPlayer._handle_media_status))
25 return {
26 node.func.attr
27 for node in ast.walk(ast.parse(source))
28 if isinstance(node, ast.Call)
29 and isinstance(node.func, ast.Attribute)
30 and isinstance(node.func.value, ast.Name)
31 and node.func.value.id == "self"
32 and node.func.attr.startswith("_")
33 and callable(getattr(ChromecastPlayer, node.func.attr, None))
34 }
35
36
37def test_every_media_status_helper_is_bound() -> None:
38 """Every helper the handler delegates to is bound, so no part of it is skipped."""
39 assert _private_methods_called_by_handler() - MOCKED_SEAMS == set(MEDIA_STATUS_HELPERS)
40