Skip to content

Commit 89e25d2

Browse files
committed
fix: metatracks always failing equality
1 parent 1c4e642 commit 89e25d2

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

moe/library/album.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def merge(self, other: "MetaAlbum", overwrite: bool = False) -> None:
209209

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

215215
for field in self.fields:

moe/library/track.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def merge(self, other: "MetaTrack", overwrite: bool = False):
219219

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

225225
for field in self.fields:

tests/library/test_album.py

+14
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@ def test_default(self):
412412
class TestEquality:
413413
"""Test equality of albums."""
414414

415+
def test_meta_equals(self):
416+
"""Meta Albums with the same fields are equal."""
417+
album1 = MetaAlbum(artist="equals")
418+
album2 = MetaAlbum(artist="equals")
419+
420+
assert album1 == album2
421+
422+
def test_meta_not_equals(self):
423+
"""Meta Albums with different fields are not equal."""
424+
album1 = MetaAlbum(artist="equals")
425+
album2 = MetaAlbum(artist="not equal")
426+
427+
assert album1 != album2
428+
415429
def test_equals(self):
416430
"""Albums with the same fields are equal."""
417431
album1 = album_factory()

tests/library/test_track.py

+16
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ def test_missing_disc_total(self, tmp_config):
224224
class TestEquality:
225225
"""Test equality of tracks."""
226226

227+
def test_meta_equals(self):
228+
"""Meta Tracks with the same metadata are equal."""
229+
album = MetaAlbum(artist="meta_artist")
230+
track1 = MetaTrack(album, 1)
231+
track2 = MetaTrack(album, 1)
232+
233+
assert track1 == track2
234+
235+
def test_meta_not_equals(self):
236+
"""Meta Tracks with different metadata are not equal."""
237+
album = MetaAlbum(artist="meta_artist")
238+
track1 = MetaTrack(album, 1)
239+
track2 = MetaTrack(album, 2)
240+
241+
assert track1 != track2
242+
227243
def test_equals(self):
228244
"""Tracks with the same metadata are equal."""
229245
track1 = track_factory()

0 commit comments

Comments
 (0)