Initial commit: AI 知识库文档智能分块工具
This commit is contained in:
57
tests/test_models.py
Normal file
57
tests/test_models.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""核心数据结构单元测试"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from models import Chunk, CLIArgs, ProcessResult
|
||||
|
||||
|
||||
class TestChunk:
|
||||
def test_creation(self):
|
||||
chunk = Chunk(title="概述", content="这是内容")
|
||||
assert chunk.title == "概述"
|
||||
assert chunk.content == "这是内容"
|
||||
|
||||
def test_equality(self):
|
||||
a = Chunk(title="t", content="c")
|
||||
b = Chunk(title="t", content="c")
|
||||
assert a == b
|
||||
|
||||
|
||||
class TestProcessResult:
|
||||
def test_creation(self):
|
||||
now = datetime.now()
|
||||
chunks = [Chunk("t1", "c1"), Chunk("t2", "c2")]
|
||||
result = ProcessResult(
|
||||
source_file="input.pdf",
|
||||
output_file="output.md",
|
||||
chunks=chunks,
|
||||
process_time=now,
|
||||
total_chunks=2,
|
||||
)
|
||||
assert result.source_file == "input.pdf"
|
||||
assert result.output_file == "output.md"
|
||||
assert len(result.chunks) == 2
|
||||
assert result.process_time == now
|
||||
assert result.total_chunks == 2
|
||||
|
||||
|
||||
class TestCLIArgs:
|
||||
def test_required_fields(self):
|
||||
args = CLIArgs(input_file="doc.pdf", api_key="sk-123")
|
||||
assert args.input_file == "doc.pdf"
|
||||
assert args.api_key == "sk-123"
|
||||
|
||||
def test_defaults(self):
|
||||
args = CLIArgs(input_file="doc.pdf", api_key="sk-123")
|
||||
assert args.output_file is None
|
||||
assert args.delimiter == "---"
|
||||
|
||||
def test_custom_values(self):
|
||||
args = CLIArgs(
|
||||
input_file="doc.pdf",
|
||||
api_key="sk-123",
|
||||
output_file="out.md",
|
||||
delimiter="***",
|
||||
)
|
||||
assert args.output_file == "out.md"
|
||||
assert args.delimiter == "***"
|
||||
Reference in New Issue
Block a user