DarkCat09
0b0759fb3b
Small note on how it works, copied from raise_on_irrelevant_result() docstring: Raises ValueError if no words from track title are present in search result track title and no words from artist name are present in search result artist name
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
from unittest import TestCase
|
|
|
|
import genius
|
|
import http_pool
|
|
|
|
|
|
TITLE = 'A Line In The Sand'
|
|
ARTIST = 'Linkin Park'
|
|
URL = 'https://genius.com/Linkin-park-a-line-in-the-sand-lyrics'
|
|
|
|
LYR1 = '''[Intro: Mike Shinoda]
|
|
Today, we stood on the wall'''
|
|
|
|
LYR2 = '''little did we know
|
|
|
|
[Instrumental Break]
|
|
|
|
[Verse 1:'''
|
|
|
|
LYR3 = '''you are gonna get yours
|
|
|
|
[Chorus: Chester Bennington]
|
|
Another day'''
|
|
|
|
|
|
# There is no lyrics for this song on Genius
|
|
# Maybe someday TITLE2 and ARTIST2 will need to be changed
|
|
# (But really existing song is chosen intentionally)
|
|
TITLE2 = 'Паруса'
|
|
ARTIST2 = 'PIZZA'
|
|
|
|
|
|
class TestGenius(TestCase):
|
|
|
|
def setUp(self) -> None:
|
|
http_pool.get()
|
|
|
|
def test_search(self) -> None:
|
|
_, url = genius.search(TITLE, ARTIST)
|
|
self.assertEqual(url, URL)
|
|
|
|
def test_search_success(self) -> None:
|
|
title, _ = genius.search(TITLE, ARTIST)
|
|
genius.raise_on_irrelevant_result(title, TITLE, ARTIST)
|
|
|
|
def test_search_failure(self) -> None:
|
|
title, _ = genius.search(TITLE2, ARTIST2)
|
|
with self.assertRaises(ValueError):
|
|
genius.raise_on_irrelevant_result(title, TITLE2, ARTIST2)
|
|
|
|
def test_relevancy_success(self) -> None:
|
|
genius.raise_on_irrelevant_result(
|
|
'ABC hEllo world!@ \u2013 sOmE artist123',
|
|
'Artist123',
|
|
'hello World',
|
|
)
|
|
|
|
def test_relevancy_failure(self) -> None:
|
|
with self.assertRaises(ValueError):
|
|
genius.raise_on_irrelevant_result(
|
|
'DEF hEllo world@!15 \u2013 anOther artist456',
|
|
'DEF 789',
|
|
'ABC irrelevant track title',
|
|
)
|
|
|
|
def test_lyrics_parsing(self) -> None:
|
|
lyrics = genius.parse(URL)
|
|
self.assertTrue(lyrics.startswith(LYR1))
|
|
self.assertTrue(LYR2 in lyrics)
|
|
self.assertTrue(LYR3 in lyrics)
|
|
|
|
def tearDown(self) -> None:
|
|
http_pool.get().clear()
|