Skip to content

Commit

Permalink
Refactor utils test cases to use pytest.mark.parametrize
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Oct 5, 2024
1 parent 3cd0855 commit 5a1183d
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions test/plugins/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,38 +93,42 @@ def test_search_pairs_titles(self, title, expected_extra_titles):

assert list(actual_titles) == [title, *expected_extra_titles]

def test_remove_credits(self):
assert (
lyrics.remove_credits(
"""It's close to midnight
Lyrics brought by example.com"""
)
== "It's close to midnight"
)
assert lyrics.remove_credits("""Lyrics brought by example.com""") == ""

# don't remove 2nd verse for the only reason it contains 'lyrics' word
text = """Look at all the shit that i done bought her
See lyrics ain't nothin
if the beat aint crackin"""
assert lyrics.remove_credits(text) == text
@pytest.mark.parametrize(
"initial_lyrics, expected",
[
("Verse\nLyrics credit in the last line", "Verse"),
("Lyrics credit in the first line\nVerse", "Verse"),
(
"""Verse
Lyrics mentioned somewhere in the middle
Verse""",
"""Verse
Lyrics mentioned somewhere in the middle
Verse""",
),
],
)
def test_remove_credits(self, initial_lyrics, expected):
assert lyrics.remove_credits(initial_lyrics) == expected

def test_scrape_strip_cruft(self):
text = """<!--lyrics below-->
@pytest.mark.parametrize(
"initial_text, expected",
[
(
"""<!--lyrics below-->
&nbsp;one
<br class='myclass'>
two !
<br><br \\>
<blink>four</blink>"""
assert lyrics._scrape_strip_cruft(text, True) == "one\ntwo !\n\nfour"

def test_scrape_strip_scripts(self):
text = """foo<script>bar</script>baz"""
assert lyrics._scrape_strip_cruft(text, True) == "foobaz"

def test_scrape_strip_tag_in_comment(self):
text = """foo<!--<bar>-->qux"""
assert lyrics._scrape_strip_cruft(text, True) == "fooqux"
<blink>four</blink>""",
"one\ntwo !\n\nfour",
),
("foo<script>bar</script>baz", "foobaz"),
("foo<!--<bar>-->qux", "fooqux"),
],
)
def test_scrape_strip_cruft(self, initial_text, expected):
assert lyrics._scrape_strip_cruft(initial_text, True) == expected

def test_scrape_merge_paragraphs(self):
text = "one</p> <p class='myclass'>two</p><p>three"
Expand Down

0 comments on commit 5a1183d

Please sign in to comment.