mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-29 21:31:23 +00:00
Add tests for encoders
and some refactoring
This commit is contained in:
@@ -6,7 +6,7 @@ from abc import abstractmethod
|
||||
|
||||
class LyricBase(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self, artist, song):
|
||||
def __init__(self, artist, track):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -8,13 +8,13 @@ BASE_URL = "https://genius.com"
|
||||
|
||||
|
||||
class Genius(LyricBase):
|
||||
def __init__(self, artist, song):
|
||||
def __init__(self, artist, track):
|
||||
self.artist = artist
|
||||
self.song = song
|
||||
self.track = track
|
||||
self.base_url = BASE_URL
|
||||
|
||||
def _guess_lyric_url(self):
|
||||
query = "/{} {} lyrics".format(self.artist, self.song)
|
||||
query = "/{} {} lyrics".format(self.artist, self.track)
|
||||
query = query.replace(" ", "-")
|
||||
encoded_query = urllib.request.quote(query)
|
||||
lyric_url = self.base_url + encoded_query
|
||||
@@ -28,7 +28,7 @@ class Genius(LyricBase):
|
||||
except urllib.request.HTTPError:
|
||||
raise LyricsNotFoundError(
|
||||
"Could not find lyrics for {} - {} at URL: {}".format(
|
||||
self.artist, self.song, url
|
||||
self.artist, self.track, url
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -5,13 +5,13 @@ from spotdl.lyrics.exceptions import LyricsNotFoundError
|
||||
|
||||
|
||||
class LyricWikia(LyricBase):
|
||||
def __init__(self, artist, song):
|
||||
def __init__(self, artist, track):
|
||||
self.artist = artist
|
||||
self.song = song
|
||||
self.track = track
|
||||
|
||||
def get_lyrics(self, linesep="\n", timeout=None):
|
||||
try:
|
||||
lyrics = lyricwikia.get_lyrics(self.artist, self.song, linesep, timeout)
|
||||
lyrics = lyricwikia.get_lyrics(self.artist, self.track, linesep, timeout)
|
||||
except lyricwikia.LyricsNotFound as e:
|
||||
raise LyricsNotFoundError(e.args[0])
|
||||
else:
|
||||
|
||||
@@ -12,7 +12,7 @@ class TestGenius:
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def track(self):
|
||||
return Genius("artist", "song")
|
||||
return Genius("artist", "track")
|
||||
|
||||
def test_base_url(self, track):
|
||||
assert track.base_url == "https://genius.com"
|
||||
|
||||
5
spotdl/lyrics/tests/test_exceptions.py
Normal file
5
spotdl/lyrics/tests/test_exceptions.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from spotdl.lyrics.exceptions import LyricsNotFoundError
|
||||
|
||||
def test_lyrics_not_found_subclass():
|
||||
assert issubclass(LyricsNotFoundError, Exception)
|
||||
|
||||
29
spotdl/lyrics/tests/test_lyric_base.py
Normal file
29
spotdl/lyrics/tests/test_lyric_base.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from spotdl.lyrics import LyricBase
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestAbstractBaseClass:
|
||||
def test_error_abstract_base_class_lyricbase(self):
|
||||
artist = "awesome artist"
|
||||
track = "amazing track"
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
# This abstract base class must be inherited from
|
||||
# for instantiation
|
||||
LyricBase(artist, track)
|
||||
|
||||
|
||||
def test_inherit_abstract_base_class_encoderbase(self):
|
||||
class LyricKid(LyricBase):
|
||||
def __init__(self, artist, track):
|
||||
super().__init__(artist, track)
|
||||
|
||||
def get_lyrics(self):
|
||||
pass
|
||||
|
||||
|
||||
artist = "awesome artist"
|
||||
track = "amazing track"
|
||||
|
||||
LyricKid(artist, track)
|
||||
Reference in New Issue
Block a user