基本完成代码

This commit is contained in:
hydrogen committed 2026-05-24 16:42:11 +08:00
commit dbda6edc00
15 files changed
+953

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
from unittest import TestCase
import loguru
logger = loguru.logger
logger.add("test.log", rotation="1 MB", retention="10 days", level="DEBUG")
class Test(TestCase):
def test_simple_html_parse(self):
from parser import TTSHTMLParser
html = """
<root>
<voice1>hello</voice1>
<voice2>world</voice2>
<voice4>foo</voice4>
<voice5>bar</voice5>
</root>
"""
parser = TTSHTMLParser(html)
result = parser.parse()
expected = (
("voice1", "hello"),
("voice2", "world"),
("voice4", "foo"),
("voice5", "bar"),
)
logger.debug(f"解析结果: {result}")
self.assertEqual(result, expected)
def test_nested_html_parse(self):
from parser import TTSHTMLParser
html = """
<root>
<voice1>hello</voice1>
<voice2>world</voice2>
<voice3>
<voice4>foo</voice4>
<voice5>bar</voice5>
123
</voice3>
</root>
"""
parser = TTSHTMLParser(html)
result = parser.parse()
expected = (
("voice1", "hello"),
("voice2", "world"),
("voice4", "foo"),
("voice5", "bar"),
("voice3", "123"),
)
logger.debug(f"解析结果: {result}")
self.assertEqual(result, expected)
if __name__ == "__main__":
import unittest
unittest.main()