mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-29 21:31:23 +00:00
Scrape lyrics from Genius and lyrics refactor
This commit is contained in:
0
spotdl/lyrics/providers/tests/__init__.py
Normal file
0
spotdl/lyrics/providers/tests/__init__.py
Normal file
39
spotdl/lyrics/providers/tests/test_genius.py
Normal file
39
spotdl/lyrics/providers/tests/test_genius.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from spotdl.lyrics import LyricBase
|
||||
from spotdl.lyrics import exceptions
|
||||
from spotdl.lyrics.providers import Genius
|
||||
|
||||
import urllib.request
|
||||
import pytest
|
||||
|
||||
|
||||
class TestGenius:
|
||||
def test_subclass(self):
|
||||
assert issubclass(Genius, LyricBase)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def track(self):
|
||||
return Genius("artist", "song")
|
||||
|
||||
def test_base_url(self, track):
|
||||
assert track.base_url == "https://genius.com"
|
||||
|
||||
def test_get_lyrics(self, track, monkeypatch):
|
||||
|
||||
def mocked_urlopen(url, timeout=None):
|
||||
class DummyHTTPResponse:
|
||||
def read(self):
|
||||
return "<p>amazing lyrics!</p>"
|
||||
|
||||
return DummyHTTPResponse()
|
||||
|
||||
monkeypatch.setattr("urllib.request.urlopen", mocked_urlopen)
|
||||
assert track.get_lyrics() == "amazing lyrics!"
|
||||
|
||||
def test_lyrics_not_found_error(self, track, monkeypatch):
|
||||
|
||||
def mocked_urlopen(url, timeout=None):
|
||||
raise urllib.request.HTTPError("", "", "", "", "")
|
||||
|
||||
monkeypatch.setattr("urllib.request.urlopen", mocked_urlopen)
|
||||
with pytest.raises(exceptions.LyricsNotFound):
|
||||
track.get_lyrics()
|
||||
31
spotdl/lyrics/providers/tests/test_lyricwikia_wrapper.py
Normal file
31
spotdl/lyrics/providers/tests/test_lyricwikia_wrapper.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import lyricwikia
|
||||
|
||||
from spotdl.lyrics import LyricBase
|
||||
from spotdl.lyrics import exceptions
|
||||
from spotdl.lyrics.providers import LyricWikia
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestLyricWikia:
|
||||
def test_subclass(self):
|
||||
assert issubclass(LyricWikia, LyricBase)
|
||||
|
||||
def test_get_lyrics(self, monkeypatch):
|
||||
# `LyricWikia` class uses the 3rd party method `lyricwikia.get_lyrics`
|
||||
# internally and there is no need to test a 3rd party library as they
|
||||
# have their own implementation of tests.
|
||||
monkeypatch.setattr("lyricwikia.get_lyrics", lambda a, b, c, d: "awesome lyrics!")
|
||||
track = LyricWikia("Lyricwikia", "Lyricwikia")
|
||||
assert track.get_lyrics() == "awesome lyrics!"
|
||||
|
||||
def test_lyrics_not_found_error(self, monkeypatch):
|
||||
|
||||
def lyricwikia_lyrics_not_found(msg):
|
||||
raise lyricwikia.LyricsNotFound(msg)
|
||||
|
||||
# Wrap `lyricwikia.LyricsNotFound` with `exceptions.LyricsNotFound` error.
|
||||
monkeypatch.setattr("lyricwikia.get_lyrics", lambda a, b, c, d: lyricwikia_lyrics_not_found("Nope, no lyrics."))
|
||||
track = LyricWikia("Lyricwikia", "Lyricwikia")
|
||||
with pytest.raises(exceptions.LyricsNotFound):
|
||||
track.get_lyrics()
|
||||
Reference in New Issue
Block a user