diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 40e7470..1a24622 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -1147,12 +1147,12 @@ class _BaseObject: return first_child.wholeText.strip() def _get_things( - self, method, thing, thing_type, params=None, cacheable=True, stream=False + self, method, thing_type, params=None, cacheable=True, stream=False ): """Returns a list of the most played thing_types by this thing.""" def _stream_get_things(): - limit = params.get("limit", 1) + limit = params.get("limit", 50) nodes = _collect_nodes( limit, self, @@ -1818,9 +1818,7 @@ class Artist(_Taggable): if limit: params["limit"] = limit - return self._get_things( - "getTopAlbums", "album", Album, params, cacheable, stream=stream - ) + return self._get_things("getTopAlbums", Album, params, cacheable, stream=stream) def get_top_tracks(self, limit=None, cacheable=True, stream=False): """Returns a list of the most played Tracks by this artist.""" @@ -1828,9 +1826,7 @@ class Artist(_Taggable): if limit: params["limit"] = limit - return self._get_things( - "getTopTracks", "track", Track, params, cacheable, stream=stream - ) + return self._get_things("getTopTracks", Track, params, cacheable, stream=stream) def get_url(self, domain_name=DOMAIN_ENGLISH): """Returns the URL of the artist page on the network. @@ -1904,9 +1900,7 @@ class Country(_BaseObject): if limit: params["limit"] = limit - return self._get_things( - "getTopTracks", "track", Track, params, cacheable, stream=stream - ) + return self._get_things("getTopTracks", Track, params, cacheable, stream=stream) def get_url(self, domain_name=DOMAIN_ENGLISH): """Returns the URL of the country page on the network. @@ -2035,9 +2029,7 @@ class Tag(_Chartable): if limit: params["limit"] = limit - return self._get_things( - "getTopTracks", "track", Track, params, cacheable, stream=stream - ) + return self._get_things("getTopTracks", Track, params, cacheable, stream=stream) def get_top_artists(self, limit=None, cacheable=True): """Returns a sequence of the most played artists.""" @@ -2244,7 +2236,7 @@ class User(_Chartable): return self.name - def get_friends(self, limit=50, cacheable=False): + def get_friends(self, limit=50, cacheable=False, stream=False): """Returns a list of the user's friends. """ def _get_friends(): @@ -2261,7 +2253,7 @@ class User(_Chartable): reverse order of their timestamp, all the way back to the first track. If limit==None, it will try to pull all the available data. - If stream=False, it will yield tracks as soon as a page has been retrieved. + If stream=True, it will yield tracks as soon as a page has been retrieved. This method uses caching. Enable caching only if you're pulling a large amount of data. @@ -2530,9 +2522,7 @@ class User(_Chartable): if limit: params["limit"] = limit - return self._get_things( - "getTopTracks", "track", Track, params, cacheable, stream=stream - ) + return self._get_things("getTopTracks", Track, params, cacheable, stream=stream) def get_track_scrobbles(self, artist, track, cacheable=False, stream=False): """ diff --git a/tests/test_artist.py b/tests/test_artist.py index 6c07cd9..4e8d694 100755 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -79,7 +79,7 @@ class TestPyLastArtist(TestPyLastWithLastFm): artist = self.network.get_top_artists(limit=1)[0].item # Act - things = artist.get_top_tracks(limit=2, stream=False) + things = artist.get_top_tracks(limit=2) # Assert self.helper_two_different_things_in_top_list(things, pylast.Track) @@ -95,42 +95,29 @@ class TestPyLastArtist(TestPyLastWithLastFm): # Assert self.helper_two_different_things_in_top_list(things, pylast.Album) - def test_artist_top_albums_limit_1(self): + @pytest.mark.parametrize("test_limit", [1, 50, 100]) + def test_artist_top_albums_limit(self, test_limit: int) -> None: # Arrange - limit = 1 # Pick an artist with plenty of plays artist = self.network.get_top_artists(limit=1)[0].item # Act - things = artist.get_top_albums(limit=limit, stream=False) + things = artist.get_top_albums(limit=test_limit) # Assert - assert len(things) == 1 + assert len(things) == test_limit - def test_artist_top_albums_limit_50(self): + def test_artist_top_albums_limit_default(self): # Arrange - limit = 50 # Pick an artist with plenty of plays artist = self.network.get_top_artists(limit=1)[0].item # Act - things = artist.get_top_albums(limit=limit, stream=False) + things = artist.get_top_albums() # Assert assert len(things) == 50 - def test_artist_top_albums_limit_100(self): - # Arrange - limit = 100 - # Pick an artist with plenty of plays - artist = self.network.get_top_artists(limit=1)[0].item - - # Act - things = list(artist.get_top_albums(limit=limit)) - - # Assert - assert len(things) == 100 - def test_artist_listener_count(self): # Arrange artist = self.network.get_artist("Test Artist") diff --git a/tests/test_network.py b/tests/test_network.py index 6f46ab4..b45fafa 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -154,7 +154,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm): country = self.network.get_country("Croatia") # Act - things = country.get_top_tracks(limit=2, stream=False) + things = country.get_top_tracks(limit=2) # Assert self.helper_two_different_things_in_top_list(things, pylast.Track) @@ -172,7 +172,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm): tag = self.network.get_tag("blues") # Act - things = tag.get_top_tracks(limit=2, stream=False) + things = tag.get_top_tracks(limit=2) # Assert self.helper_two_different_things_in_top_list(things, pylast.Track) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 2b6f955..4c39f33 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -34,11 +34,11 @@ def load_secrets(): # pragma: no cover class PyLastTestCase: - def assert_startswith(self, str, prefix, start=None, end=None): - assert str.startswith(prefix, start, end) + def assert_startswith(self, s, prefix, start=None, end=None): + assert s.startswith(prefix, start, end) - def assert_endswith(self, str, suffix, start=None, end=None): - assert str.endswith(suffix, start, end) + def assert_endswith(self, s, suffix, start=None, end=None): + assert s.endswith(suffix, start, end) def _no_xfail_rerun_filter(err, name, test, plugin): @@ -100,8 +100,8 @@ class TestPyLastWithLastFm(PyLastTestCase): func = getattr(thing, function_name, None) # Act - result1 = func(limit=1, cacheable=False, stream=False) - result2 = func(limit=1, cacheable=True, stream=False) + result1 = func(limit=1, cacheable=False) + result2 = func(limit=1, cacheable=True) result3 = list(func(limit=1)) # Assert diff --git a/tests/test_user.py b/tests/test_user.py index 6b03bc0..5f68262 100755 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -143,10 +143,10 @@ class TestPyLastUser(TestPyLastWithLastFm): user = self.network.get_user("test-user") # Act/Assert - 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 + 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 def test_user_is_hashable(self): # Arrange @@ -216,7 +216,7 @@ class TestPyLastUser(TestPyLastWithLastFm): lastfm_user = self.network.get_user("RJ") # Act - things = lastfm_user.get_top_tracks(limit=2, stream=False) + things = lastfm_user.get_top_tracks(limit=2) # Assert self.helper_two_different_things_in_top_list(things, pylast.Track) @@ -367,9 +367,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, stream=False - ) + tracks = lastfm_user.get_recent_tracks(time_from=utc_start, time_to=utc_end) # Assert assert len(tracks) == 1 @@ -387,7 +385,7 @@ class TestPyLastUser(TestPyLastWithLastFm): # Act tracks = lastfm_user.get_recent_tracks( - time_from=utc_start, time_to=utc_end, limit=None, stream=False + time_from=utc_start, time_to=utc_end, limit=None ) # Assert @@ -474,7 +472,7 @@ class TestPyLastUser(TestPyLastWithLastFm): user = self.network.get_user("bbc6music") # Act - scrobbles = user.get_track_scrobbles(artist, title, stream=False) + scrobbles = user.get_track_scrobbles(artist, title) # Assert assert len(scrobbles) > 0 @@ -488,7 +486,7 @@ class TestPyLastUser(TestPyLastWithLastFm): user = self.network.get_user("bbc6music") # Act - result1 = user.get_track_scrobbles(artist, title, cacheable=False, stream=False) + result1 = user.get_track_scrobbles(artist, title, cacheable=False) result2 = list(user.get_track_scrobbles(artist, title, cacheable=True)) result3 = list(user.get_track_scrobbles(artist, title))