Files
songtrace/tests/test_lyrics.py
T

41 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from songtrace.lyrics import normalize_lyrics, alignment_token
RAW = """[Verse 1]
It's one two three
[Chorus]
Whoa, la la o' la
Count me up to 7 times
"""
def test_normalize_strips_sections_and_blanks():
ref = normalize_lyrics(RAW)
assert ref.lines == [
["It's", "one", "two", "three"],
["Whoa,", "la", "la", "o'", "la"],
["Count", "me", "up", "to", "7", "times"],
]
assert ref.words[0] == "It's"
assert ref.word_line_index == [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]
def test_alignment_token():
assert alignment_token("Whoa,") == "whoa"
assert alignment_token("o'") == "o'"
assert alignment_token("7") == "seven"
assert alignment_token("...") == ""
def test_alignment_token_no_internal_whitespace():
assert alignment_token("21") == "twentyone"
assert alignment_token("7th") == "seventh"
def test_alignment_token_hyphenated_word():
assert alignment_token("well-known") == "wellknown"
def test_alignment_token_curly_apostrophe():
assert alignment_token("don’t") == "don't"