Skip to content

Commit

Permalink
fix: metatracks always failing equality
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Apr 6, 2024
1 parent 1c4e642 commit 89e25d2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion moe/library/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def merge(self, other: "MetaAlbum", overwrite: bool = False) -> None:

def __eq__(self, other) -> bool:
"""Compares MetaAlbums by their fields."""
if type(self) != type(other): # noqa: E721
if not isinstance(other, MetaAlbum):
return False

for field in self.fields:
Expand Down
2 changes: 1 addition & 1 deletion moe/library/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def merge(self, other: "MetaTrack", overwrite: bool = False):

def __eq__(self, other) -> bool:
"""Compares Tracks by their fields."""
if not isinstance(other, Track):
if not isinstance(other, MetaTrack):
return False

for field in self.fields:
Expand Down
14 changes: 14 additions & 0 deletions tests/library/test_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,20 @@ def test_default(self):
class TestEquality:
"""Test equality of albums."""

def test_meta_equals(self):
"""Meta Albums with the same fields are equal."""
album1 = MetaAlbum(artist="equals")
album2 = MetaAlbum(artist="equals")

assert album1 == album2

def test_meta_not_equals(self):
"""Meta Albums with different fields are not equal."""
album1 = MetaAlbum(artist="equals")
album2 = MetaAlbum(artist="not equal")

assert album1 != album2

def test_equals(self):
"""Albums with the same fields are equal."""
album1 = album_factory()
Expand Down
16 changes: 16 additions & 0 deletions tests/library/test_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ def test_missing_disc_total(self, tmp_config):
class TestEquality:
"""Test equality of tracks."""

def test_meta_equals(self):
"""Meta Tracks with the same metadata are equal."""
album = MetaAlbum(artist="meta_artist")
track1 = MetaTrack(album, 1)
track2 = MetaTrack(album, 1)

assert track1 == track2

def test_meta_not_equals(self):
"""Meta Tracks with different metadata are not equal."""
album = MetaAlbum(artist="meta_artist")
track1 = MetaTrack(album, 1)
track2 = MetaTrack(album, 2)

assert track1 != track2

def test_equals(self):
"""Tracks with the same metadata are equal."""
track1 = track_factory()
Expand Down

0 comments on commit 89e25d2

Please sign in to comment.