Added option to stream from resources to reduce memory usage
This commit is contained in:
parent
705052ae66
commit
92004058ba
8 changed files with 174 additions and 192 deletions
|
@ -32,7 +32,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
|||
|
||||
# Act
|
||||
# limit=2 to ignore now-playing:
|
||||
track = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
track = list(lastfm_user.get_recent_tracks(limit=2))[0]
|
||||
|
||||
# Assert
|
||||
assert hasattr(track, "album")
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
"""
|
||||
Integration (not unit) tests for pylast.py
|
||||
"""
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
@ -78,7 +78,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
|
||||
# Act
|
||||
things = artist.get_top_tracks(limit=2)
|
||||
things = artist.get_top_tracks(limit=2, stream=False)
|
||||
|
||||
# Assert
|
||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||
|
@ -89,7 +89,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
|
||||
# Act
|
||||
things = artist.get_top_albums(limit=2)
|
||||
things = list(artist.get_top_albums(limit=2))
|
||||
|
||||
# Assert
|
||||
self.helper_two_different_things_in_top_list(things, pylast.Album)
|
||||
|
@ -101,7 +101,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
|
||||
# Act
|
||||
things = artist.get_top_albums(limit=limit)
|
||||
things = artist.get_top_albums(limit=limit, stream=False)
|
||||
|
||||
# Assert
|
||||
assert len(things) == 1
|
||||
|
@ -113,7 +113,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
|
||||
# Act
|
||||
things = artist.get_top_albums(limit=limit)
|
||||
things = artist.get_top_albums(limit=limit, stream=False)
|
||||
|
||||
# Assert
|
||||
assert len(things) == 50
|
||||
|
@ -125,7 +125,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
|
||||
# Act
|
||||
things = artist.get_top_albums(limit=limit)
|
||||
things = list(artist.get_top_albums(limit=limit))
|
||||
|
||||
# Assert
|
||||
assert len(things) == 100
|
||||
|
|
|
@ -5,9 +5,9 @@ Integration (not unit) tests for pylast.py
|
|||
import re
|
||||
import time
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
# limit=2 to ignore now-playing:
|
||||
last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
last_scrobble = list(lastfm_user.get_recent_tracks(limit=2))[0]
|
||||
assert str(last_scrobble.track.artist).lower() == artist
|
||||
assert str(last_scrobble.track.title).lower() == title
|
||||
|
||||
|
@ -153,7 +153,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
country = self.network.get_country("Croatia")
|
||||
|
||||
# Act
|
||||
things = country.get_top_tracks(limit=2)
|
||||
things = country.get_top_tracks(limit=2, stream=False)
|
||||
|
||||
# Assert
|
||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||
|
@ -171,7 +171,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
tag = self.network.get_tag("blues")
|
||||
|
||||
# Act
|
||||
things = tag.get_top_tracks(limit=2)
|
||||
things = tag.get_top_tracks(limit=2, stream=False)
|
||||
|
||||
# Assert
|
||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||
|
|
|
@ -6,10 +6,11 @@ import os
|
|||
import sys
|
||||
import time
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
from flaky import flaky
|
||||
|
||||
import pylast
|
||||
|
||||
WRITE_TEST = sys.version_info[:2] == (3, 8)
|
||||
|
||||
|
||||
|
@ -82,9 +83,9 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
assert a is not None
|
||||
assert b is not None
|
||||
assert c is not None
|
||||
assert len(a) >= 0
|
||||
assert len(b) >= 0
|
||||
assert len(c) >= 0
|
||||
assert isinstance(len(a), int)
|
||||
assert isinstance(len(b), int)
|
||||
assert isinstance(len(c), int)
|
||||
assert a == b
|
||||
assert b == c
|
||||
|
||||
|
@ -94,9 +95,9 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
func = getattr(thing, function_name, None)
|
||||
|
||||
# Act
|
||||
result1 = func(limit=1, cacheable=False)
|
||||
result2 = func(limit=1, cacheable=True)
|
||||
result3 = func(limit=1)
|
||||
result1 = func(limit=1, cacheable=False, stream=False)
|
||||
result2 = func(limit=1, cacheable=True, stream=False)
|
||||
result3 = list(func(limit=1))
|
||||
|
||||
# Assert
|
||||
self.helper_validate_results(result1, result2, result3)
|
||||
|
|
|
@ -4,9 +4,9 @@ Integration (not unit) tests for pylast.py
|
|||
"""
|
||||
import time
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
|||
track.love()
|
||||
|
||||
# Assert
|
||||
loved = lastfm_user.get_loved_tracks(limit=1)
|
||||
loved = list(lastfm_user.get_loved_tracks(limit=1))
|
||||
assert str(loved[0].track.artist).lower() == "test artist"
|
||||
assert str(loved[0].track.title).lower() == "test title"
|
||||
|
||||
|
@ -41,7 +41,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
|||
time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later?
|
||||
|
||||
# Assert
|
||||
loved = lastfm_user.get_loved_tracks(limit=1)
|
||||
loved = list(lastfm_user.get_loved_tracks(limit=1))
|
||||
if len(loved): # OK to be empty but if not:
|
||||
assert str(loved[0].track.artist) != "Test Artist"
|
||||
assert str(loved[0].track.title) != "test title"
|
||||
|
@ -79,7 +79,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
|||
def test_track_is_hashable(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
track = artist.get_top_tracks()[0].item
|
||||
track = artist.get_top_tracks(stream=False)[0].item
|
||||
assert isinstance(track, pylast.Track)
|
||||
|
||||
# Act/Assert
|
||||
|
|
|
@ -8,9 +8,9 @@ import os
|
|||
import re
|
||||
import warnings
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
from .test_pylast import TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
@ -142,10 +142,10 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
user = self.network.get_user("test-user")
|
||||
|
||||
# Act/Assert
|
||||
assert len(user.get_loved_tracks(limit=20)) == 20
|
||||
assert len(user.get_loved_tracks(limit=100)) <= 100
|
||||
assert len(user.get_loved_tracks(limit=None)) >= 23
|
||||
assert len(user.get_loved_tracks(limit=0)) >= 23
|
||||
assert len(user.get_loved_tracks(limit=20, stream=False)) == 20
|
||||
assert len(user.get_loved_tracks(limit=100, stream=False)) <= 100
|
||||
assert len(user.get_loved_tracks(limit=None, stream=False)) >= 23
|
||||
assert len(user.get_loved_tracks(limit=0, stream=False)) >= 23
|
||||
|
||||
def test_user_is_hashable(self):
|
||||
# Arrange
|
||||
|
@ -210,7 +210,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
lastfm_user = self.network.get_user("RJ")
|
||||
|
||||
# Act
|
||||
things = lastfm_user.get_top_tracks(limit=2)
|
||||
things = lastfm_user.get_top_tracks(limit=2, stream=False)
|
||||
|
||||
# Assert
|
||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||
|
@ -361,7 +361,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
utc_end = calendar.timegm(end.utctimetuple())
|
||||
|
||||
# Act
|
||||
tracks = lastfm_user.get_recent_tracks(time_from=utc_start, time_to=utc_end)
|
||||
tracks = lastfm_user.get_recent_tracks(time_from=utc_start, time_to=utc_end, stream=False)
|
||||
|
||||
# Assert
|
||||
assert len(tracks) == 1
|
||||
|
@ -379,7 +379,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
|
||||
# Act
|
||||
tracks = lastfm_user.get_recent_tracks(
|
||||
time_from=utc_start, time_to=utc_end, limit=None
|
||||
time_from=utc_start, time_to=utc_end, limit=None, stream=False
|
||||
)
|
||||
|
||||
# Assert
|
||||
|
@ -449,7 +449,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
user = self.network.get_user("bbc6music")
|
||||
|
||||
# Act
|
||||
scrobbles = user.get_track_scrobbles(artist, title)
|
||||
scrobbles = user.get_track_scrobbles(artist, title, stream=False)
|
||||
|
||||
# Assert
|
||||
assert len(scrobbles) > 0
|
||||
|
@ -463,9 +463,9 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
user = self.network.get_user("bbc6music")
|
||||
|
||||
# Act
|
||||
result1 = user.get_track_scrobbles(artist, title, cacheable=False)
|
||||
result2 = user.get_track_scrobbles(artist, title, cacheable=True)
|
||||
result3 = user.get_track_scrobbles(artist, title)
|
||||
result1 = user.get_track_scrobbles(artist, title, cacheable=False, stream=False)
|
||||
result2 = list(user.get_track_scrobbles(artist, title, cacheable=True))
|
||||
result3 = list(user.get_track_scrobbles(artist, title))
|
||||
|
||||
# Assert
|
||||
self.helper_validate_results(result1, result2, result3)
|
||||
|
@ -480,4 +480,4 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
match="Deprecated - This type of request is no longer supported",
|
||||
):
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||
lastfm_user.get_artist_tracks(artist="Test Artist")
|
||||
lastfm_user.get_artist_tracks(artist="Test Artist", stream=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue