From 89e25d2e6a04a5673de74ca837dc682d9157193b Mon Sep 17 00:00:00 2001 From: Jacob Pavlock Date: Sat, 6 Apr 2024 16:13:37 -0700 Subject: [PATCH] fix: metatracks always failing equality --- moe/library/album.py | 2 +- moe/library/track.py | 2 +- tests/library/test_album.py | 14 ++++++++++++++ tests/library/test_track.py | 16 ++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/moe/library/album.py b/moe/library/album.py index 87086c0a..53d340bf 100644 --- a/moe/library/album.py +++ b/moe/library/album.py @@ -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: diff --git a/moe/library/track.py b/moe/library/track.py index 793fb5fa..832e3cf0 100644 --- a/moe/library/track.py +++ b/moe/library/track.py @@ -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: diff --git a/tests/library/test_album.py b/tests/library/test_album.py index 70edbd3a..c31e1011 100644 --- a/tests/library/test_album.py +++ b/tests/library/test_album.py @@ -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() diff --git a/tests/library/test_track.py b/tests/library/test_track.py index 02dec40e..0ee7d37d 100644 --- a/tests/library/test_track.py +++ b/tests/library/test_track.py @@ -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()