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