40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Unit tests for Stage 3 lyrics hyphenation and proportional timing."""
|
|
|
|
import pyphen
|
|
|
|
from unmix.pipeline.s3_lyrics import hyphenate_word, split_word_into_syllables_timed
|
|
|
|
|
|
def test_hyphenate_word_german():
|
|
dic = pyphen.Pyphen(lang="de_DE")
|
|
# "Guten" -> ["Gu", "ten"]
|
|
sylls = hyphenate_word("Guten", dic)
|
|
assert len(sylls) == 2
|
|
assert "".join(sylls) == "Guten"
|
|
|
|
# With trailing punctuation and space: "Morgen! "
|
|
sylls_punct = hyphenate_word("Morgen! ", dic)
|
|
assert len(sylls_punct) == 2
|
|
assert "".join(sylls_punct) == "Morgen! "
|
|
|
|
|
|
def test_hyphenate_word_english():
|
|
dic = pyphen.Pyphen(lang="en_US")
|
|
# "Hello" -> ["Hel", "lo"]
|
|
sylls = hyphenate_word("Hello", dic)
|
|
assert len(sylls) == 2
|
|
assert "".join(sylls) == "Hello"
|
|
|
|
|
|
def test_split_word_into_syllables_timed():
|
|
dic = pyphen.Pyphen(lang="en_US")
|
|
# "Hello " duration 1.0s (from 10.0 to 11.0)
|
|
timed = split_word_into_syllables_timed("Hello ", 10.0, 11.0, dic)
|
|
assert len(timed) == 2
|
|
assert timed[0]["start"] == 10.0
|
|
assert timed[1]["end"] == 11.0
|
|
assert timed[0]["end"] == timed[1]["start"]
|
|
# Syllables should be "Hel" and "lo "
|
|
assert timed[0]["text"] == "Hel"
|
|
assert timed[1]["text"] == "lo "
|