Rewrite and add pragmas to improve coverage of non-runnable test code

This commit is contained in:
Hugo 2020-08-22 11:45:33 +03:00
parent 66f5ace917
commit 48f4be0bcf
3 changed files with 15 additions and 26 deletions

View file

@ -153,11 +153,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert # Assert
tags = artist.get_tags() tags = artist.get_tags()
assert len(tags) > 0 assert len(tags) > 0
found = False found = any(tag.name == "testing" for tag in tags)
for tag in tags:
if tag.name == "testing":
found = True
break
assert found assert found
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
@ -172,11 +168,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert # Assert
tags = artist.get_tags() tags = artist.get_tags()
found = False found = any(tag.name == "testing" for tag in tags)
for tag in tags:
if tag.name == "testing":
found = True
break
assert not found assert not found
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
@ -191,11 +183,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert # Assert
tags = artist.get_tags() tags = artist.get_tags()
found = False found = any(tag.name == "testing" for tag in tags)
for tag in tags:
if tag.name == "testing":
found = True
break
assert not found assert not found
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions") @pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
@ -213,12 +201,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
# Assert # Assert
tags_after = artist.get_tags() tags_after = artist.get_tags()
assert len(tags_after) == len(tags_before) - 2 assert len(tags_after) == len(tags_before) - 2
found1, found2 = False, False found1 = any(tag.name == "removetag1" for tag in tags_after)
for tag in tags_after: found2 = any(tag.name == "removetag2" for tag in tags_after)
if tag.name == "removetag1":
found1 = True
elif tag.name == "removetag2":
found2 = True
assert not found1 assert not found1
assert not found2 assert not found2
@ -308,4 +292,4 @@ class TestPyLastArtist(TestPyLastWithLastFm):
playcount = artist.get_userplaycount() playcount = artist.get_userplaycount()
# Assert # Assert
assert playcount >= 0 assert playcount >= 0 # whilst xfail: # pragma: no cover

View file

@ -13,7 +13,7 @@ from flaky import flaky
WRITE_TEST = sys.version_info[:2] == (3, 8) WRITE_TEST = sys.version_info[:2] == (3, 8)
def load_secrets(): def load_secrets(): # pragma: no cover
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

View file

@ -68,7 +68,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
if int(registered): if int(registered):
# Last.fm API broken? Used to be yyyy-mm-dd not Unix timestamp # Last.fm API broken? Used to be yyyy-mm-dd not Unix timestamp
assert registered == "1037793040" assert registered == "1037793040"
else: else: # pragma: no cover
# Old way # Old way
# Just check date because of timezones # Just check date because of timezones
assert "2002-11-20 " in registered assert "2002-11-20 " in registered
@ -192,8 +192,13 @@ class TestPyLastUser(TestPyLastWithLastFm):
# Act/Assert # Act/Assert
self.helper_validate_cacheable(lastfm_user, "get_friends") self.helper_validate_cacheable(lastfm_user, "get_friends")
self.helper_validate_cacheable(lastfm_user, "get_loved_tracks") # no cover whilst xfail:
self.helper_validate_cacheable(lastfm_user, "get_recent_tracks") 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): def test_user_get_top_tags_with_limit(self):
# Arrange # Arrange