The app now holds one RadioProvider and asks it for stations, song history and stream URLs instead of importing SomaFM's HTTP client directly. - models.py: provider-neutral Song/Station plus the shared parsers every catalogue needs (Station.provider/.uid keep ids unique once there is more than one). - providers/base.py: the RadioProvider interface and the toolkit it needs in practice - httpx client factory, .pls/.m3u resolution with an 8h disk cache, and a default stream_candidates() strategy. - providers/somafm/: everything SomaFM-specific (channels.json, songs/<id>.json, PLS layout, guessed icecast mirrors) behind SomaFMProvider. - providers/__init__.py: registry, get_provider() and --provider, remembered in the config file. Widgets render branding, splash copy and the help credits from the active provider, so a second catalogue needs no UI changes; with SomaFM selected the screen is byte-identical to before.
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from beefy_player.__main__ import _build_parser, _list_stations
|
|
|
|
|
|
def test_parser_defaults_and_flags() -> None:
|
|
parser = _build_parser()
|
|
args = parser.parse_args([])
|
|
assert args.autoplay is None
|
|
assert args.offline is False
|
|
assert args.no_audio is False
|
|
|
|
assert args.spectrum_source == "auto"
|
|
|
|
args = parser.parse_args(
|
|
["--station", "defcon", "--play", "--no-mpris", "--spectrum-source", "monitor"]
|
|
)
|
|
assert args.station == "defcon"
|
|
assert args.autoplay is True
|
|
assert args.no_mpris is True
|
|
assert args.spectrum_source == "monitor"
|
|
assert args.provider is None # the config file decides
|
|
|
|
|
|
def test_provider_flag_is_validated() -> None:
|
|
parser = _build_parser()
|
|
assert parser.parse_args(["--provider", "somafm"]).provider == "somafm"
|
|
with pytest.raises(SystemExit):
|
|
parser.parse_args(["--provider", "no-such-catalogue"])
|
|
|
|
|
|
def test_list_stations_offline(capsys) -> None:
|
|
assert _list_stations(offline=True) == 0
|
|
output = capsys.readouterr().out
|
|
assert "groovesalad" in output
|
|
assert "Groove Salad" in output
|