Skip to content

Improve test coverage and fix a couple of potential bugs - #61

Merged
jodal merged 5 commits into
mopidy:mainfrom
jodal:test-coverage
Sep 13, 2026
Merged

jodal merged 5 commits into
mopidy:mainfrom
jodal:test-coverage

Conversation

@jodal

@jodal jodal commented Sep 13, 2026

Copy link
Copy Markdown
Member

No description provided.

parsers.py is a copy of the parsers in Mopidy's stream extension, so
copy their tests too. The only changes are the import and the type
annotations that our ruff rules ask for.
pytest collects classes whose name starts with Test, so the three ASX
cases never ran. The base class only varied one value, which is what
parametrize is for, and a plain function cannot go missing this way.
Use responses to answer the HTTP requests with payloads shaped like the
ones the TuneIn API returns.

The cache decorators are class attributes, so they hold results between
tests. A fixture clears them before each test.
_get_playlist read the whole body unless the content type was exactly
audio/mpeg. A live stream never ends, and the requests timeout only
covers the wait between reads, so a station that serves, say, audio/aac
made the call block until the connection dropped, with the backend
thread and a cache slot held.

Read the body in chunks now, and stop at the first of a size limit and a
deadline. A body that does not stop is a stream, not a playlist, so
report that there is no playlist. The caller then uses the URL as it is,
which is what it already does for a stream.
find_playlist_parser() fell back to the content type when the URL had no
known extension, but compared the whole header value, so a playlist
served as "audio/x-scpls; charset=UTF-8" found no parser. Strip the
parameters before the lookup, and add audio/x-mpegurl, which is what
TuneIn servers send for M3U.

Of 22 playlists collected from the TuneIn API, the fallback recognised 3
before this change and recognises all 22 after it.

Use the same normalization for the audio/mpeg check in _get_playlist,
where a content type with a charset made it read the body of a stream
until the deadline passed.
@jodal
jodal merged commit c7804e2 into mopidy:main Sep 13, 2026
8 checks passed
@jodal
jodal deleted the test-coverage branch September 13, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant