Files
2026-07-23 17:21:49 +08:00

33 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import tempfile
import unittest
import embeddings
class TextExtractionTests(unittest.TestCase):
def write_text(self, suffix, content):
handle = tempfile.NamedTemporaryFile(suffix=suffix, delete=False)
handle.close()
self.addCleanup(lambda: os.path.exists(handle.name) and os.unlink(handle.name))
with open(handle.name, "w", encoding="utf-8") as stream:
stream.write(content)
return handle.name
def test_extracts_utf8_markdown(self):
path = self.write_text(".md", "# 退款规则\n\n七日内可申请退款。")
self.assertEqual(embeddings.extract_text(path, ".md"), "# 退款规则\n\n七日内可申请退款。")
def test_extracts_utf8_text(self):
path = self.write_text(".txt", "客服热线400-123-4567")
self.assertEqual(embeddings.extract_text(path, ".txt"), "客服热线400-123-4567")
def test_rejects_unsupported_extension(self):
path = self.write_text(".csv", "not supported")
with self.assertRaises(ValueError):
embeddings.extract_text(path, ".csv")
if __name__ == "__main__":
unittest.main()