Refactor: replace redundant helper methods, no need with pytest

This commit is contained in:
Hugo van Kemenade 2023-06-03 18:03:05 +03:00
parent 1c669d8bb0
commit 7da76f49bd
5 changed files with 22 additions and 30 deletions

View file

@ -16,7 +16,7 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
representation = repr(library)
# Assert
self.assert_startswith(representation, "pylast.Library(")
assert representation.startswith("pylast.Library(")
def test_str(self) -> None:
# Arrange
@ -26,7 +26,7 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
string = str(library)
# Assert
self.assert_endswith(string, "'s Library")
assert string.endswith("'s Library")
def test_library_is_hashable(self) -> None:
# Arrange

View file

@ -6,11 +6,11 @@ from flaky import flaky
import pylast
from .test_pylast import PyLastTestCase, load_secrets
from .test_pylast import load_secrets
@flaky(max_runs=3, min_passes=1)
class TestPyLastWithLibreFm(PyLastTestCase):
class TestPyLastWithLibreFm:
"""Own class for Libre.fm because we don't need the Last.fm setUp"""
def test_libre_fm(self) -> None:
@ -38,4 +38,4 @@ class TestPyLastWithLibreFm(PyLastTestCase):
representation = repr(network)
# Assert
self.assert_startswith(representation, "pylast.LibreFMNetwork(")
assert representation.startswith("pylast.LibreFMNetwork(")

View file

@ -330,12 +330,12 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
assert len(images) == 4
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
assert images[pylast.SIZE_SMALL].startswith("https://")
assert images[pylast.SIZE_SMALL].endswith(".png")
assert "/34s/" in images[pylast.SIZE_SMALL]
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
assert images[pylast.SIZE_EXTRA_LARGE].startswith("https://")
assert images[pylast.SIZE_EXTRA_LARGE].endswith(".png")
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
def test_artist_search(self) -> None:
@ -362,12 +362,12 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
assert len(images) == 5
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
assert images[pylast.SIZE_SMALL].startswith("https://")
assert images[pylast.SIZE_SMALL].endswith(".png")
assert "/34s/" in images[pylast.SIZE_SMALL]
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
assert images[pylast.SIZE_EXTRA_LARGE].startswith("https://")
assert images[pylast.SIZE_EXTRA_LARGE].endswith(".png")
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
def test_track_search(self) -> None:
@ -396,12 +396,12 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert
assert len(images) == 4
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
assert images[pylast.SIZE_SMALL].startswith("https://")
assert images[pylast.SIZE_SMALL].endswith(".png")
assert "/34s/" in images[pylast.SIZE_SMALL]
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
assert images[pylast.SIZE_EXTRA_LARGE].startswith("https://")
assert images[pylast.SIZE_EXTRA_LARGE].endswith(".png")
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
def test_search_get_total_result_count(self) -> None:

View file

@ -32,21 +32,13 @@ def load_secrets(): # pragma: no cover
return doc
class PyLastTestCase:
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) -> None:
assert s.endswith(suffix, start, end)
def _no_xfail_rerun_filter(err, name, test, plugin) -> bool:
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):
class TestPyLastWithLastFm:
secrets = None
def unix_timestamp(self):

View file

@ -24,7 +24,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
representation = repr(user)
# Assert
self.assert_startswith(representation, "pylast.User('RJ',")
assert representation.startswith("pylast.User('RJ',")
def test_str(self) -> None:
# Arrange
@ -345,7 +345,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
url = user.get_image()
# Assert
self.assert_startswith(url, "https://")
assert url.startswith("https://")
def test_user_get_library(self) -> None:
# Arrange
@ -428,8 +428,8 @@ class TestPyLastUser(TestPyLastWithLastFm):
image = user.get_image()
# Assert
self.assert_startswith(image, "https://")
self.assert_endswith(image, ".png")
assert image.startswith("https://")
assert image.endswith(".png")
def test_get_url(self) -> None:
# Arrange