autotyping: --none-return: add a -> None return type to functions without any return, yield, or raise in their body

This commit is contained in:
Hugo van Kemenade 2022-04-03 12:43:37 +03:00
parent 4e5fe31572
commit 6c3f3afb3a
12 changed files with 184 additions and 182 deletions

View file

@ -156,7 +156,7 @@ class _Network:
domain_names,
urls,
token=None,
):
) -> None:
"""
name: the name of the network
homepage: the homepage URL
@ -284,7 +284,7 @@ class _Network:
"""
return self.api_key, self.api_secret, self.session_key
def _delay_call(self):
def _delay_call(self) -> None:
"""
Makes sure that web service calls are at least 0.2 seconds apart.
"""
@ -496,7 +496,7 @@ class _Network:
track_number=None,
mbid=None,
context=None,
):
) -> None:
"""
Used to notify Last.fm that a user has started listening to a track.
@ -583,7 +583,7 @@ class _Network:
)
)
def scrobble_many(self, tracks):
def scrobble_many(self, tracks) -> None:
"""
Used to scrobble a batch of tracks at once. The parameter tracks is a
sequence of dicts per track containing the keyword arguments as if
@ -664,7 +664,7 @@ class LastFMNetwork(_Network):
username="",
password_hash="",
token="",
):
) -> None:
super().__init__(
name="Last.fm",
homepage="https://www.last.fm",
@ -728,7 +728,7 @@ class LibreFMNetwork(_Network):
def __init__(
self, api_key="", api_secret="", session_key="", username="", password_hash=""
):
) -> None:
super().__init__(
name="Libre.fm",
@ -778,7 +778,7 @@ class LibreFMNetwork(_Network):
class _ShelfCacheBackend:
"""Used as a backend for caching cacheable requests."""
def __init__(self, file_path=None, flag=None):
def __init__(self, file_path=None, flag=None) -> None:
if flag is not None:
self.shelf = shelve.open(file_path, flag=flag)
else:
@ -794,7 +794,7 @@ class _ShelfCacheBackend:
def get_xml(self, key):
return self.shelf[key]
def set_xml(self, key, xml_string):
def set_xml(self, key, xml_string) -> None:
self.cache_keys.add(key)
self.shelf[key] = xml_string
@ -808,7 +808,7 @@ class _ShelfCacheBackend:
class _Request:
"""Representing an abstract web service operation."""
def __init__(self, network, method_name, params=None):
def __init__(self, network, method_name, params=None) -> None:
logger.info(method_name)
if params is None:
@ -832,7 +832,7 @@ class _Request:
self.params["sk"] = self.session_key
self.sign_it()
def sign_it(self):
def sign_it(self) -> None:
"""Sign this request."""
if "api_sig" not in self.params.keys():
@ -982,7 +982,7 @@ class SessionKeyGenerator:
unless you want to.
"""
def __init__(self, network):
def __init__(self, network) -> None:
self.network = network
self.web_auth_tokens = {}
@ -1094,7 +1094,7 @@ class _BaseObject:
network = None
def __init__(self, network, ws_prefix):
def __init__(self, network, ws_prefix) -> None:
self.network = network
self.ws_prefix = ws_prefix
@ -1194,7 +1194,7 @@ class _BaseObject:
class _Chartable(_BaseObject):
"""Common functions for classes with charts."""
def __init__(self, network, ws_prefix):
def __init__(self, network, ws_prefix) -> None:
super().__init__(network=network, ws_prefix=ws_prefix)
def get_weekly_chart_dates(self):
@ -1265,10 +1265,10 @@ class _Chartable(_BaseObject):
class _Taggable(_BaseObject):
"""Common functions for classes with tags."""
def __init__(self, network, ws_prefix):
def __init__(self, network, ws_prefix) -> None:
super().__init__(network=network, ws_prefix=ws_prefix)
def add_tags(self, tags):
def add_tags(self, tags) -> None:
"""Adds one or several tags.
* tags: A sequence of tag names or Tag objects.
"""
@ -1276,7 +1276,7 @@ class _Taggable(_BaseObject):
for tag in tags:
self.add_tag(tag)
def add_tag(self, tag):
def add_tag(self, tag) -> None:
"""Adds one tag.
* tag: a tag name or a Tag object.
"""
@ -1289,7 +1289,7 @@ class _Taggable(_BaseObject):
self._request(self.ws_prefix + ".addTags", False, params)
def remove_tag(self, tag):
def remove_tag(self, tag) -> None:
"""Remove a user's tag from this object."""
if isinstance(tag, Tag):
@ -1314,7 +1314,7 @@ class _Taggable(_BaseObject):
return tags
def remove_tags(self, tags):
def remove_tags(self, tags) -> None:
"""Removes one or several tags from this object.
* tags: a sequence of tag names or Tag objects.
"""
@ -1322,12 +1322,12 @@ class _Taggable(_BaseObject):
for tag in tags:
self.remove_tag(tag)
def clear_tags(self):
def clear_tags(self) -> None:
"""Clears all the user-set tags."""
self.remove_tags(*(self.get_tags()))
def set_tags(self, tags):
def set_tags(self, tags) -> None:
"""Sets this object's tags to only those tags.
* tags: a sequence of tag names or Tag objects.
"""
@ -1390,7 +1390,7 @@ class PyLastError(Exception):
class WSError(PyLastError):
"""Exception related to the Network web service"""
def __init__(self, network, status, details):
def __init__(self, network, status, details) -> None:
self.status = status
self.details = details
self.network = network
@ -1434,7 +1434,7 @@ class WSError(PyLastError):
class MalformedResponseError(PyLastError):
"""Exception conveying a malformed response from the music network."""
def __init__(self, network, underlying_error):
def __init__(self, network, underlying_error) -> None:
self.network = network
self.underlying_error = underlying_error
@ -1448,7 +1448,7 @@ class MalformedResponseError(PyLastError):
class NetworkError(PyLastError):
"""Exception conveying a problem in sending a request to Last.fm"""
def __init__(self, network, underlying_error):
def __init__(self, network, underlying_error) -> None:
self.network = network
self.underlying_error = underlying_error
@ -1465,7 +1465,9 @@ class _Opus(_Taggable):
__hash__ = _BaseObject.__hash__
def __init__(self, artist, title, network, ws_prefix, username=None, info=None):
def __init__(
self, artist, title, network, ws_prefix, username=None, info=None
) -> None:
"""
Create an opus instance.
# Parameters:
@ -1608,7 +1610,7 @@ class Album(_Opus):
__hash__ = _Opus.__hash__
def __init__(self, artist, title, network, username=None, info=None):
def __init__(self, artist, title, network, username=None, info=None) -> None:
super().__init__(artist, title, network, "album", username, info)
def get_tracks(self):
@ -1653,7 +1655,7 @@ class Artist(_Taggable):
__hash__ = _BaseObject.__hash__
def __init__(self, name, network, username=None, info=None):
def __init__(self, name, network, username=None, info=None) -> None:
"""Create an artist object.
# Parameters:
* name str: The artist's name.
@ -1843,7 +1845,7 @@ class Country(_BaseObject):
__hash__ = _BaseObject.__hash__
def __init__(self, name, network):
def __init__(self, name, network) -> None:
super().__init__(network=network, ws_prefix="geo")
self.name = name
@ -1918,7 +1920,7 @@ class Library(_BaseObject):
__hash__ = _BaseObject.__hash__
def __init__(self, user, network):
def __init__(self, user, network) -> None:
super().__init__(network=network, ws_prefix="library")
if isinstance(user, User):
@ -1967,7 +1969,7 @@ class Tag(_Chartable):
__hash__ = _BaseObject.__hash__
def __init__(self, name, network):
def __init__(self, name, network) -> None:
super().__init__(network=network, ws_prefix="tag")
self.name = name
@ -2054,7 +2056,7 @@ class Track(_Opus):
__hash__ = _Opus.__hash__
def __init__(self, artist, title, network, username=None, info=None):
def __init__(self, artist, title, network, username=None, info=None) -> None:
super().__init__(artist, title, network, "track", username, info)
def get_correction(self):
@ -2097,12 +2099,12 @@ class Track(_Opus):
node = doc.getElementsByTagName("album")[0]
return Album(_extract(node, "artist"), _extract(node, "title"), self.network)
def love(self):
def love(self) -> None:
"""Adds the track to the user's loved tracks."""
self._request(self.ws_prefix + ".love")
def unlove(self):
def unlove(self) -> None:
"""Remove the track to the user's loved tracks."""
self._request(self.ws_prefix + ".unlove")
@ -2163,7 +2165,7 @@ class User(_Chartable):
__hash__ = _BaseObject.__hash__
def __init__(self, user_name, network):
def __init__(self, user_name, network) -> None:
super().__init__(network=network, ws_prefix="user")
self.name = user_name
@ -2558,7 +2560,7 @@ class User(_Chartable):
class AuthenticatedUser(User):
def __init__(self, network):
def __init__(self, network) -> None:
super().__init__(user_name=network.username, network=network)
def _get_params(self):
@ -2572,7 +2574,7 @@ class AuthenticatedUser(User):
class _Search(_BaseObject):
"""An abstract class. Use one of its derivatives."""
def __init__(self, ws_prefix, search_terms, network):
def __init__(self, ws_prefix, search_terms, network) -> None:
super().__init__(network, ws_prefix)
self._ws_prefix = ws_prefix
@ -2612,7 +2614,7 @@ class _Search(_BaseObject):
class AlbumSearch(_Search):
"""Search for an album by name."""
def __init__(self, album_name, network):
def __init__(self, album_name, network) -> None:
super().__init__(
ws_prefix="album", search_terms={"album": album_name}, network=network
)
@ -2639,7 +2641,7 @@ class AlbumSearch(_Search):
class ArtistSearch(_Search):
"""Search for an artist by artist name."""
def __init__(self, artist_name, network):
def __init__(self, artist_name, network) -> None:
super().__init__(
ws_prefix="artist", search_terms={"artist": artist_name}, network=network
)
@ -2668,7 +2670,7 @@ class TrackSearch(_Search):
down by specifying the artist name, set it to empty string.
"""
def __init__(self, artist_name, track_title, network):
def __init__(self, artist_name, track_title, network) -> None:
super().__init__(
ws_prefix="track",
search_terms={"track": track_title, "artist": artist_name},

View file

@ -8,7 +8,7 @@ from .test_pylast import TestPyLastWithLastFm
class TestPyLastAlbum(TestPyLastWithLastFm):
def test_album_tags_are_topitems(self):
def test_album_tags_are_topitems(self) -> None:
# Arrange
album = self.network.get_album("Test Artist", "Test Album")
@ -19,14 +19,14 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
assert len(tags) > 0
assert isinstance(tags[0], pylast.TopItem)
def test_album_is_hashable(self):
def test_album_is_hashable(self) -> None:
# Arrange
album = self.network.get_album("Test Artist", "Test Album")
# Act/Assert
self.helper_is_thing_hashable(album)
def test_album_in_recent_tracks(self):
def test_album_in_recent_tracks(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
@ -37,7 +37,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
# Assert
assert hasattr(track, "album")
def test_album_wiki_content(self):
def test_album_wiki_content(self) -> None:
# Arrange
album = pylast.Album("Test Artist", "Test Album", self.network)
@ -48,7 +48,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
assert wiki is not None
assert len(wiki) >= 1
def test_album_wiki_published_date(self):
def test_album_wiki_published_date(self) -> None:
# Arrange
album = pylast.Album("Test Artist", "Test Album", self.network)
@ -59,7 +59,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
assert wiki is not None
assert len(wiki) >= 1
def test_album_wiki_summary(self):
def test_album_wiki_summary(self) -> None:
# Arrange
album = pylast.Album("Test Artist", "Test Album", self.network)
@ -70,7 +70,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
assert wiki is not None
assert len(wiki) >= 1
def test_album_eq_none_is_false(self):
def test_album_eq_none_is_false(self) -> None:
# Arrange
album1 = None
album2 = pylast.Album("Test Artist", "Test Album", self.network)
@ -78,7 +78,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
# Act / Assert
assert album1 != album2
def test_album_ne_none_is_true(self):
def test_album_ne_none_is_true(self) -> None:
# Arrange
album1 = None
album2 = pylast.Album("Test Artist", "Test Album", self.network)
@ -86,7 +86,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
# Act / Assert
assert album1 != album2
def test_get_cover_image(self):
def test_get_cover_image(self) -> None:
# Arrange
album = self.network.get_album("Test Artist", "Test Album")
@ -97,7 +97,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
self.assert_startswith(image, "https://")
self.assert_endswith(image, ".gif")
def test_mbid(self):
def test_mbid(self) -> None:
# Arrange
album = self.network.get_album("Radiohead", "OK Computer")
@ -107,7 +107,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
# Assert
assert mbid == "0b6b4ba0-d36f-47bd-b4ea-6a5b91842d29"
def test_no_mbid(self):
def test_no_mbid(self) -> None:
# Arrange
album = self.network.get_album("Test Artist", "Test Album")

View file

@ -10,7 +10,7 @@ from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
class TestPyLastArtist(TestPyLastWithLastFm):
def test_repr(self):
def test_repr(self) -> None:
# Arrange
artist = pylast.Artist("Test Artist", self.network)
@ -20,7 +20,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert
assert representation.startswith("pylast.Artist('Test Artist',")
def test_artist_is_hashable(self):
def test_artist_is_hashable(self) -> None:
# Arrange
test_artist = self.network.get_artist("Radiohead")
artist = test_artist.get_similar(limit=2)[0].item
@ -29,7 +29,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Act/Assert
self.helper_is_thing_hashable(artist)
def test_bio_published_date(self):
def test_bio_published_date(self) -> None:
# Arrange
artist = pylast.Artist("Test Artist", self.network)
@ -40,7 +40,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert bio is not None
assert len(bio) >= 1
def test_bio_content(self):
def test_bio_content(self) -> None:
# Arrange
artist = pylast.Artist("Test Artist", self.network)
@ -51,7 +51,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert bio is not None
assert len(bio) >= 1
def test_bio_content_none(self):
def test_bio_content_none(self) -> None:
# Arrange
# An artist with no biography, with "<content/>" in the API XML
artist = pylast.Artist("Mr Sizef + Unquote", self.network)
@ -62,7 +62,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert
assert bio is None
def test_bio_summary(self):
def test_bio_summary(self) -> None:
# Arrange
artist = pylast.Artist("Test Artist", self.network)
@ -73,7 +73,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert bio is not None
assert len(bio) >= 1
def test_artist_top_tracks(self):
def test_artist_top_tracks(self) -> None:
# Arrange
# Pick an artist with plenty of plays
artist = self.network.get_top_artists(limit=1)[0].item
@ -84,7 +84,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert
self.helper_two_different_things_in_top_list(things, pylast.Track)
def test_artist_top_albums(self):
def test_artist_top_albums(self) -> None:
# Arrange
# Pick an artist with plenty of plays
artist = self.network.get_top_artists(limit=1)[0].item
@ -107,7 +107,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert
assert len(things) == test_limit
def test_artist_top_albums_limit_default(self):
def test_artist_top_albums_limit_default(self) -> None:
# Arrange
# Pick an artist with plenty of plays
artist = self.network.get_top_artists(limit=1)[0].item
@ -118,7 +118,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert
assert len(things) == 50
def test_artist_listener_count(self):
def test_artist_listener_count(self) -> None:
# Arrange
artist = self.network.get_artist("Test Artist")
@ -130,7 +130,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert count > 0
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_tag_artist(self):
def test_tag_artist(self) -> None:
# Arrange
artist = self.network.get_artist("Test Artist")
# artist.clear_tags()
@ -145,7 +145,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert found
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_remove_tag_of_type_text(self):
def test_remove_tag_of_type_text(self) -> None:
# Arrange
tag = "testing" # text
artist = self.network.get_artist("Test Artist")
@ -160,7 +160,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert not found
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_remove_tag_of_type_tag(self):
def test_remove_tag_of_type_tag(self) -> None:
# Arrange
tag = pylast.Tag("testing", self.network) # Tag
artist = self.network.get_artist("Test Artist")
@ -175,7 +175,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert not found
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_remove_tags(self):
def test_remove_tags(self) -> None:
# Arrange
tags = ["removetag1", "removetag2"]
artist = self.network.get_artist("Test Artist")
@ -195,7 +195,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert not found2
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_set_tags(self):
def test_set_tags(self) -> None:
# Arrange
tags = ["sometag1", "sometag2"]
artist = self.network.get_artist("Test Artist 2")
@ -219,7 +219,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert found1
assert found2
def test_artists(self):
def test_artists(self) -> None:
# Arrange
artist1 = self.network.get_artist("Radiohead")
artist2 = self.network.get_artist("Portishead")
@ -239,7 +239,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
assert url == "https://www.last.fm/music/radiohead"
assert mbid == "a74b1b7f-71a5-4011-9441-d0b5e4122711"
def test_artist_eq_none_is_false(self):
def test_artist_eq_none_is_false(self) -> None:
# Arrange
artist1 = None
artist2 = pylast.Artist("Test Artist", self.network)
@ -247,7 +247,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Act / Assert
assert artist1 != artist2
def test_artist_ne_none_is_true(self):
def test_artist_ne_none_is_true(self) -> None:
# Arrange
artist1 = None
artist2 = pylast.Artist("Test Artist", self.network)
@ -255,7 +255,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Act / Assert
assert artist1 != artist2
def test_artist_get_correction(self):
def test_artist_get_correction(self) -> None:
# Arrange
artist = pylast.Artist("guns and roses", self.network)
@ -265,7 +265,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert
assert corrected_artist_name == "Guns N' Roses"
def test_get_userplaycount(self):
def test_get_userplaycount(self) -> None:
# Arrange
artist = pylast.Artist("John Lennon", self.network, username=self.username)

View file

@ -8,14 +8,14 @@ from .test_pylast import TestPyLastWithLastFm
class TestPyLastCountry(TestPyLastWithLastFm):
def test_country_is_hashable(self):
def test_country_is_hashable(self) -> None:
# Arrange
country = self.network.get_country("Italy")
# Act/Assert
self.helper_is_thing_hashable(country)
def test_countries(self):
def test_countries(self) -> None:
# Arrange
country1 = pylast.Country("Italy", self.network)
country2 = pylast.Country("Finland", self.network)

View file

@ -8,7 +8,7 @@ from .test_pylast import TestPyLastWithLastFm
class TestPyLastLibrary(TestPyLastWithLastFm):
def test_repr(self):
def test_repr(self) -> None:
# Arrange
library = pylast.Library(user=self.username, network=self.network)
@ -18,7 +18,7 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
# Assert
self.assert_startswith(representation, "pylast.Library(")
def test_str(self):
def test_str(self) -> None:
# Arrange
library = pylast.Library(user=self.username, network=self.network)
@ -28,21 +28,21 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
# Assert
self.assert_endswith(string, "'s Library")
def test_library_is_hashable(self):
def test_library_is_hashable(self) -> None:
# Arrange
library = pylast.Library(user=self.username, network=self.network)
# Act/Assert
self.helper_is_thing_hashable(library)
def test_cacheable_library(self):
def test_cacheable_library(self) -> None:
# Arrange
library = pylast.Library(self.username, self.network)
# Act/Assert
self.helper_validate_cacheable(library, "get_artists")
def test_get_user(self):
def test_get_user(self) -> None:
# Arrange
library = pylast.Library(user=self.username, network=self.network)
user_to_get = self.network.get_user(self.username)

View file

@ -13,7 +13,7 @@ from .test_pylast import PyLastTestCase, load_secrets
class TestPyLastWithLibreFm(PyLastTestCase):
"""Own class for Libre.fm because we don't need the Last.fm setUp"""
def test_libre_fm(self):
def test_libre_fm(self) -> None:
# Arrange
secrets = load_secrets()
username = secrets["username"]
@ -27,7 +27,7 @@ class TestPyLastWithLibreFm(PyLastTestCase):
# Assert
assert name == "Radiohead"
def test_repr(self):
def test_repr(self) -> None:
# Arrange
secrets = load_secrets()
username = secrets["username"]

View file

@ -13,7 +13,7 @@ from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
class TestPyLastNetwork(TestPyLastWithLastFm):
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_scrobble(self):
def test_scrobble(self) -> None:
# Arrange
artist = "test artist"
title = "test title"
@ -31,7 +31,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert str(last_scrobble.track.title).lower() == title
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_update_now_playing(self):
def test_update_now_playing(self) -> None:
# Arrange
artist = "Test Artist"
title = "test title"
@ -55,7 +55,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert len(current_track.info["image"])
assert re.search(r"^http.+$", current_track.info["image"][pylast.SIZE_LARGE])
def test_enable_rate_limiting(self):
def test_enable_rate_limiting(self) -> None:
# Arrange
assert not self.network.is_rate_limited()
@ -72,7 +72,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert self.network.is_rate_limited()
assert now - then >= 0.2
def test_disable_rate_limiting(self):
def test_disable_rate_limiting(self) -> None:
# Arrange
self.network.enable_rate_limit()
assert self.network.is_rate_limited()
@ -87,14 +87,14 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
assert not self.network.is_rate_limited()
def test_lastfm_network_name(self):
def test_lastfm_network_name(self) -> None:
# Act
name = str(self.network)
# Assert
assert name == "Last.fm Network"
def test_geo_get_top_artists(self):
def test_geo_get_top_artists(self) -> None:
# Arrange
# Act
artists = self.network.get_geo_top_artists(country="United Kingdom", limit=1)
@ -104,7 +104,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert isinstance(artists[0], pylast.TopItem)
assert isinstance(artists[0].item, pylast.Artist)
def test_geo_get_top_tracks(self):
def test_geo_get_top_tracks(self) -> None:
# Arrange
# Act
tracks = self.network.get_geo_top_tracks(
@ -116,7 +116,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert isinstance(tracks[0], pylast.TopItem)
assert isinstance(tracks[0].item, pylast.Track)
def test_network_get_top_artists_with_limit(self):
def test_network_get_top_artists_with_limit(self) -> None:
# Arrange
# Act
artists = self.network.get_top_artists(limit=1)
@ -124,7 +124,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
def test_network_get_top_tags_with_limit(self):
def test_network_get_top_tags_with_limit(self) -> None:
# Arrange
# Act
tags = self.network.get_top_tags(limit=1)
@ -132,7 +132,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
def test_network_get_top_tags_with_no_limit(self):
def test_network_get_top_tags_with_no_limit(self) -> None:
# Arrange
# Act
tags = self.network.get_top_tags()
@ -140,7 +140,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_at_least_one_thing_in_top_list(tags, pylast.Tag)
def test_network_get_top_tracks_with_limit(self):
def test_network_get_top_tracks_with_limit(self) -> None:
# Arrange
# Act
tracks = self.network.get_top_tracks(limit=1)
@ -148,7 +148,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(tracks, pylast.Track)
def test_country_top_tracks(self):
def test_country_top_tracks(self) -> None:
# Arrange
country = self.network.get_country("Croatia")
@ -158,7 +158,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_two_different_things_in_top_list(things, pylast.Track)
def test_country_network_top_tracks(self):
def test_country_network_top_tracks(self) -> None:
# Arrange
# Act
things = self.network.get_geo_top_tracks("Croatia", limit=2)
@ -166,7 +166,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_two_different_things_in_top_list(things, pylast.Track)
def test_tag_top_tracks(self):
def test_tag_top_tracks(self) -> None:
# Arrange
tag = self.network.get_tag("blues")
@ -176,7 +176,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_two_different_things_in_top_list(things, pylast.Track)
def test_album_data(self):
def test_album_data(self) -> None:
# Arrange
thing = self.network.get_album("Test Artist", "Test Album")
@ -196,7 +196,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert playcount > 1
assert "https://www.last.fm/music/test%2bartist/test%2balbum" == url
def test_track_data(self):
def test_track_data(self) -> None:
# Arrange
thing = self.network.get_track("Test Artist", "test title")
@ -217,7 +217,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert playcount > 1
assert "https://www.last.fm/fr/music/test%2bartist/_/test%2btitle" == url
def test_country_top_artists(self):
def test_country_top_artists(self) -> None:
# Arrange
country = self.network.get_country("Ukraine")
@ -227,7 +227,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
def test_caching(self):
def test_caching(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -242,7 +242,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
self.network.disable_caching()
assert not self.network.is_caching_enabled()
def test_album_mbid(self):
def test_album_mbid(self) -> None:
# Arrange
mbid = "03c91c40-49a6-44a7-90e7-a700edf97a62"
@ -255,7 +255,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert album.title == "Believe"
assert album_mbid == mbid
def test_artist_mbid(self):
def test_artist_mbid(self) -> None:
# Arrange
mbid = "7e84f845-ac16-41fe-9ff8-df12eb32af55"
@ -266,7 +266,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert isinstance(artist, pylast.Artist)
assert artist.name in ("MusicBrainz Test Artist", "MusicBrainzz Test Artist")
def test_track_mbid(self):
def test_track_mbid(self) -> None:
# Arrange
mbid = "ebc037b1-cc9c-44f2-a21f-83c219f0e1e0"
@ -279,7 +279,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert track.title == "first"
assert track_mbid == mbid
def test_init_with_token(self):
def test_init_with_token(self) -> None:
# Arrange/Act
msg = None
try:
@ -294,7 +294,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
assert msg == "Unauthorized Token - This token has not been issued"
def test_proxy(self):
def test_proxy(self) -> None:
# Arrange
proxy = "http://example.com:1234"
@ -306,7 +306,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
self.network.disable_proxy()
assert not self.network.is_proxy_enabled()
def test_album_search(self):
def test_album_search(self) -> None:
# Arrange
album = "Nevermind"
@ -318,7 +318,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert isinstance(results, list)
assert isinstance(results[0], pylast.Album)
def test_album_search_images(self):
def test_album_search_images(self) -> None:
# Arrange
album = "Nevermind"
search = self.network.search_for_album(album)
@ -338,7 +338,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
def test_artist_search(self):
def test_artist_search(self) -> None:
# Arrange
artist = "Nirvana"
@ -350,7 +350,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert isinstance(results, list)
assert isinstance(results[0], pylast.Artist)
def test_artist_search_images(self):
def test_artist_search_images(self) -> None:
# Arrange
artist = "Nirvana"
search = self.network.search_for_artist(artist)
@ -370,7 +370,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
def test_track_search(self):
def test_track_search(self) -> None:
# Arrange
artist = "Nirvana"
track = "Smells Like Teen Spirit"
@ -383,7 +383,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
assert isinstance(results, list)
assert isinstance(results[0], pylast.Track)
def test_track_search_images(self):
def test_track_search_images(self) -> None:
# Arrange
artist = "Nirvana"
track = "Smells Like Teen Spirit"
@ -404,7 +404,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
def test_search_get_total_result_count(self):
def test_search_get_total_result_count(self) -> None:
# Arrange
artist = "Nirvana"
track = "Smells Like Teen Spirit"

View file

@ -33,10 +33,10 @@ def load_secrets(): # pragma: no cover
class PyLastTestCase:
def assert_startswith(self, s, prefix, start=None, end=None):
def assert_startswith(self, s, prefix, start=None, end=None) -> None:
assert s.startswith(prefix, start, end)
def assert_endswith(self, s, suffix, start=None, end=None):
def assert_endswith(self, s, suffix, start=None, end=None) -> None:
assert s.endswith(suffix, start, end)
@ -54,7 +54,7 @@ class TestPyLastWithLastFm(PyLastTestCase):
return int(time.time())
@classmethod
def setup_class(cls):
def setup_class(cls) -> None:
if cls.secrets is None:
cls.secrets = load_secrets()
@ -71,7 +71,7 @@ class TestPyLastWithLastFm(PyLastTestCase):
password_hash=password_hash,
)
def helper_is_thing_hashable(self, thing):
def helper_is_thing_hashable(self, thing) -> None:
# Arrange
things = set()
@ -82,7 +82,7 @@ class TestPyLastWithLastFm(PyLastTestCase):
assert thing is not None
assert len(things) == 1
def helper_validate_results(self, a, b, c):
def helper_validate_results(self, a, b, c) -> None:
# Assert
assert a is not None
assert b is not None
@ -93,7 +93,7 @@ class TestPyLastWithLastFm(PyLastTestCase):
assert a == b
assert b == c
def helper_validate_cacheable(self, thing, function_name):
def helper_validate_cacheable(self, thing, function_name) -> None:
# Arrange
# get thing.function_name()
func = getattr(thing, function_name, None)
@ -106,27 +106,27 @@ class TestPyLastWithLastFm(PyLastTestCase):
# Assert
self.helper_validate_results(result1, result2, result3)
def helper_at_least_one_thing_in_top_list(self, things, expected_type):
def helper_at_least_one_thing_in_top_list(self, things, expected_type) -> None:
# Assert
assert len(things) > 1
assert isinstance(things, list)
assert isinstance(things[0], pylast.TopItem)
assert isinstance(things[0].item, expected_type)
def helper_only_one_thing_in_top_list(self, things, expected_type):
def helper_only_one_thing_in_top_list(self, things, expected_type) -> None:
# Assert
assert len(things) == 1
assert isinstance(things, list)
assert isinstance(things[0], pylast.TopItem)
assert isinstance(things[0].item, expected_type)
def helper_only_one_thing_in_list(self, things, expected_type):
def helper_only_one_thing_in_list(self, things, expected_type) -> None:
# Assert
assert len(things) == 1
assert isinstance(things, list)
assert isinstance(things[0], expected_type)
def helper_two_different_things_in_top_list(self, things, expected_type):
def helper_two_different_things_in_top_list(self, things, expected_type) -> None:
# Assert
assert len(things) == 2
thing1 = things[0]

View file

@ -8,14 +8,14 @@ from .test_pylast import TestPyLastWithLastFm
class TestPyLastTag(TestPyLastWithLastFm):
def test_tag_is_hashable(self):
def test_tag_is_hashable(self) -> None:
# Arrange
tag = self.network.get_top_tags(limit=1)[0]
# Act/Assert
self.helper_is_thing_hashable(tag)
def test_tag_top_artists(self):
def test_tag_top_artists(self) -> None:
# Arrange
tag = self.network.get_tag("blues")
@ -25,7 +25,7 @@ class TestPyLastTag(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
def test_tag_top_albums(self):
def test_tag_top_albums(self) -> None:
# Arrange
tag = self.network.get_tag("blues")
@ -35,7 +35,7 @@ class TestPyLastTag(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(albums, pylast.Album)
def test_tags(self):
def test_tags(self) -> None:
# Arrange
tag1 = self.network.get_tag("blues")
tag2 = self.network.get_tag("rock")

View file

@ -13,7 +13,7 @@ from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
class TestPyLastTrack(TestPyLastWithLastFm):
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_love(self):
def test_love(self) -> None:
# Arrange
artist = "Test Artist"
title = "test title"
@ -29,7 +29,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert str(loved[0].track.title).lower() == "test title"
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
def test_unlove(self):
def test_unlove(self) -> None:
# Arrange
artist = pylast.Artist("Test Artist", self.network)
title = "test title"
@ -47,7 +47,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert str(loved[0].track.artist) != "Test Artist"
assert str(loved[0].track.title) != "test title"
def test_user_play_count_in_track_info(self):
def test_user_play_count_in_track_info(self) -> None:
# Arrange
artist = "Test Artist"
title = "test title"
@ -61,7 +61,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert count >= 0
def test_user_loved_in_track_info(self):
def test_user_loved_in_track_info(self) -> None:
# Arrange
artist = "Test Artist"
title = "test title"
@ -77,7 +77,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert isinstance(loved, bool)
assert not isinstance(loved, str)
def test_track_is_hashable(self):
def test_track_is_hashable(self) -> None:
# Arrange
artist = self.network.get_artist("Test Artist")
track = artist.get_top_tracks(stream=False)[0].item
@ -86,7 +86,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Act/Assert
self.helper_is_thing_hashable(track)
def test_track_wiki_content(self):
def test_track_wiki_content(self) -> None:
# Arrange
track = pylast.Track("Test Artist", "test title", self.network)
@ -97,7 +97,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert wiki is not None
assert len(wiki) >= 1
def test_track_wiki_summary(self):
def test_track_wiki_summary(self) -> None:
# Arrange
track = pylast.Track("Test Artist", "test title", self.network)
@ -108,7 +108,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert wiki is not None
assert len(wiki) >= 1
def test_track_get_duration(self):
def test_track_get_duration(self) -> None:
# Arrange
track = pylast.Track("Cher", "Believe", self.network)
@ -118,7 +118,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert duration >= 200000
def test_track_get_album(self):
def test_track_get_album(self) -> None:
# Arrange
track = pylast.Track("Nirvana", "Lithium", self.network)
@ -128,7 +128,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert str(album) == "Nirvana - Nevermind"
def test_track_get_similar(self):
def test_track_get_similar(self) -> None:
# Arrange
track = pylast.Track("Cher", "Believe", self.network)
@ -143,7 +143,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
break
assert found
def test_track_get_similar_limits(self):
def test_track_get_similar_limits(self) -> None:
# Arrange
track = pylast.Track("Cher", "Believe", self.network)
@ -153,7 +153,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert len(track.get_similar(limit=None)) >= 23
assert len(track.get_similar(limit=0)) >= 23
def test_tracks_notequal(self):
def test_tracks_notequal(self) -> None:
# Arrange
track1 = pylast.Track("Test Artist", "test title", self.network)
track2 = pylast.Track("Test Artist", "Test Track", self.network)
@ -162,7 +162,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert track1 != track2
def test_track_title_prop_caps(self):
def test_track_title_prop_caps(self) -> None:
# Arrange
track = pylast.Track("test artist", "test title", self.network)
@ -172,7 +172,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert title == "Test Title"
def test_track_listener_count(self):
def test_track_listener_count(self) -> None:
# Arrange
track = pylast.Track("test artist", "test title", self.network)
@ -182,7 +182,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert count > 21
def test_album_tracks(self):
def test_album_tracks(self) -> None:
# Arrange
album = pylast.Album("Test Artist", "Test", self.network)
@ -196,7 +196,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
assert len(tracks) == 1
assert url.startswith("https://www.last.fm/music/test")
def test_track_eq_none_is_false(self):
def test_track_eq_none_is_false(self) -> None:
# Arrange
track1 = None
track2 = pylast.Track("Test Artist", "test title", self.network)
@ -204,7 +204,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Act / Assert
assert track1 != track2
def test_track_ne_none_is_true(self):
def test_track_ne_none_is_true(self) -> None:
# Arrange
track1 = None
track2 = pylast.Track("Test Artist", "test title", self.network)
@ -212,7 +212,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Act / Assert
assert track1 != track2
def test_track_get_correction(self):
def test_track_get_correction(self) -> None:
# Arrange
track = pylast.Track("Guns N' Roses", "mrbrownstone", self.network)
@ -222,7 +222,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
# Assert
assert corrected_track_name == "Mr. Brownstone"
def test_track_with_no_mbid(self):
def test_track_with_no_mbid(self) -> None:
# Arrange
track = pylast.Track("Static-X", "Set It Off", self.network)

View file

@ -16,7 +16,7 @@ from .test_pylast import TestPyLastWithLastFm
class TestPyLastUser(TestPyLastWithLastFm):
def test_repr(self):
def test_repr(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -26,7 +26,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.assert_startswith(representation, "pylast.User('RJ',")
def test_str(self):
def test_str(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -36,7 +36,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert string == "RJ"
def test_equality(self):
def test_equality(self) -> None:
# Arrange
user_1a = self.network.get_user("RJ")
user_1b = self.network.get_user("RJ")
@ -48,7 +48,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert user_1a != user_2
assert user_1a != not_a_user
def test_get_name(self):
def test_get_name(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -58,7 +58,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert name == "RJ"
def test_get_user_registration(self):
def test_get_user_registration(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -74,7 +74,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Just check date because of timezones
assert "2002-11-20 " in registered
def test_get_user_unixtime_registration(self):
def test_get_user_unixtime_registration(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -85,7 +85,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Just check date because of timezones
assert unixtime_registered == 1037793040
def test_get_countryless_user(self):
def test_get_countryless_user(self) -> None:
# Arrange
# Currently test_user has no country set:
lastfm_user = self.network.get_user("test_user")
@ -96,7 +96,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert country is None
def test_user_get_country(self):
def test_user_get_country(self) -> None:
# Arrange
lastfm_user = self.network.get_user("RJ")
@ -106,7 +106,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert str(country) == "United Kingdom"
def test_user_equals_none(self):
def test_user_equals_none(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
@ -116,7 +116,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert not value
def test_user_not_equal_to_none(self):
def test_user_not_equal_to_none(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
@ -126,7 +126,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert value
def test_now_playing_user_with_no_scrobbles(self):
def test_now_playing_user_with_no_scrobbles(self) -> None:
# Arrange
# Currently test-account has no scrobbles:
user = self.network.get_user("test-account")
@ -137,7 +137,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert current_track is None
def test_love_limits(self):
def test_love_limits(self) -> None:
# Arrange
# Currently test-account has at least 23 loved tracks:
user = self.network.get_user("test-user")
@ -148,7 +148,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert len(user.get_loved_tracks(limit=None)) >= 23
assert len(user.get_loved_tracks(limit=0)) >= 23
def test_user_is_hashable(self):
def test_user_is_hashable(self) -> None:
# Arrange
user = self.network.get_user(self.username)
@ -169,7 +169,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# # Assert
# self.assertGreaterEqual(len(tracks), 0)
def test_pickle(self):
def test_pickle(self) -> None:
# Arrange
import pickle
@ -187,7 +187,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert lastfm_user == loaded_user
@pytest.mark.xfail
def test_cacheable_user(self):
def test_cacheable_user(self) -> None:
# Arrange
lastfm_user = self.network.get_authenticated_user()
@ -201,7 +201,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
lastfm_user, "get_recent_tracks"
)
def test_user_get_top_tags_with_limit(self):
def test_user_get_top_tags_with_limit(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -211,7 +211,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
def test_user_top_tracks(self):
def test_user_top_tracks(self) -> None:
# Arrange
lastfm_user = self.network.get_user("RJ")
@ -221,14 +221,14 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.helper_two_different_things_in_top_list(things, pylast.Track)
def helper_assert_chart(self, chart, expected_type):
def helper_assert_chart(self, chart, expected_type) -> None:
# Assert
assert chart is not None
assert len(chart) > 0
assert isinstance(chart[0], pylast.TopItem)
assert isinstance(chart[0].item, expected_type)
def helper_get_assert_charts(self, thing, date):
def helper_get_assert_charts(self, thing, date) -> None:
# Arrange
album_chart, track_chart = None, None
(from_date, to_date) = date
@ -245,14 +245,14 @@ class TestPyLastUser(TestPyLastWithLastFm):
self.helper_assert_chart(album_chart, pylast.Album)
self.helper_assert_chart(track_chart, pylast.Track)
def helper_dates_valid(self, dates):
def helper_dates_valid(self, dates) -> None:
# Assert
assert len(dates) >= 1
assert isinstance(dates[0], tuple)
(start, end) = dates[0]
assert start < end
def test_user_charts(self):
def test_user_charts(self) -> None:
# Arrange
lastfm_user = self.network.get_user("RJ")
dates = lastfm_user.get_weekly_chart_dates()
@ -261,7 +261,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Act/Assert
self.helper_get_assert_charts(lastfm_user, dates[0])
def test_user_top_artists(self):
def test_user_top_artists(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
@ -271,7 +271,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
def test_user_top_albums(self):
def test_user_top_albums(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -285,7 +285,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert len(top_album.info["image"])
assert re.search(r"^http.+$", top_album.info["image"][pylast.SIZE_LARGE])
def test_user_tagged_artists(self):
def test_user_tagged_artists(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
tags = ["artisttagola"]
@ -298,7 +298,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_list(artists, pylast.Artist)
def test_user_tagged_albums(self):
def test_user_tagged_albums(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
tags = ["albumtagola"]
@ -311,7 +311,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_list(albums, pylast.Album)
def test_user_tagged_tracks(self):
def test_user_tagged_tracks(self) -> None:
# Arrange
lastfm_user = self.network.get_user(self.username)
tags = ["tracktagola"]
@ -324,7 +324,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.helper_only_one_thing_in_list(tracks, pylast.Track)
def test_user_subscriber(self):
def test_user_subscriber(self) -> None:
# Arrange
subscriber = self.network.get_user("RJ")
non_subscriber = self.network.get_user("Test User")
@ -337,7 +337,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert subscriber_is_subscriber
assert not non_subscriber_is_subscriber
def test_user_get_image(self):
def test_user_get_image(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -347,7 +347,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
self.assert_startswith(url, "https://")
def test_user_get_library(self):
def test_user_get_library(self) -> None:
# Arrange
user = self.network.get_user(self.username)
@ -357,7 +357,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert isinstance(library, pylast.Library)
def test_get_recent_tracks_from_to(self):
def test_get_recent_tracks_from_to(self) -> None:
# Arrange
lastfm_user = self.network.get_user("RJ")
start = dt.datetime(2011, 7, 21, 15, 10)
@ -374,7 +374,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert str(tracks[0].track.artist) == "Johnny Cash"
assert str(tracks[0].track.title) == "Ring of Fire"
def test_get_recent_tracks_limit_none(self):
def test_get_recent_tracks_limit_none(self) -> None:
# Arrange
lastfm_user = self.network.get_user("bbc6music")
start = dt.datetime(2020, 2, 15, 15, 00)
@ -393,7 +393,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert str(tracks[0].track.artist) == "Seun Kuti & Egypt 80"
assert str(tracks[0].track.title) == "Struggles Sounds"
def test_get_recent_tracks_is_streamable(self):
def test_get_recent_tracks_is_streamable(self) -> None:
# Arrange
lastfm_user = self.network.get_user("bbc6music")
start = dt.datetime(2020, 2, 15, 15, 00)
@ -410,7 +410,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert inspect.isgenerator(tracks)
def test_get_playcount(self):
def test_get_playcount(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -420,7 +420,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert playcount >= 128387
def test_get_image(self):
def test_get_image(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -431,7 +431,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
self.assert_startswith(image, "https://")
self.assert_endswith(image, ".png")
def test_get_url(self):
def test_get_url(self) -> None:
# Arrange
user = self.network.get_user("RJ")
@ -441,7 +441,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Assert
assert url == "https://www.last.fm/user/rj"
def test_get_weekly_artist_charts(self):
def test_get_weekly_artist_charts(self) -> None:
# Arrange
user = self.network.get_user("bbc6music")
@ -453,7 +453,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert artist is not None
assert isinstance(artist.network, pylast.LastFMNetwork)
def test_get_weekly_track_charts(self):
def test_get_weekly_track_charts(self) -> None:
# Arrange
user = self.network.get_user("bbc6music")
@ -465,7 +465,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert track is not None
assert isinstance(track.network, pylast.LastFMNetwork)
def test_user_get_track_scrobbles(self):
def test_user_get_track_scrobbles(self) -> None:
# Arrange
artist = "France Gall"
title = "Laisse Tomber Les Filles"
@ -479,7 +479,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
assert str(scrobbles[0].track.artist) == "France Gall"
assert scrobbles[0].track.title == "Laisse Tomber Les Filles"
def test_cacheable_user_get_track_scrobbles(self):
def test_cacheable_user_get_track_scrobbles(self) -> None:
# Arrange
artist = "France Gall"
title = "Laisse Tomber Les Filles"

View file

@ -18,13 +18,13 @@ def mock_network():
"fdasfdsafsaf not unicode",
],
)
def test_get_cache_key(artist):
def test_get_cache_key(artist) -> None:
request = pylast._Request(mock_network(), "some_method", params={"artist": artist})
request._get_cache_key()
@pytest.mark.parametrize("obj", [pylast.Artist("B\xe9l", mock_network())])
def test_cast_and_hash(obj):
def test_cast_and_hash(obj) -> None:
assert type(str(obj)) is str
assert isinstance(hash(obj), int)