Use RecordingFactory in tests

This commit is contained in:
Šarūnas Nejus 2026-01-25 23:12:55 +00:00
parent 4a05444102
commit 64d1ebe0e8
No known key found for this signature in database
2 changed files with 108 additions and 163 deletions

View file

@ -149,3 +149,24 @@ class LabelInfoFactory(factory.DictFactory):
class TextRepresentationFactory(factory.DictFactory):
language = "eng"
script = "Latn"
class RecordingFactory(_IdFactory):
class Params:
id_base = 1000
aliases = factory.List([])
artist_credit = factory.List(
[
factory.SubFactory(
ArtistCreditFactory, artist__name="Recording Artist"
)
]
)
disambiguation = ""
isrcs = factory.List([])
length = 360
title = "Recording"
video = False
genres = factory.List([])
tags = factory.List([])

View file

@ -76,6 +76,10 @@ def text_representation_factory(**kwargs) -> mb.TextRepresentation:
return factories.TextRepresentationFactory.build(**kwargs)
def recording_factory(**kwargs) -> mb.Recording:
return factories.RecordingFactory.build(**kwargs)
class MusicBrainzTestCase(BeetsTestCase):
def setUp(self):
super().setUp()
@ -175,44 +179,6 @@ class MusicBrainzTestCase(BeetsTestCase):
)
return release
@staticmethod
def _make_recording(
title,
tr_id,
duration,
video=False,
disambiguation="",
remixer=False,
multi_artist_credit=False,
) -> mb.Recording:
recording: mb.Recording = {
"title": title,
"id": tr_id,
"length": duration,
"video": video,
"disambiguation": disambiguation,
"isrcs": [],
"aliases": [],
"artist_credit": [
artist_credit_factory(artist__name="Recording Artist")
],
}
if multi_artist_credit:
recording["artist_credit"][0]["joinphrase"] = " & "
recording["artist_credit"].append(
artist_credit_factory(
artist__name="Other Recording Artist",
artist__index=2,
)
)
if remixer:
recording["artist_relations"] = [
artist_relation_factory(
type="remixer", artist__name="Recording Remixer"
)
]
return recording
class MBAlbumInfoTest(MusicBrainzTestCase):
def test_parse_release_with_year(self):
@ -240,26 +206,23 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
def test_parse_tracks(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
recording_factory(length=100000),
recording_factory(index=2, length=200000, title="Other Recording"),
]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
t = d.tracks
assert len(t) == 2
assert t[0].title == "TITLE ONE"
assert t[0].track_id == "ID ONE"
assert t[0].title == "Recording"
assert t[0].track_id == "00000000-0000-0000-0000-000000001001"
assert t[0].length == 100.0
assert t[1].title == "TITLE TWO"
assert t[1].track_id == "ID TWO"
assert t[1].title == "Other Recording"
assert t[1].track_id == "00000000-0000-0000-0000-000000001002"
assert t[1].length == 200.0
def test_parse_track_indices(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
@ -270,10 +233,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert t[1].index == 2
def test_parse_medium_numbers_single_medium(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
@ -283,10 +243,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert t[1].medium == 1
def test_parse_medium_numbers_two_mediums(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(recordings=[recordings[0]])
second_track_list = [
{
@ -320,13 +277,13 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert d.original_month == 3
def test_no_durations(self):
recordings = [self._make_recording("TITLE", "ID", None)]
recordings = [recording_factory(length=None)]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
assert d.tracks[0].length is None
def test_track_length_overrides_recording_length(self):
recordings = [self._make_recording("TITLE", "ID", 1.0 * 1000.0)]
recordings = [recording_factory()]
release = self._make_release(
recordings=recordings, track_length=2.0 * 1000.0
)
@ -395,10 +352,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert d.barcode == "BARCODE"
def test_parse_media(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
assert d.media == "FORMAT"
@ -410,10 +364,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert d.releasegroupdisambig == "Release Group Disambiguation"
def test_parse_disctitle(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
t = d.tracks
@ -427,7 +378,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
assert d.language is None
def test_parse_recording_artist(self):
recordings = [self._make_recording("a", "b", 1)]
recordings = [recording_factory()]
release = self._make_release(recordings=recordings)
track = self.mb.album_info(release).tracks[0]
assert track.artist == "Recording Artist"
@ -437,7 +388,12 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
def test_parse_recording_artist_multi(self):
recordings = [
self._make_recording("a", "b", 1, multi_artist_credit=True)
recording_factory(
artist_credit__0__joinphrase=" & ",
artist_credit__1=artist_credit_factory(
artist__name="Other Recording Artist", artist__index=2
),
)
]
release = self._make_release(recordings=recordings)
track = self.mb.album_info(release).tracks[0]
@ -470,7 +426,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
]
def test_track_artist_overrides_recording_artist(self):
recordings = [self._make_recording("a", "b", 1)]
recordings = [recording_factory()]
release = self._make_release(recordings=recordings, track_artist=True)
track = self.mb.album_info(release).tracks[0]
assert track.artist == "Track Artist"
@ -480,7 +436,12 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
def test_track_artist_overrides_recording_artist_multi(self):
recordings = [
self._make_recording("a", "b", 1, multi_artist_credit=True)
recording_factory(
artist_credit__0__joinphrase=" & ",
artist_credit__1=artist_credit_factory(
artist__name="Other Recording Artist", artist__index=2
),
)
]
release = self._make_release(
recordings=recordings,
@ -513,7 +474,15 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
]
def test_parse_recording_remixer(self):
recordings = [self._make_recording("a", "b", 1, remixer=True)]
recordings = [
recording_factory(
artist_relations=[
artist_relation_factory(
type="remixer", artist__name="Recording Remixer"
)
]
)
]
release = self._make_release(recordings=recordings)
track = self.mb.album_info(release).tracks[0]
assert track.remixer == "Recording Remixer"
@ -545,10 +514,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
def test_ignored_media(self):
config["match"]["ignored_media"] = ["IGNORED1", "IGNORED2"]
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(
recordings=recordings, medium_format="IGNORED1"
)
@ -557,10 +523,7 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
def test_no_ignored_media(self):
config["match"]["ignored_media"] = ["IGNORED1", "IGNORED2"]
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
recordings = [recording_factory(), recording_factory()]
release = self._make_release(
recordings=recordings, medium_format="NON-IGNORED"
)
@ -569,134 +532,109 @@ class MBAlbumInfoTest(MusicBrainzTestCase):
def test_skip_data_track(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording(
"[data track]", "ID DATA TRACK", 100.0 * 1000.0
),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
recording_factory(),
recording_factory(title="[data track]"),
recording_factory(title="Other Recording"),
]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
assert len(d.tracks) == 2
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[1].title == "TITLE TWO"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "Other Recording"
def test_skip_audio_data_tracks_by_default(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
data_tracks = [
self._make_recording(
"TITLE AUDIO DATA", "ID DATA TRACK", 100.0 * 1000.0
)
recording_factory(),
recording_factory(title="Other Recording"),
]
data_tracks = [recording_factory(title="TITLE AUDIO DATA")]
release = self._make_release(
recordings=recordings, data_tracks=data_tracks
)
d = self.mb.album_info(release)
assert len(d.tracks) == 2
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[1].title == "TITLE TWO"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "Other Recording"
def test_no_skip_audio_data_tracks_if_configured(self):
config["match"]["ignore_data_tracks"] = False
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
data_tracks = [
self._make_recording(
"TITLE AUDIO DATA", "ID DATA TRACK", 100.0 * 1000.0
)
recording_factory(),
recording_factory(title="Other Recording"),
]
data_tracks = [recording_factory(title="TITLE AUDIO DATA")]
release = self._make_release(
recordings=recordings, data_tracks=data_tracks
)
d = self.mb.album_info(release)
assert len(d.tracks) == 3
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[1].title == "TITLE TWO"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "Other Recording"
assert d.tracks[2].title == "TITLE AUDIO DATA"
def test_skip_video_tracks_by_default(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording(
"TITLE VIDEO", "ID VIDEO", 100.0 * 1000.0, video=True
),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
recording_factory(),
recording_factory(title="TITLE VIDEO", video=True),
recording_factory(title="Other Recording"),
]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
assert len(d.tracks) == 2
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[1].title == "TITLE TWO"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "Other Recording"
def test_skip_video_data_tracks_by_default(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
data_tracks = [
self._make_recording(
"TITLE VIDEO", "ID VIDEO", 100.0 * 1000.0, True
)
recording_factory(),
recording_factory(title="Other Recording"),
]
data_tracks = [recording_factory(title="TITLE VIDEO")]
release = self._make_release(
recordings=recordings, data_tracks=data_tracks
)
d = self.mb.album_info(release)
assert len(d.tracks) == 2
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[1].title == "TITLE TWO"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "Other Recording"
def test_no_skip_video_tracks_if_configured(self):
config["match"]["ignore_data_tracks"] = False
config["match"]["ignore_video_tracks"] = False
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording(
"TITLE VIDEO", "ID VIDEO", 100.0 * 1000.0, True
),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
recording_factory(),
recording_factory(title="TITLE VIDEO"),
recording_factory(title="Other Recording"),
]
release = self._make_release(recordings=recordings)
d = self.mb.album_info(release)
assert len(d.tracks) == 3
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "TITLE VIDEO"
assert d.tracks[2].title == "TITLE TWO"
assert d.tracks[2].title == "Other Recording"
def test_no_skip_video_data_tracks_if_configured(self):
config["match"]["ignore_data_tracks"] = False
config["match"]["ignore_video_tracks"] = False
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording("TITLE TWO", "ID TWO", 200.0 * 1000.0),
]
data_tracks = [
self._make_recording(
"TITLE VIDEO", "ID VIDEO", 100.0 * 1000.0, True
)
recording_factory(),
recording_factory(title="Other Recording"),
]
data_tracks = [recording_factory(title="TITLE VIDEO")]
release = self._make_release(
recordings=recordings, data_tracks=data_tracks
)
d = self.mb.album_info(release)
assert len(d.tracks) == 3
assert d.tracks[0].title == "TITLE ONE"
assert d.tracks[1].title == "TITLE TWO"
assert d.tracks[0].title == "Recording"
assert d.tracks[1].title == "Other Recording"
assert d.tracks[2].title == "TITLE VIDEO"
def test_track_disambiguation(self):
recordings = [
self._make_recording("TITLE ONE", "ID ONE", 100.0 * 1000.0),
self._make_recording(
"TITLE TWO",
"ID TWO",
200.0 * 1000.0,
disambiguation="SECOND TRACK",
recording_factory(),
recording_factory(
title="Other Recording", disambiguation="SECOND TRACK"
),
]
release = self._make_release(recordings=recordings)
@ -726,9 +664,7 @@ class ArtistTest(unittest.TestCase):
def test_two_artists(self):
credit = [
artist_credit_factory(artist__name="Artist", joinphrase=" AND "),
artist_credit_factory(
artist__name="Other Artist", artist__id_suffix="1"
),
artist_credit_factory(artist__name="Other Artist", artist__index=2),
]
assert MusicBrainzPlugin._parse_artist_credits(credit) == {
@ -803,9 +739,7 @@ class MBLibraryTest(MusicBrainzTestCase):
"tracks": [
{
"id": "baz",
"recording": self._make_recording(
"translated title", "bar", 42
),
"recording": recording_factory(),
"position": 9,
"number": "A1",
}
@ -838,9 +772,7 @@ class MBLibraryTest(MusicBrainzTestCase):
"tracks": [
{
"id": "baz",
"recording": self._make_recording(
"original title", "bar", 42
),
"recording": recording_factory(),
"position": 9,
"number": "A1",
}
@ -876,9 +808,7 @@ class MBLibraryTest(MusicBrainzTestCase):
"tracks": [
{
"id": "baz",
"recording": self._make_recording(
"translated title", "bar", 42
),
"recording": recording_factory(),
"position": 9,
"number": "A1",
}
@ -913,9 +843,7 @@ class MBLibraryTest(MusicBrainzTestCase):
"tracks": [
{
"id": "baz",
"recording": self._make_recording(
"translated title", "bar", 42
),
"recording": recording_factory(),
"position": 9,
"number": "A1",
}
@ -950,9 +878,7 @@ class MBLibraryTest(MusicBrainzTestCase):
"tracks": [
{
"id": "baz",
"recording": self._make_recording(
"translated title", "bar", 42
),
"recording": recording_factory(),
"position": 9,
"number": "A1",
}
@ -988,9 +914,7 @@ class TestMusicBrainzPlugin(PluginMixin):
plugin = "musicbrainz"
mbid = "d2a6f856-b553-40a0-ac54-a321e8e2da99"
RECORDING: ClassVar[mb.Recording] = MusicBrainzTestCase._make_recording(
"foo", "00000000-0000-0000-0000-000000000000", 42
)
RECORDING: ClassVar[mb.Recording] = recording_factory()
@pytest.fixture
def plugin_config(self):