Skip to content

Commit

Permalink
fix: albumartist overwriting track artist
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Nov 4, 2022
1 parent 76f9b95 commit 6bbf445
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
11 changes: 4 additions & 7 deletions moe/library/track.py
Expand Up @@ -179,15 +179,12 @@ def __init__(
album.tracks.append(self)

self.track_num = track_num
self.artist = artist
self.artist = artist or self.album_obj.artist
self.artists = artists
self.disc = disc
self.genres = genres
self.title = title

# set default values
self.artist = self.album_obj.artist

for key, value in kwargs.items():
setattr(self, key, value)

Expand Down Expand Up @@ -379,12 +376,12 @@ def __init__(
self.title = title
self.track_num = track_num

# set default values
self.artist = self.albumartist

for key, value in kwargs.items():
setattr(self, key, value)

if self.artist is None:
self.artist = self.albumartist

if not self.disc:
self.disc = self._guess_disc()

Expand Down
32 changes: 32 additions & 0 deletions tests/library/test_track.py
Expand Up @@ -91,6 +91,38 @@ def test_guess_disc_single_disc(self):

assert new_track.disc == 1

def test_default_artist(self):
"""Use the album artist if an artist is not given."""
album = album_factory(artist="use me")
track = track_factory(album=album, artist=None)

assert track.artist == "use me"

def test_use_given_artist(self):
"""Don't use the album artist if an artist is given."""
album = album_factory(artist="dont use me")
track = track_factory(album=album, artist="use me")

assert track.artist == "use me"


class TestMetaInit:
"""Test MetaTrack initialization."""

def test_default_artist(self):
"""Use the album artist if an artist is not given."""
album = MetaAlbum(artist="use me")
track = MetaTrack(album, 1, artist=None)

assert track.artist == "use me"

def test_use_given_artist(self):
"""Don't use the album artist if an artist is given."""
album = MetaAlbum(artist="dont use me")
track = MetaTrack(album, 1, artist="use me")

assert track.artist == "use me"


class TestAlbumSet:
"""Changing an album attribute will change the value for the current Album.
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/musicbrainz/resources/full_release.py
Expand Up @@ -1713,10 +1713,10 @@ def full_album() -> MetaAlbum:
MetaTrack(
album=album,
track_num=2,
artist="Kanye West",
artist="Kanye West feat. Kid Cudi & Raekwon",
title="Gorgeous",
disc=1,
mb_track_id="b3c6aa0a-6960-4db6-bf27-ed50de88309c",
mb_track_id="d4cbaf03-b40a-352d-9461-eadbc5986fc0",
)

return album
2 changes: 1 addition & 1 deletion tests/plugins/musicbrainz/resources/min_release.py
Expand Up @@ -237,7 +237,7 @@ def min_album() -> MetaAlbum:
MetaTrack(
album=album,
track_num=1,
artist="Tyler, the Creator",
artist="Tyler, the Creator & A$AP Rocky",
title="POTATO SALAD",
disc=1,
mb_track_id="0cb6936a-19df-4067-b7ba-28d6c866d23f",
Expand Down
6 changes: 6 additions & 0 deletions tests/plugins/musicbrainz/test_mb_core.py
Expand Up @@ -323,6 +323,9 @@ def test_album_search(self, mock_mb_by_id, mb_config):
mb_album_id, includes=moe_mb.mb_core.RELEASE_INCLUDES
)
assert mb_album == mb_rsrc.full_album()
for track in mb_album.tracks:
assert track in mb_rsrc.full_album().tracks
assert len(mb_album.tracks) == len(mb_rsrc.full_album().tracks)

def test_partial_date_year_mon(self, mock_mb_by_id, mb_config):
"""If given date is missing the day, default to 1."""
Expand Down Expand Up @@ -368,6 +371,9 @@ def test_minimal_release(self, mock_mb_by_id, mb_config):
mb_album_id, includes=moe_mb.mb_core.RELEASE_INCLUDES
)
assert mb_album == mb_rsrc.min_album()
for track in mb_album.tracks:
assert track in mb_rsrc.min_album().tracks
assert len(mb_album.tracks) == len(mb_rsrc.min_album().tracks)


class TestGetCandidateByID:
Expand Down

0 comments on commit 6bbf445

Please sign in to comment.