65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
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()
|