feat: 数据模型 data_models(design §3+§9.4,future.annotations)

This commit is contained in:
lhl
2026-08-08 15:30:04 +08:00
parent e865a78701
commit 9d69bb3cd7
2 changed files with 302 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
from dataclasses import asdict
from genesis.data_models import (
CellComment, CellFormatting, CellValue, Confidence, ElementType,
ExcelTable, ExtractionMethod, ImageAnalysis, ParsedTemplate, Provenance,
RelationType, RuleDocument, SheetType, StructuredSource,
)
def test_sheettype_has_8_members():
assert len(SheetType) == 8
assert SheetType.FUNCTION.value == "FUNCTION"
assert SheetType.GENERIC.value == "GENERIC"
def test_value_enum_members():
assert ElementType.FUNCTION.value == "機能"
assert RelationType.USE.value == "利用"
assert Confidence.HIGH.value == "high"
assert ExtractionMethod.OPENPYXL.value == "openpyxl"
def test_cellformatting_defaults():
fmt = CellFormatting()
assert fmt.strikethrough is False
assert fmt.font_color is None
assert fmt.bg_color is None
def test_cellvalue_forward_reference_works():
"""CellValue 引用后置定义的 CellFormatting/CellCommentfuture.annotations 落地)"""
prov = Provenance(file_name="f.xlsx", sheet_name="S", row=1, column="A", column_header="h")
cv = CellValue(
value="x",
provenance=prov,
formatting=CellFormatting(strikethrough=True),
comment=CellComment(author="reviewer", text="check", source_uri="f.xlsx#S!A1"),
)
assert cv.formatting.strikethrough is True
assert cv.comment.author == "reviewer"
def test_excel_table_references_sheettype():
table = ExcelTable(
name="機能一覧",
detected_type=SheetType.FUNCTION,
extraction_method=ExtractionMethod.OPENPYXL.value,
headers=["機能ID", "機能名"],
rows=[],
)
assert table.detected_type is SheetType.FUNCTION
assert table.extraction_method == "openpyxl"
def test_structured_source_assembles_all():
source = StructuredSource(
tables=[],
template=ParsedTemplate(file_name="t.docx", sections=[], placeholders={}, styles={}),
rule_docs=[RuleDocument(
file_name="記入規則.docx", category="write", markdown_content="# 規則",
source_path="samples/記入規則.docx", file_type="word", hash="abc",
)],
image_analyses=[ImageAnalysis(
image_ref="img1", description="画面遷移図", confidence=0.9,
source_uri="f.xlsx#S!A1", sheet_name="S", anchor_cell="A1", status="recognized",
)],
existing_system=None,
comments=[],
)
assert source.rule_docs[0].category == "write"
assert source.image_analyses[0].nearby_text == ""
def test_asdict_serializable():
prov = Provenance(file_name="f.xlsx", sheet_name="S", row=1, column="A", column_header="h")
d = asdict(CellValue(value=1, provenance=prov))
assert d["provenance"]["row"] == 1