From 3fe197bbccc61b72fdd39d38a587000f6d4303c7 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sun, 2 Mar 2014 14:46:13 +0200 Subject: [PATCH] Hashable artist and album, for #82 --- .gitignore | 1 + pylast.py | 2 ++ test_pylast.py | 30 ++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a66d7f0..d547e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports +htmlcov/ .tox/ .coverage .cache diff --git a/pylast.py b/pylast.py index cfa7325..bdf35e0 100644 --- a/pylast.py +++ b/pylast.py @@ -1189,6 +1189,7 @@ class Album(_BaseObject, _Taggable): title = None artist = None username = None + __hash__ = _BaseObject.__hash__ def __init__(self, artist, title, network, username=None): """ @@ -1358,6 +1359,7 @@ class Artist(_BaseObject, _Taggable): name = None username = None + __hash__ = _BaseObject.__hash__ def __init__(self, name, network, username=None): """Create an artist object. diff --git a/test_pylast.py b/test_pylast.py index db14355..dab6c6f 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -361,6 +361,32 @@ class TestPyLast(unittest.TestCase): self.assertTrue(type(tags[0]) == pylast.TopItem) + def test_album_is_hashable(self): + # Arrange + album = self.network.get_album("Test Artist", "Test Album") + albums = set() + + # Act + albums.add(album) + + # Assert + self.assertIsNotNone(album) + self.assertEqual(len(albums), 1) + + + def test_artist_is_hashable(self): + # Arrange + artist = self.network.get_artist("Test Artist") + artists = set() + + # Act + artists.add(artist) + + # Assert + self.assertIsNotNone(artist) + self.assertEqual(len(artists), 1) + + def test_track_is_hashable(self): # Arrange lastfm_user = self.network.get_user(self.username) @@ -376,10 +402,6 @@ class TestPyLast(unittest.TestCase): def test_user_is_hashable(self): - # TODO same for some other types - # https://github.com/hugovk/pylast/issues/82 - # (passes in Python 2.7 but how about 3?) - # Arrange lastfm_user = self.network.get_user(self.username) users = set()