Format with Black 18.6b1
This commit is contained in:
parent
e5a5278d51
commit
da9465c100
File diff suppressed because it is too large
Load diff
19
setup.py
19
setup.py
|
@ -10,9 +10,16 @@ setup(
|
|||
long_description_content_type="text/markdown",
|
||||
version="2.3.0.dev0",
|
||||
author="Amr Hassan <amr.hassan@gmail.com> and Contributors",
|
||||
install_requires=['six'],
|
||||
tests_require=['mock', 'pytest', 'coverage', 'pycodestyle', 'pyyaml',
|
||||
'pyflakes', 'flaky'],
|
||||
install_requires=["six"],
|
||||
tests_require=[
|
||||
"mock",
|
||||
"pytest",
|
||||
"coverage",
|
||||
"pycodestyle",
|
||||
"pyyaml",
|
||||
"pyflakes",
|
||||
"flaky",
|
||||
],
|
||||
description="A Python interface to Last.fm and Libre.fm",
|
||||
author_email="amr.hassan@gmail.com",
|
||||
url="https://github.com/pylast/pylast",
|
||||
|
@ -32,10 +39,10 @@ setup(
|
|||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
],
|
||||
python_requires='>=2.7.10, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
|
||||
python_requires=">=2.7.10, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
|
||||
keywords=["Last.fm", "music", "scrobble", "scrobbling"],
|
||||
packages=find_packages(exclude=('tests*',)),
|
||||
license="Apache2"
|
||||
packages=find_packages(exclude=("tests*",)),
|
||||
license="Apache2",
|
||||
)
|
||||
|
||||
# End of file
|
||||
|
|
|
@ -10,10 +10,9 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||
|
||||
def test_album_tags_are_topitems(self):
|
||||
# Arrange
|
||||
albums = self.network.get_user('RJ').get_top_albums()
|
||||
albums = self.network.get_user("RJ").get_top_albums()
|
||||
|
||||
# Act
|
||||
tags = albums[0].item.get_top_tags(limit=1)
|
||||
|
@ -38,7 +37,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
|||
track = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
|
||||
# Assert
|
||||
self.assertTrue(hasattr(track, 'album'))
|
||||
self.assertTrue(hasattr(track, "album"))
|
||||
|
||||
def test_album_in_artist_tracks(self):
|
||||
# Arrange
|
||||
|
@ -48,7 +47,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
|||
track = lastfm_user.get_artist_tracks(artist="Test Artist")[0]
|
||||
|
||||
# Assert
|
||||
self.assertTrue(hasattr(track, 'album'))
|
||||
self.assertTrue(hasattr(track, "album"))
|
||||
|
||||
def test_album_wiki_content(self):
|
||||
# Arrange
|
||||
|
@ -111,5 +110,5 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
|||
self.assert_endswith(image, ".png")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -10,7 +10,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastArtist(TestPyLastWithLastFm):
|
||||
|
||||
def test_repr(self):
|
||||
# Arrange
|
||||
artist = pylast.Artist("Test Artist", self.network)
|
||||
|
@ -19,8 +18,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
representation = repr(artist)
|
||||
|
||||
# Assert
|
||||
self.assertTrue(
|
||||
representation.startswith("pylast.Artist('Test Artist',"))
|
||||
self.assertTrue(representation.startswith("pylast.Artist('Test Artist',"))
|
||||
|
||||
def test_artist_is_hashable(self):
|
||||
# Arrange
|
||||
|
@ -136,7 +134,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
def test_tag_artist(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
# artist.clear_tags()
|
||||
# artist.clear_tags()
|
||||
|
||||
# Act
|
||||
artist.add_tag("testing")
|
||||
|
@ -285,8 +283,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
|
||||
def test_get_userplaycount(self):
|
||||
# Arrange
|
||||
artist = pylast.Artist("John Lennon", self.network,
|
||||
username=self.username)
|
||||
artist = pylast.Artist("John Lennon", self.network, username=self.username)
|
||||
|
||||
# Act
|
||||
playcount = artist.get_userplaycount()
|
||||
|
@ -295,5 +292,5 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
self.assertGreaterEqual(playcount, 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -10,7 +10,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastCountry(TestPyLastWithLastFm):
|
||||
|
||||
def test_country_is_hashable(self):
|
||||
# Arrange
|
||||
country = self.network.get_country("Italy")
|
||||
|
@ -37,5 +36,5 @@ class TestPyLastCountry(TestPyLastWithLastFm):
|
|||
self.assertEqual(url, "https://www.last.fm/place/italy")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -10,7 +10,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastLibrary(TestPyLastWithLastFm):
|
||||
|
||||
def test_repr(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
@ -57,5 +56,5 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
|
|||
self.assertEqual(library_user, user_to_get)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -22,8 +22,7 @@ class TestPyLastWithLibreFm(PyLastTestCase):
|
|||
password_hash = secrets["password_hash"]
|
||||
|
||||
# Act
|
||||
network = pylast.LibreFMNetwork(
|
||||
password_hash=password_hash, username=username)
|
||||
network = pylast.LibreFMNetwork(password_hash=password_hash, username=username)
|
||||
artist = network.get_artist("Radiohead")
|
||||
name = artist.get_name()
|
||||
|
||||
|
@ -35,8 +34,7 @@ class TestPyLastWithLibreFm(PyLastTestCase):
|
|||
secrets = load_secrets()
|
||||
username = secrets["username"]
|
||||
password_hash = secrets["password_hash"]
|
||||
network = pylast.LibreFMNetwork(
|
||||
password_hash=password_hash, username=username)
|
||||
network = pylast.LibreFMNetwork(password_hash=password_hash, username=username)
|
||||
|
||||
# Act
|
||||
representation = repr(network)
|
||||
|
@ -45,5 +43,5 @@ class TestPyLastWithLibreFm(PyLastTestCase):
|
|||
self.assert_startswith(representation, "pylast.LibreFMNetwork(")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -11,7 +11,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||
|
||||
def test_scrobble(self):
|
||||
# Arrange
|
||||
artist = "test artist"
|
||||
|
@ -39,7 +38,8 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
|
||||
# Act
|
||||
self.network.update_now_playing(
|
||||
artist=artist, title=title, album=album, track_number=track_number)
|
||||
artist=artist, title=title, album=album, track_number=track_number
|
||||
)
|
||||
|
||||
# Assert
|
||||
current_track = lastfm_user.get_now_playing()
|
||||
|
@ -89,8 +89,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
def test_geo_get_top_artists(self):
|
||||
# Arrange
|
||||
# Act
|
||||
artists = self.network.get_geo_top_artists(
|
||||
country="United Kingdom", limit=1)
|
||||
artists = self.network.get_geo_top_artists(country="United Kingdom", limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(artists), 1)
|
||||
|
@ -101,7 +100,8 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
# Arrange
|
||||
# Act
|
||||
tracks = self.network.get_geo_top_tracks(
|
||||
country="United Kingdom", location="Manchester", limit=1)
|
||||
country="United Kingdom", location="Manchester", limit=1
|
||||
)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(tracks), 1)
|
||||
|
@ -186,8 +186,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
self.assertEqual(title, name)
|
||||
self.assertIsInstance(playcount, int)
|
||||
self.assertGreater(playcount, 1)
|
||||
self.assertEqual(
|
||||
"https://www.last.fm/music/test%2bartist/test%2balbum", url)
|
||||
self.assertEqual("https://www.last.fm/music/test%2bartist/test%2balbum", url)
|
||||
|
||||
def test_track_data(self):
|
||||
# Arrange
|
||||
|
@ -209,7 +208,8 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
self.assertIsInstance(playcount, int)
|
||||
self.assertGreater(playcount, 1)
|
||||
self.assertEqual(
|
||||
"https://www.last.fm/fr/music/test%2bartist/_/test%2btitle", url)
|
||||
"https://www.last.fm/fr/music/test%2bartist/_/test%2btitle", url
|
||||
)
|
||||
|
||||
def test_country_top_artists(self):
|
||||
# Arrange
|
||||
|
@ -286,8 +286,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
msg = str(exc)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(msg,
|
||||
"Unauthorized Token - This token has not been issued")
|
||||
self.assertEqual(msg, "Unauthorized Token - This token has not been issued")
|
||||
|
||||
def test_proxy(self):
|
||||
# Arrange
|
||||
|
@ -297,8 +296,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
# Act / Assert
|
||||
self.network.enable_proxy(host, port)
|
||||
self.assertTrue(self.network.is_proxy_enabled())
|
||||
self.assertEqual(self.network._get_proxy(),
|
||||
["https://example.com", 1234])
|
||||
self.assertEqual(self.network._get_proxy(), ["https://example.com", 1234])
|
||||
|
||||
self.network.disable_proxy()
|
||||
self.assertFalse(self.network.is_proxy_enabled())
|
||||
|
@ -414,5 +412,5 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
self.assertGreater(int(total), 10000)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -16,22 +16,22 @@ def load_secrets():
|
|||
secrets_file = "test_pylast.yaml"
|
||||
if os.path.isfile(secrets_file):
|
||||
import yaml # pip install pyyaml
|
||||
|
||||
with open(secrets_file, "r") as f: # see example_test_pylast.yaml
|
||||
doc = yaml.load(f)
|
||||
else:
|
||||
doc = {}
|
||||
try:
|
||||
doc["username"] = os.environ['PYLAST_USERNAME'].strip()
|
||||
doc["password_hash"] = os.environ['PYLAST_PASSWORD_HASH'].strip()
|
||||
doc["api_key"] = os.environ['PYLAST_API_KEY'].strip()
|
||||
doc["api_secret"] = os.environ['PYLAST_API_SECRET'].strip()
|
||||
doc["username"] = os.environ["PYLAST_USERNAME"].strip()
|
||||
doc["password_hash"] = os.environ["PYLAST_PASSWORD_HASH"].strip()
|
||||
doc["api_key"] = os.environ["PYLAST_API_KEY"].strip()
|
||||
doc["api_secret"] = os.environ["PYLAST_API_SECRET"].strip()
|
||||
except KeyError:
|
||||
pytest.skip("Missing environment variables: PYLAST_USERNAME etc.")
|
||||
return doc
|
||||
|
||||
|
||||
class PyLastTestCase(unittest.TestCase):
|
||||
|
||||
def assert_startswith(self, str, prefix, start=None, end=None):
|
||||
self.assertTrue(str.startswith(prefix, start, end))
|
||||
|
||||
|
@ -58,8 +58,11 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
api_secret = self.__class__.secrets["api_secret"]
|
||||
|
||||
self.network = pylast.LastFMNetwork(
|
||||
api_key=api_key, api_secret=api_secret,
|
||||
username=self.username, password_hash=password_hash)
|
||||
api_key=api_key,
|
||||
api_secret=api_secret,
|
||||
username=self.username,
|
||||
password_hash=password_hash,
|
||||
)
|
||||
|
||||
def helper_is_thing_hashable(self, thing):
|
||||
# Arrange
|
||||
|
@ -128,5 +131,5 @@ class TestPyLastWithLastFm(PyLastTestCase):
|
|||
self.assertNotEqual(thing1, thing2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -10,7 +10,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastTag(TestPyLastWithLastFm):
|
||||
|
||||
def test_tag_is_hashable(self):
|
||||
# Arrange
|
||||
tag = self.network.get_top_tags(limit=1)[0]
|
||||
|
@ -59,5 +58,5 @@ class TestPyLastTag(TestPyLastWithLastFm):
|
|||
self.assertEqual(url, "https://www.last.fm/tag/blues")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -10,7 +10,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastTrack(TestPyLastWithLastFm):
|
||||
|
||||
def test_love(self):
|
||||
# Arrange
|
||||
artist = "Test Artist"
|
||||
|
@ -48,8 +47,8 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
|||
artist = "Test Artist"
|
||||
title = "test title"
|
||||
track = pylast.Track(
|
||||
artist=artist, title=title,
|
||||
network=self.network, username=self.username)
|
||||
artist=artist, title=title, network=self.network, username=self.username
|
||||
)
|
||||
|
||||
# Act
|
||||
count = track.get_userplaycount()
|
||||
|
@ -62,8 +61,8 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
|||
artist = "Test Artist"
|
||||
title = "test title"
|
||||
track = pylast.Track(
|
||||
artist=artist, title=title,
|
||||
network=self.network, username=self.username)
|
||||
artist=artist, title=title, network=self.network, username=self.username
|
||||
)
|
||||
|
||||
# Act
|
||||
loved = track.get_userloved()
|
||||
|
@ -249,5 +248,5 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
|||
self.assertIsNone(mbid)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -11,7 +11,6 @@ from .test_pylast import TestPyLastWithLastFm
|
|||
|
||||
|
||||
class TestPyLastUser(TestPyLastWithLastFm):
|
||||
|
||||
def test_repr(self):
|
||||
# Arrange
|
||||
user = self.network.get_user("RJ")
|
||||
|
@ -107,7 +106,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
value = (lastfm_user is None)
|
||||
value = lastfm_user is None
|
||||
|
||||
# Assert
|
||||
self.assertFalse(value)
|
||||
|
@ -117,7 +116,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
value = (lastfm_user is not None)
|
||||
value = lastfm_user is not None
|
||||
|
||||
# Assert
|
||||
self.assertTrue(value)
|
||||
|
@ -125,7 +124,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
def test_now_playing_user_with_no_scrobbles(self):
|
||||
# Arrange
|
||||
# Currently test-account has no scrobbles:
|
||||
user = self.network.get_user('test-account')
|
||||
user = self.network.get_user("test-account")
|
||||
|
||||
# Act
|
||||
current_track = user.get_now_playing()
|
||||
|
@ -155,19 +154,20 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
# fails due Last.fm's complaining of hitting the rate limit, even when
|
||||
# limited to one call per second. The ToS allows 5 calls per second.
|
||||
# def test_get_all_scrobbles(self):
|
||||
# # Arrange
|
||||
# lastfm_user = self.network.get_user("RJ")
|
||||
# self.network.enable_rate_limit() # this is going to be slow...
|
||||
# # Arrange
|
||||
# lastfm_user = self.network.get_user("RJ")
|
||||
# self.network.enable_rate_limit() # this is going to be slow...
|
||||
|
||||
# # Act
|
||||
# tracks = lastfm_user.get_recent_tracks(limit=None)
|
||||
# # Act
|
||||
# tracks = lastfm_user.get_recent_tracks(limit=None)
|
||||
|
||||
# # Assert
|
||||
# self.assertGreaterEqual(len(tracks), 0)
|
||||
# # Assert
|
||||
# self.assertGreaterEqual(len(tracks), 0)
|
||||
|
||||
def test_pickle(self):
|
||||
# Arrange
|
||||
import pickle
|
||||
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
filename = str(self.unix_timestamp()) + ".pkl"
|
||||
|
||||
|
@ -290,7 +290,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
artist.add_tags(tags)
|
||||
|
||||
# Act
|
||||
artists = lastfm_user.get_tagged_artists('artisttagola', limit=1)
|
||||
artists = lastfm_user.get_tagged_artists("artisttagola", limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_list(artists, pylast.Artist)
|
||||
|
@ -303,7 +303,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
album.add_tags(tags)
|
||||
|
||||
# Act
|
||||
albums = lastfm_user.get_tagged_albums('albumtagola', limit=1)
|
||||
albums = lastfm_user.get_tagged_albums("albumtagola", limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_list(albums, pylast.Album)
|
||||
|
@ -316,7 +316,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
track.add_tags(tags)
|
||||
|
||||
# Act
|
||||
tracks = lastfm_user.get_tagged_tracks('tracktagola', limit=1)
|
||||
tracks = lastfm_user.get_tagged_tracks("tracktagola", limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_list(tracks, pylast.Track)
|
||||
|
@ -359,15 +359,16 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
lastfm_user = self.network.get_user("RJ")
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
start = datetime(2011, 7, 21, 15, 10)
|
||||
end = datetime(2011, 7, 21, 15, 15)
|
||||
import calendar
|
||||
|
||||
utc_start = calendar.timegm(start.utctimetuple())
|
||||
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)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(tracks), 1)
|
||||
|
@ -430,5 +431,5 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
self.assertIsInstance(track.network, pylast.LastFMNetwork)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main(failfast=True)
|
||||
|
|
|
@ -7,23 +7,24 @@ import pylast
|
|||
|
||||
|
||||
def mock_network():
|
||||
return mock.Mock(
|
||||
_get_ws_auth=mock.Mock(return_value=("", "", ""))
|
||||
)
|
||||
return mock.Mock(_get_ws_auth=mock.Mock(return_value=("", "", "")))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('artist', [
|
||||
u'\xe9lafdasfdsafdsa', u'ééééééé',
|
||||
pylast.Artist(u'B\xe9l', mock_network()),
|
||||
'fdasfdsafsaf not unicode',
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"artist",
|
||||
[
|
||||
u"\xe9lafdasfdsafdsa",
|
||||
u"ééééééé",
|
||||
pylast.Artist(u"B\xe9l", mock_network()),
|
||||
"fdasfdsafsaf not unicode",
|
||||
],
|
||||
)
|
||||
def test_get_cache_key(artist):
|
||||
request = pylast._Request(mock_network(), 'some_method',
|
||||
params={'artist': artist})
|
||||
request = pylast._Request(mock_network(), "some_method", params={"artist": artist})
|
||||
request._get_cache_key()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('obj', [pylast.Artist(u'B\xe9l', mock_network())])
|
||||
@pytest.mark.parametrize("obj", [pylast.Artist(u"B\xe9l", mock_network())])
|
||||
def test_cast_and_hash(obj):
|
||||
assert type(six.text_type(obj)) is six.text_type
|
||||
assert isinstance(hash(obj), int)
|
||||
|
|
Loading…
Reference in a new issue