import pytest
from lxml import etree
from modules.ssml_parser.SSMLParser import (
create_ssml_parser,
SSMLSegment,
SSMLBreak,
SSMLContext,
)
@pytest.fixture
def parser():
return create_ssml_parser()
@pytest.mark.ssml_parser
def test_speak_tag(parser):
ssml = """
你好
你好
"""
segments = parser.parse(ssml)
assert len(segments) == 3
assert isinstance(segments[0], SSMLSegment)
assert segments[0].text == "你好"
assert segments[0].params.rate == "fast"
assert isinstance(segments[1], SSMLBreak)
assert segments[1].duration == 500
assert isinstance(segments[2], SSMLSegment)
assert segments[2].text == "你好"
assert segments[2].params.rate == "slow"
@pytest.mark.ssml_parser
def test_voice_tag(parser):
ssml = """
你好
"""
segments = parser.parse(ssml)
assert len(segments) == 1
assert isinstance(segments[0], SSMLSegment)
assert segments[0].text == "你好"
assert segments[0].params.spk == "xiaoyan"
assert segments[0].params.style == "news"
@pytest.mark.ssml_parser
def test_break_tag(parser):
ssml = """
"""
segments = parser.parse(ssml)
assert len(segments) == 1
assert isinstance(segments[0], SSMLBreak)
assert segments[0].duration == 500
@pytest.mark.ssml_parser
def test_prosody_tag(parser):
ssml = """
你好
"""
segments = parser.parse(ssml)
assert len(segments) == 1
assert isinstance(segments[0], SSMLSegment)
assert segments[0].text == "你好"
assert segments[0].params.rate == "fast"
@pytest.mark.ssml_parser
def test_unsupported_version(parser):
ssml = """
你好
"""
with pytest.raises(ValueError, match=r"Unsupported SSML version 0.2"):
parser.parse(ssml)
@pytest.mark.ssml_parser
def test_unsupported_tag(parser):
ssml = """
你好
"""
with pytest.raises(NotImplementedError, match=r"Tag unsupported not supported."):
parser.parse(ssml)
if __name__ == "__main__":
pytest.main()