Hashable artist and album, for #82

This commit is contained in:
hugovk 2014-03-02 14:46:13 +02:00
parent 1b5a09b404
commit 3fe197bbcc
3 changed files with 29 additions and 4 deletions

1
.gitignore vendored
View file

@ -27,6 +27,7 @@ pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache

View file

@ -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.

View file

@ -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()