Keep the MusicBrainz tests typing clean and formatted

The release-group branch landed with test-only type errors and
unformatted modules, so mise run check failed before the cog could ship.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
Ziad Arafat committed 2026-11-25 17:00:02 -07:00
1 parent 7b472625ad
commit 15fe770536
5 files changed
+29 -19

No files matched your search

+6 -4
View File
@@ -1,6 +1,6 @@
"""MusicBrainz containment and resolution inside the album importer."""
from typing import Any
from typing import Any, cast
def album_row(
@@ -80,7 +80,7 @@ class FakeArr:
async def __call__(self, path: str, **kwargs: Any) -> Any: # noqa: ANN401
"""Serve the handful of routes the importer uses."""
params = kwargs.get("params") or {}
body = kwargs.get("body")
body = cast("dict[str, Any] | None", kwargs.get("body"))
method = kwargs.get("method") or ("POST" if body else "GET")
if path == "album/lookup":
return self.lookup
@@ -89,6 +89,7 @@ class FakeArr:
row = self.catalog.get(mbid) if mbid else None
return [row] if row else []
if path == "album" and method == "POST":
assert body is not None
self.added.append(body)
row = dict(body)
row["id"] = row.get("id") or (900 + len(self.added))
@@ -115,6 +116,7 @@ class FakeArr:
}
]
if path == "command":
assert body is not None
self.searches.append(body["albumIds"])
return {"id": 1}
return {}
@@ -132,8 +134,8 @@ async def engine_with(arr: FakeArr, brainz: Any | None) -> Any: # noqa: ANN401
return MusicImporter(
arr,
None,
None,
cast("Any", None),
cast("Any", None),
save,
authorize,
musicbrainz=brainz,
+15 -5
View File
@@ -47,10 +47,14 @@ def test_an_ep_wins_over_a_single_but_not_over_an_album() -> None:
album(1, "Levels", "Single"),
album(2, "Levels", "EP"),
]
assert choose("Levels", candidates)["id"] == 2
selected = choose("Levels", candidates)
assert selected is not None
assert selected["id"] == 2
candidates.append(album(3, "Levels", "Album"))
assert choose("Levels", candidates)["id"] == 3
selected = choose("Levels", candidates)
assert selected is not None
assert selected["id"] == 3
def test_a_plain_album_wins_over_a_compilation_or_live_edition() -> None:
@@ -60,7 +64,9 @@ def test_a_plain_album_wins_over_a_compilation_or_live_edition() -> None:
album(2, "True", "Album", ["Live"]),
album(3, "True", "Album"),
]
assert choose("True", candidates)["id"] == 3
selected = choose("True", candidates)
assert selected is not None
assert selected["id"] == 3
def test_a_single_wins_over_a_remix_edition() -> None:
@@ -69,7 +75,9 @@ def test_a_single_wins_over_a_remix_edition() -> None:
album(1, "Wake Me Up", "Single", ["Remix"]),
album(2, "Wake Me Up", "Single"),
]
assert choose("Wake Me Up", candidates)["id"] == 2
selected = choose("Wake Me Up", candidates)
assert selected is not None
assert selected["id"] == 2
def test_equally_ranked_albums_stay_ambiguous() -> None:
@@ -110,4 +118,6 @@ def test_release_preference_never_overrides_the_artist_check() -> None:
"artist": {"artistName": "A Tribute Band"},
},
]
assert choose("True", candidates)["id"] == 1
selected = choose("True", candidates)
assert selected is not None
assert selected["id"] == 1
+6 -4
View File
@@ -1,6 +1,6 @@
"""MusicBrainz resolves a track to the release groups that contain it."""
from typing import Any
from typing import Any, cast
GROUP_SINGLE = {
"id": "rg-single",
@@ -159,7 +159,7 @@ async def test_rate_limit_is_retried_then_succeeds() -> None:
async def sleep(seconds: float) -> None:
delays.append(seconds)
mb = MusicBrainz(client, sleep=sleep, clock=lambda: 0.0)
mb = MusicBrainz(cast("Any", client), sleep=sleep, clock=lambda: 0.0)
groups = await mb.release_groups("Avicii", "Wake Me Up")
assert [g["foreignAlbumId"] for g in groups] == ["rg-single", "rg-comp"]
assert len(client.calls) == 2
@@ -175,7 +175,7 @@ async def test_repeated_failure_degrades_to_no_groups() -> None:
async def sleep(_seconds: float) -> None:
return None
mb = MusicBrainz(client, sleep=sleep, clock=lambda: 0.0)
mb = MusicBrainz(cast("Any", client), sleep=sleep, clock=lambda: 0.0)
assert await mb.release_groups("Avicii", "Wake Me Up") == []
@@ -191,7 +191,9 @@ async def test_calls_are_spaced_by_one_second() -> None:
delays.append(seconds)
now["t"] += seconds
mb = MusicBrainz(client, sleep=sleep, clock=lambda: now["t"])
mb = MusicBrainz(
cast("Any", client), sleep=sleep, clock=lambda: now["t"]
)
await mb.release_groups("Avicii", "Wake Me Up")
await mb.release_groups("Avicii", "Hey Brother")
assert delays == [1.0]
+1 -3
View File
@@ -128,9 +128,7 @@ def choose_album(
if holding:
# A release group MusicBrainz says holds the track beats
# one that only outranks it on type.
held = [
a for a in matches if a["foreignAlbumId"] in holding
]
held = [a for a in matches if a["foreignAlbumId"] in holding]
if held:
matches = held
unique = {a["foreignAlbumId"]: a for a in matches}
+1 -3
View File
@@ -59,9 +59,7 @@ def parse_recordings(payload: dict[str, Any]) -> list[dict[str, Any]]:
if credited and isinstance(credited[0], dict):
name = credited[0].get("name") or ""
primary = meta.get("primary-type") or ""
secondary = list(
meta.get("secondary-types") or []
)
secondary = list(meta.get("secondary-types") or [])
row = groups.setdefault(
group_id,
{