update 0.4.4
Python application / build (push) Has been cancelled

- update документация
- промт для ии полу конфигурируемый
This commit is contained in:
Igor20264
2026-09-06 11:04:01 +03:00
parent 638fd38d7f
commit 818a044aa1
26 changed files with 1987 additions and 457 deletions
+38
View File
@@ -153,11 +153,49 @@ def test_prompt_catalog_loads():
from md2gost.help_content import load_prompt_catalog
catalog = load_prompt_catalog()
names = {name for name, _title, text in catalog}
assert "generate-md.md" in names
assert "generate-mirea-report.md" in names
assert "generate-pis-custom-report.md" in names
assert all(text.strip() for _n, _t, text in catalog)
def test_compose_prompt_with_schemes():
from md2gost.diagram_schemes import DiagramScheme
from md2gost.help_content import compose_prompt, scheme_prompt_block
scheme = DiagramScheme(
id="c4",
title="C4 Container",
docs='Person(alias, "Label")',
ai_prompt="Рисуй C4. Блок ```uml-c4 без @startuml.",
)
block = scheme_prompt_block(scheme)
assert "uml-c4" in block
assert "```c4" in block or "```uml-c4" in block
assert "Рисуй C4" in block
assert "Person(alias" in block
base = "Базовый промпт про markdown.\n"
out = compose_prompt(base, [scheme])
assert out.startswith("Базовый промпт")
assert "Дополнение: выбранные схемы" in out
assert "uml-c4" in out
assert compose_prompt(base, []).strip() == base.strip()
assert compose_prompt(base, None).strip() == base.strip()
def test_docs_catalog_loads():
from md2gost.help_content import load_docs_catalog
catalog = load_docs_catalog()
assert catalog, "docs/ catalog should not be empty"
names = {name for name, _title, _text in catalog}
assert "README.md" in names
assert "markdown.md" in names
assert catalog[0][0].lower() == "readme.md"
assert "Документация" in catalog[0][1]
assert all(text.strip() for _n, _t, text in catalog)
def test_listing_continuation_mode():
import os
import docx
+114
View File
@@ -0,0 +1,114 @@
"""Tests for JSON style overlay (md2gost.styles.json / --styles)."""
from __future__ import annotations
import json
from pathlib import Path
import docx
import pytest
from docx.enum.text import WD_ALIGN_PARAGRAPH
from md2gost.style_config import (
StyleConfigError,
get_preset,
resolve_style_config,
style_config_from_dict,
)
from md2gost.styles import apply_document_styles, apply_style_config
from md2gost import page_geometry as pg
TEMPLATE = Path("md2gost/Template.docx")
def test_preset_unchanged_without_overlay():
cfg = resolve_style_config("mirea")
assert cfg.page.left_mm == 30
assert cfg.page.right_mm == 10
h1 = cfg.styles["Heading 1"]
assert h1.alignment == "left"
assert h1.size_pt == 18
assert h1.all_caps is True
def test_overlay_changes_margins_and_h1(tmp_path: Path):
overlay = {
"page": {"left_mm": 20, "right_mm": 20},
"styles": {
"Heading 1": {
"alignment": "center",
"size_pt": 14,
"left_indent_cm": 0,
}
},
}
path = tmp_path / "custom.json"
path.write_text(json.dumps(overlay), encoding="utf-8")
cfg = resolve_style_config("mirea", styles_path=path)
assert cfg.page.left_mm == 20
assert cfg.page.right_mm == 20
# Unspecified margins stay from preset
assert cfg.page.top_mm == 20
assert cfg.page.bottom_mm == 20
assert cfg.styles["Heading 1"].alignment == "center"
assert cfg.styles["Heading 1"].size_pt == 14
# Unspecified heading fields stay from preset
assert cfg.styles["Heading 1"].all_caps is True
assert cfg.styles["Heading 1"].bold is True
def test_unknown_style_name_raises():
with pytest.raises(StyleConfigError, match="Unknown style name"):
style_config_from_dict({"styles": {"Heading 9": {"size_pt": 12}}})
def test_unknown_page_key_raises():
with pytest.raises(StyleConfigError, match="Unknown page key"):
style_config_from_dict({"page": {"gutter_mm": 5}})
def test_unknown_style_field_raises():
with pytest.raises(StyleConfigError, match="Unknown style field"):
style_config_from_dict({"styles": {"Normal": {"color": "red"}}})
def test_cli_overlay_wins_over_near_md(tmp_path: Path):
near = tmp_path / "md2gost.styles.json"
near.write_text(
json.dumps({"page": {"left_mm": 25}, "styles": {"Heading 1": {"size_pt": 16}}}),
encoding="utf-8",
)
cli = tmp_path / "cli.json"
cli.write_text(
json.dumps({"page": {"left_mm": 15}, "styles": {"Heading 1": {"alignment": "center"}}}),
encoding="utf-8",
)
cfg = resolve_style_config("mirea", md_dir=tmp_path, styles_path=cli)
assert cfg.page.left_mm == 15
assert cfg.styles["Heading 1"].size_pt == 16 # from near-md, not overridden
assert cfg.styles["Heading 1"].alignment == "center" # from CLI
def test_apply_overlay_to_document(tmp_path: Path):
overlay = style_config_from_dict({
"page": {"left_mm": 20, "right_mm": 20, "top_mm": 20, "bottom_mm": 20},
"styles": {"Heading 1": {"alignment": "center", "size_pt": 14}},
})
doc = docx.Document(str(TEMPLATE))
apply_document_styles(doc, "mirea", overlay=overlay)
h1 = doc.styles["Heading 1"]
assert h1.paragraph_format.alignment == WD_ALIGN_PARAGRAPH.CENTER
assert abs(h1.font.size.pt - 14) < 0.01
section = doc.sections[0]
assert abs(section.left_margin.mm - 20) < 0.1
assert abs(pg.MARGIN_LEFT.mm - 20) < 0.1
def test_pis_preset_h1_centered():
doc = docx.Document(str(TEMPLATE))
apply_style_config(doc, get_preset("pis_custom"))
h1 = doc.styles["Heading 1"]
assert h1.paragraph_format.alignment == WD_ALIGN_PARAGRAPH.CENTER
assert h1.font.all_caps is True