Library, Playlist, XSPF and Group now also hashable, with a helper function to reduce test duplication. For #82.
This commit is contained in:
parent
b29b002b70
commit
6db87f8a27
|
@ -1979,6 +1979,8 @@ class Library(_BaseObject):
|
||||||
|
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
|
__hash__ = _BaseObject.__hash__
|
||||||
|
|
||||||
def __init__(self, user, network):
|
def __init__(self, user, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2138,6 +2140,8 @@ class Playlist(_BaseObject):
|
||||||
id = None
|
id = None
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
|
__hash__ = _BaseObject.__hash__
|
||||||
|
|
||||||
def __init__(self, user, id, network):
|
def __init__(self, user, id, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2697,6 +2701,8 @@ class Group(_BaseObject):
|
||||||
|
|
||||||
name = None
|
name = None
|
||||||
|
|
||||||
|
__hash__ = _BaseObject.__hash__
|
||||||
|
|
||||||
def __init__(self, group_name, network):
|
def __init__(self, group_name, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2828,6 +2834,8 @@ class XSPF(_BaseObject):
|
||||||
|
|
||||||
uri = None
|
uri = None
|
||||||
|
|
||||||
|
__hash__ = _BaseObject.__hash__
|
||||||
|
|
||||||
def __init__(self, uri, network):
|
def __init__(self, uri, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
|
111
test_pylast.py
111
test_pylast.py
|
@ -361,111 +361,114 @@ class TestPyLast(unittest.TestCase):
|
||||||
self.assertTrue(type(tags[0]) == pylast.TopItem)
|
self.assertTrue(type(tags[0]) == pylast.TopItem)
|
||||||
|
|
||||||
|
|
||||||
|
def helper_is_thing_hashable(self, thing):
|
||||||
|
# Arrange
|
||||||
|
things = set()
|
||||||
|
|
||||||
|
# Act
|
||||||
|
things.add(thing)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(thing)
|
||||||
|
self.assertEqual(len(things), 1)
|
||||||
|
|
||||||
def test_album_is_hashable(self):
|
def test_album_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = self.network.get_album("Test Artist", "Test Album")
|
album = self.network.get_album("Test Artist", "Test Album")
|
||||||
albums = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
albums.add(album)
|
self.helper_is_thing_hashable(album)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(album)
|
|
||||||
self.assertEqual(len(albums), 1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_artist_is_hashable(self):
|
def test_artist_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
artists = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
artists.add(artist)
|
self.helper_is_thing_hashable(artist)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(artist)
|
|
||||||
self.assertEqual(len(artists), 1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_country_is_hashable(self):
|
def test_country_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
country = pylast.Country("Italy", self.network)
|
country = pylast.Country("Italy", self.network)
|
||||||
countries = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
countries.add(country)
|
self.helper_is_thing_hashable(country)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(country)
|
|
||||||
self.assertEqual(len(countries), 1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_event_is_hashable(self):
|
def test_event_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
event = user.get_past_events(limit = 1)[0]
|
event = user.get_past_events(limit = 1)[0]
|
||||||
events = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
events.add(event)
|
self.helper_is_thing_hashable(event)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(event)
|
def test_group_is_hashable(self):
|
||||||
self.assertEqual(len(events), 1)
|
# Arrange
|
||||||
|
group = pylast.Group("Audioscrobbler Beta", self.network)
|
||||||
|
|
||||||
|
# Act/Assert
|
||||||
|
self.helper_is_thing_hashable(group)
|
||||||
|
|
||||||
|
|
||||||
|
def test_library_is_hashable(self):
|
||||||
|
# Arrange
|
||||||
|
library = pylast.Library(user = self.username, network = self.network)
|
||||||
|
|
||||||
|
# Act/Assert
|
||||||
|
self.helper_is_thing_hashable(library)
|
||||||
|
|
||||||
|
|
||||||
|
def test_playlist_is_hashable(self):
|
||||||
|
# Arrange
|
||||||
|
playlist = pylast.Playlist(user = "RJ", id = "1k1qp_doglist", network = self.network)
|
||||||
|
|
||||||
|
# Act/Assert
|
||||||
|
self.helper_is_thing_hashable(playlist)
|
||||||
|
|
||||||
|
|
||||||
def test_tag_is_hashable(self):
|
def test_tag_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = self.network.get_top_tags(limit = 1)[0]
|
tag = self.network.get_top_tags(limit = 1)[0]
|
||||||
tags = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
tags.add(tag)
|
self.helper_is_thing_hashable(tag)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(tag)
|
|
||||||
self.assertEqual(len(tags), 1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_track_is_hashable(self):
|
def test_track_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
track = lastfm_user.get_recent_tracks(limit = 2)[0] # 2 to ignore now-playing
|
track = lastfm_user.get_recent_tracks(limit = 2)[0] # 2 to ignore now-playing
|
||||||
tracks = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
tracks.add(track)
|
self.helper_is_thing_hashable(track)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(track)
|
|
||||||
self.assertEqual(len(tracks), 1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_user_is_hashable(self):
|
def test_user_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
users = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
users.add(lastfm_user)
|
self.helper_is_thing_hashable(lastfm_user)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(lastfm_user)
|
|
||||||
self.assertEqual(len(users), 1)
|
|
||||||
|
|
||||||
|
|
||||||
def test_venue_is_hashable(self):
|
def test_venue_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
venue_id = "8778225" # Last.fm office
|
venue_id = "8778225" # Last.fm office
|
||||||
venue = pylast.Venue(venue_id, self.network)
|
venue = pylast.Venue(venue_id, self.network)
|
||||||
venues = set()
|
|
||||||
|
|
||||||
# Act
|
# Act/Assert
|
||||||
venues.add(venue)
|
self.helper_is_thing_hashable(venue)
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertIsNotNone(venue)
|
def test_xspf_is_hashable(self):
|
||||||
self.assertEqual(len(venues), 1)
|
# Arrange
|
||||||
|
xspf = pylast.XSPF(uri = "lastfm://playlist/1k1qp_doglist", network = self.network)
|
||||||
|
|
||||||
|
# Act/Assert
|
||||||
|
self.helper_is_thing_hashable(xspf)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue