File size: 2,635 Bytes
da8d589 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
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 = """
<speak version="0.1">
<voice spk="xiaoyan" style="news">
<prosody rate="fast">你好</prosody>
<break time="500ms"/>
<prosody rate="slow">你好</prosody>
</voice>
</speak>
"""
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 = """
<speak version="0.1">
<voice spk="xiaoyan" style="news">你好</voice>
</speak>
"""
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 = """
<speak version="0.1">
<break time="500ms"/>
</speak>
"""
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 = """
<speak version="0.1">
<prosody rate="fast">你好</prosody>
</speak>
"""
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 = """
<speak version="0.2">
<voice spk="xiaoyan" style="news">你好</voice>
</speak>
"""
with pytest.raises(ValueError, match=r"Unsupported SSML version 0.2"):
parser.parse(ssml)
@pytest.mark.ssml_parser
def test_unsupported_tag(parser):
ssml = """
<speak version="0.1">
<unsupported>你好</unsupported>
</speak>
"""
with pytest.raises(NotImplementedError, match=r"Tag unsupported not supported."):
parser.parse(ssml)
if __name__ == "__main__":
pytest.main()
|