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

View file

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

View file

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

View file

@ -32,21 +32,13 @@ def load_secrets(): # pragma: no cover
return doc 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: def _no_xfail_rerun_filter(err, name, test, plugin) -> bool:
for _ in test.iter_markers(name="xfail"): for _ in test.iter_markers(name="xfail"):
return False return False
@flaky(max_runs=3, min_passes=1, rerun_filter=_no_xfail_rerun_filter) @flaky(max_runs=3, min_passes=1, rerun_filter=_no_xfail_rerun_filter)
class TestPyLastWithLastFm(PyLastTestCase): class TestPyLastWithLastFm:
secrets = None secrets = None
def unix_timestamp(self): def unix_timestamp(self):

View file

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