/
/
/
1"""Shared fixtures and stubs for Yandex Music provider tests."""
2
3from __future__ import annotations
4
5import logging
6
7import pytest
8from music_assistant_models.enums import MediaType
9from music_assistant_models.media_items import ItemMapping
10
11
12class ProviderStub:
13 """Minimal provider-like object for parser tests (no Mock).
14
15 Provides the minimal interface needed by parse_* functions.
16 """
17
18 domain = "yandex_music"
19 instance_id = "yandex_music_instance"
20
21 def __init__(self) -> None:
22 """Initialize stub with minimal client."""
23 self.client = type("ClientStub", (), {"user_id": 12345})()
24
25 def get_item_mapping(self, media_type: MediaType | str, key: str, name: str) -> ItemMapping:
26 """Return ItemMapping for the given media type, key and name."""
27 return ItemMapping(
28 media_type=MediaType(media_type) if isinstance(media_type, str) else media_type,
29 item_id=key,
30 provider=self.instance_id,
31 name=name,
32 )
33
34
35class StreamingProviderStub:
36 """Minimal provider stub for streaming tests (no Mock).
37
38 Provides the minimal interface needed by YandexMusicStreamingManager.
39 """
40
41 domain = "yandex_music"
42 instance_id = "yandex_music_instance"
43 logger = logging.getLogger("yandex_music_test_streaming")
44
45 def __init__(self) -> None:
46 """Initialize stub with minimal client."""
47 self.client = type("ClientStub", (), {"user_id": 12345})()
48 self.mass = type("MassStub", (), {})()
49 self._warning_count = 0
50
51 def _count_warning(self, *args: object, **kwargs: object) -> None:
52 """Track warning calls for test assertions."""
53 self._warning_count += 1
54
55
56class TrackingLogger:
57 """Logger that tracks calls for test assertions without using Mock."""
58
59 def __init__(self) -> None:
60 """Initialize with empty call counters."""
61 self._debug_count = 0
62 self._info_count = 0
63 self._warning_count = 0
64 self._error_count = 0
65
66 def debug(self, *args: object, **kwargs: object) -> None:
67 """Track debug calls."""
68 self._debug_count += 1
69
70 def info(self, *args: object, **kwargs: object) -> None:
71 """Track info calls."""
72 self._info_count += 1
73
74 def warning(self, *args: object, **kwargs: object) -> None:
75 """Track warning calls."""
76 self._warning_count += 1
77
78 def error(self, *args: object, **kwargs: object) -> None:
79 """Track error calls."""
80 self._error_count += 1
81
82
83class StreamingProviderStubWithTracking:
84 """Provider stub with tracking logger for assertions.
85
86 Use this when you need to verify logging behavior.
87 """
88
89 domain = "yandex_music"
90 instance_id = "yandex_music_instance"
91
92 def __init__(self) -> None:
93 """Initialize stub with tracking logger."""
94 self.client = type("ClientStub", (), {"user_id": 12345})()
95 self.mass = type("MassStub", (), {})()
96 self.logger = TrackingLogger()
97
98
99# Minimal client-like object for yandex_music de_json (library requires client, not None)
100DE_JSON_CLIENT = type("ClientStub", (), {"report_unknown_fields": False})()
101
102
103@pytest.fixture
104def provider_stub() -> ProviderStub:
105 """Return a real provider stub (no Mock)."""
106 return ProviderStub()
107
108
109@pytest.fixture
110def streaming_provider_stub() -> StreamingProviderStub:
111 """Return a streaming provider stub (no Mock)."""
112 return StreamingProviderStub()
113
114
115@pytest.fixture
116def streaming_provider_stub_with_tracking() -> StreamingProviderStubWithTracking:
117 """Return a streaming provider stub with tracking logger."""
118 return StreamingProviderStubWithTracking()
119