Merge remote-tracking branch 'upstream/master' into streaming
This commit is contained in:
commit
10107a04e4
23 changed files with 333 additions and 359 deletions
|
@ -2,9 +2,10 @@
|
|||
"""
|
||||
Integration (not unit) tests for pylast.py
|
||||
"""
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
|
||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
@ -94,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 = list(artist.get_top_albums(limit=limit))
|
||||
|
||||
# Assert
|
||||
assert len(things) == 100
|
||||
|
||||
def test_artist_listener_count(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
|
@ -153,11 +141,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
# Assert
|
||||
tags = artist.get_tags()
|
||||
assert len(tags) > 0
|
||||
found = False
|
||||
for tag in tags:
|
||||
if tag.name == "testing":
|
||||
found = True
|
||||
break
|
||||
found = any(tag.name == "testing" for tag in tags)
|
||||
assert found
|
||||
|
||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||
|
@ -172,11 +156,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
tags = artist.get_tags()
|
||||
found = False
|
||||
for tag in tags:
|
||||
if tag.name == "testing":
|
||||
found = True
|
||||
break
|
||||
found = any(tag.name == "testing" for tag in tags)
|
||||
assert not found
|
||||
|
||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||
|
@ -191,11 +171,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
tags = artist.get_tags()
|
||||
found = False
|
||||
for tag in tags:
|
||||
if tag.name == "testing":
|
||||
found = True
|
||||
break
|
||||
found = any(tag.name == "testing" for tag in tags)
|
||||
assert not found
|
||||
|
||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||
|
@ -213,12 +189,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
# Assert
|
||||
tags_after = artist.get_tags()
|
||||
assert len(tags_after) == len(tags_before) - 2
|
||||
found1, found2 = False, False
|
||||
for tag in tags_after:
|
||||
if tag.name == "removetag1":
|
||||
found1 = True
|
||||
elif tag.name == "removetag2":
|
||||
found2 = True
|
||||
found1 = any(tag.name == "removetag1" for tag in tags_after)
|
||||
found2 = any(tag.name == "removetag2" for tag in tags_after)
|
||||
assert not found1
|
||||
assert not found2
|
||||
|
||||
|
@ -256,16 +228,12 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
url = artist1.get_url()
|
||||
mbid = artist1.get_mbid()
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
image = artist1.get_cover_image()
|
||||
|
||||
playcount = artist1.get_playcount()
|
||||
streamable = artist1.is_streamable()
|
||||
name = artist1.get_name(properly_capitalized=False)
|
||||
name_cap = artist1.get_name(properly_capitalized=True)
|
||||
|
||||
# Assert
|
||||
assert "https" in image
|
||||
assert playcount > 1
|
||||
assert artist1 != artist2
|
||||
assert name.lower() == name_cap.lower()
|
||||
|
@ -308,4 +276,4 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
|||
playcount = artist.get_userplaycount()
|
||||
|
||||
# Assert
|
||||
assert playcount >= 0
|
||||
assert playcount >= 0 # whilst xfail: # pragma: no cover
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
"""
|
||||
Integration (not unit) tests for pylast.py
|
||||
"""
|
||||
import pylast
|
||||
from flaky import flaky
|
||||
|
||||
import pylast
|
||||
|
||||
from .test_pylast import PyLastTestCase, load_secrets
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,10 @@ Integration (not unit) tests for pylast.py
|
|||
import re
|
||||
import time
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
|
||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
@ -63,7 +64,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
|||
self.network.enable_rate_limit()
|
||||
then = time.time()
|
||||
# Make some network call, limit not applied first time
|
||||
self.network.get_user(self.username)
|
||||
self.network.get_top_artists()
|
||||
# Make a second network call, limiting should be applied
|
||||
self.network.get_top_artists()
|
||||
now = time.time()
|
||||
|
|
|
@ -6,14 +6,15 @@ import os
|
|||
import sys
|
||||
import time
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
from flaky import flaky
|
||||
|
||||
import pylast
|
||||
|
||||
WRITE_TEST = sys.version_info[:2] == (3, 8)
|
||||
|
||||
|
||||
def load_secrets():
|
||||
def load_secrets(): # pragma: no cover
|
||||
secrets_file = "test_pylast.yaml"
|
||||
if os.path.isfile(secrets_file):
|
||||
import yaml # pip install pyyaml
|
||||
|
@ -33,14 +34,19 @@ def load_secrets():
|
|||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@flaky(max_runs=3, min_passes=1)
|
||||
def _no_xfail_rerun_filter(err, name, test, plugin):
|
||||
for _ in test.iter_markers(name="xfail"):
|
||||
return False
|
||||
|
||||
|
||||
@flaky(max_runs=3, min_passes=1, rerun_filter=_no_xfail_rerun_filter)
|
||||
class TestPyLastWithLastFm(PyLastTestCase):
|
||||
|
||||
secrets = None
|
||||
|
|
|
@ -4,9 +4,10 @@ Integration (not unit) tests for pylast.py
|
|||
"""
|
||||
import time
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
|
||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ import datetime as dt
|
|||
import inspect
|
||||
import os
|
||||
import re
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
from .test_pylast import TestPyLastWithLastFm
|
||||
|
||||
|
@ -69,7 +69,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
if int(registered):
|
||||
# Last.fm API broken? Used to be yyyy-mm-dd not Unix timestamp
|
||||
assert registered == "1037793040"
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
# Old way
|
||||
# Just check date because of timezones
|
||||
assert "2002-11-20 " in registered
|
||||
|
@ -193,8 +193,13 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
|
||||
# Act/Assert
|
||||
self.helper_validate_cacheable(lastfm_user, "get_friends")
|
||||
self.helper_validate_cacheable(lastfm_user, "get_loved_tracks")
|
||||
self.helper_validate_cacheable(lastfm_user, "get_recent_tracks")
|
||||
# no cover whilst xfail:
|
||||
self.helper_validate_cacheable( # pragma: no cover
|
||||
lastfm_user, "get_loved_tracks"
|
||||
)
|
||||
self.helper_validate_cacheable( # pragma: no cover
|
||||
lastfm_user, "get_recent_tracks"
|
||||
)
|
||||
|
||||
def test_user_get_top_tags_with_limit(self):
|
||||
# Arrange
|
||||
|
@ -487,15 +492,3 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
|||
|
||||
# Assert
|
||||
self.helper_validate_results(result1, result2, result3)
|
||||
|
||||
def test_get_artist_tracks_deprecated(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act / Assert
|
||||
with warnings.catch_warnings(), pytest.raises(
|
||||
pylast.WSError,
|
||||
match="Deprecated - This type of request is no longer supported",
|
||||
):
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||
lastfm_user.get_artist_tracks(artist="Test Artist")
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from unittest import mock
|
||||
|
||||
import pylast
|
||||
import pytest
|
||||
|
||||
import pylast
|
||||
|
||||
|
||||
def mock_network():
|
||||
return mock.Mock(_get_ws_auth=mock.Mock(return_value=("", "", "")))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue