58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""核心数据结构单元测试"""
|
|
|
|
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 == "***"
|