Merge pull request #355 from pylast/fix-default-limit

This commit is contained in:
Hugo van Kemenade 2020-12-28 23:30:39 +02:00 committed by GitHub
commit 66b4cb7d10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 31 deletions

View file

@ -1146,10 +1146,10 @@ class _BaseObject:
return first_child.wholeText.strip()
def _get_things(self, method, thing, thing_type, params=None, cacheable=True):
"""Returns a list of the most played thing_types by this thing."""
def _get_things(self, method, thing_type, params=None, cacheable=True):
"""Returns a list of the most played thing_types."""
limit = params.get("limit", 1)
limit = params.get("limit", 50)
seq = []
for node in _collect_nodes(
limit, self, self.ws_prefix + "." + method, cacheable, params
@ -1812,7 +1812,7 @@ class Artist(_BaseObject, _Taggable):
if limit:
params["limit"] = limit
return self._get_things("getTopAlbums", "album", Album, params, cacheable)
return self._get_things("getTopAlbums", Album, params, cacheable)
def get_top_tracks(self, limit=None, cacheable=True):
"""Returns a list of the most played Tracks by this artist."""
@ -1820,7 +1820,7 @@ class Artist(_BaseObject, _Taggable):
if limit:
params["limit"] = limit
return self._get_things("getTopTracks", "track", Track, params, cacheable)
return self._get_things("getTopTracks", Track, params, cacheable)
def get_url(self, domain_name=DOMAIN_ENGLISH):
"""Returns the URL of the artist page on the network.
@ -1894,7 +1894,7 @@ class Country(_BaseObject):
if limit:
params["limit"] = limit
return self._get_things("getTopTracks", "track", Track, params, cacheable)
return self._get_things("getTopTracks", Track, params, cacheable)
def get_url(self, domain_name=DOMAIN_ENGLISH):
"""Returns the URL of the country page on the network.
@ -2024,7 +2024,7 @@ class Tag(_BaseObject, _Chartable):
if limit:
params["limit"] = limit
return self._get_things("getTopTracks", "track", Track, params, cacheable)
return self._get_things("getTopTracks", Track, params, cacheable)
def get_top_artists(self, limit=None, cacheable=True):
"""Returns a sequence of the most played artists."""
@ -2498,7 +2498,7 @@ class User(_BaseObject, _Chartable):
if limit:
params["limit"] = limit
return self._get_things("getTopTracks", "track", Track, params, cacheable)
return self._get_things("getTopTracks", Track, params, cacheable)
def get_track_scrobbles(self, artist, track, cacheable=False):
"""

View file

@ -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)
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)
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 = 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")

View file

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