feat(writer): add build_contexts (template+rules -> GenerationContext list)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from genesis.data_models import ParsedTemplate, ChapterMarker
|
||||
from genesis.writer.context_builder import build_contexts
|
||||
from genesis.writer.models import GenerationContext
|
||||
|
||||
|
||||
def _ss():
|
||||
template = ParsedTemplate(
|
||||
file_name="t.docx",
|
||||
sections=[
|
||||
ChapterMarker(type="heading", name="はじめに", level=1),
|
||||
ChapterMarker(type="placeholder", name="section:introduction", level=0),
|
||||
],
|
||||
placeholders={},
|
||||
styles={"defined": ["Heading1"], "used": ["Heading1", "Normal"]},
|
||||
)
|
||||
return SimpleNamespace(template=template)
|
||||
|
||||
|
||||
def test_build_contexts_maps_chapters():
|
||||
ctxs = build_contexts(_ss(), samples_dir="nonexistent_dir_xyz")
|
||||
assert len(ctxs) == 1
|
||||
c = ctxs[0]
|
||||
assert isinstance(c, GenerationContext)
|
||||
assert c.chapter_id == "introduction"
|
||||
assert c.write_rules == [] # 样本缺失 -> 空
|
||||
assert c.design_rules == []
|
||||
assert c.template_styles == {"Heading1", "Normal"}
|
||||
assert c.template_marker.section_placeholder == "section:introduction"
|
||||
Reference in New Issue
Block a user