Update 0.4.0
Python application / build (push) Has been cancelled

- Add\Rework UI
- Add Split Table and Listing
- Add Support Customazeble schems
This commit is contained in:
Igor20264
2026-09-04 22:28:39 +03:00
parent 516abe7b83
commit b38661f588
70 changed files with 69532 additions and 413 deletions
+161
View File
@@ -378,3 +378,164 @@ def test_apid_biblio_min_seven():
assert any(i.id == "biblio.count" for i in issues)
def test_special_heading_alignment_soderzhanie_vs_vvedenie():
import docx
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Cm
from md2gost.renderable.heading import Heading
from md2gost.renderer import Renderer
from md2gost.styles import apply_mirea_styles
doc = docx.Document(r"md2gost/Template.docx")
doc._body.clear_content()
apply_mirea_styles(doc)
renderer = Renderer(doc, skip_numbering=True)
h_toc = Heading(doc._body, 1, False)
h_toc.add_run("СОДЕРЖАНИЕ")
renderer._handle_heading(h_toc)
assert h_toc._docx_paragraph.alignment == WD_ALIGN_PARAGRAPH.CENTER
assert abs(h_toc._docx_paragraph.paragraph_format.left_indent.cm - 0) < 0.01
h_intro = Heading(doc._body, 1, False)
h_intro.add_run("ВВЕДЕНИЕ")
renderer._handle_heading(h_intro)
# Left like Heading 1 (style indent 1.25), not forced center
assert h_intro._docx_paragraph.alignment != WD_ALIGN_PARAGRAPH.CENTER
def test_appendix_item_becomes_h3_plus_title():
import docx
from docx.enum.text import WD_ALIGN_PARAGRAPH
from md2gost.renderable.heading import Heading
from md2gost.renderer import Renderer
from md2gost.styles import apply_mirea_styles
doc = docx.Document(r"md2gost/Template.docx")
doc._body.clear_content()
apply_mirea_styles(doc)
renderer = Renderer(doc, skip_numbering=True)
h = Heading(doc._body, 2, True)
h.add_run("Приложение А Листинг модуля")
renderer._handle_heading(h)
assert h.style.name == "Heading 3"
assert h.text == "Приложение А"
assert h._docx_paragraph.alignment == WD_ALIGN_PARAGRAPH.CENTER
assert len(renderer._after_current) == 1
title_p = renderer._after_current[0]
assert "Листинг модуля" in title_p._docx_paragraph.text
assert title_p._docx_paragraph.alignment == WD_ALIGN_PARAGRAPH.CENTER
def test_caption_table_keep_with_next_and_toc_styles():
import docx
from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_LINE_SPACING
from md2gost.styles import apply_mirea_styles
doc = docx.Document(r"md2gost/Template.docx")
apply_mirea_styles(doc)
assert doc.styles["Caption Table"].paragraph_format.keep_with_next is True
assert doc.styles["Table Text"].paragraph_format.alignment == WD_ALIGN_PARAGRAPH.LEFT
bh = doc.styles["Bibliography Heading"]
assert abs(bh.paragraph_format.left_indent.cm - 1.25) < 0.01
toc1 = doc.styles["toc 1"]
assert toc1.font.all_caps is True
assert toc1.font.bold is False
assert toc1.paragraph_format.line_spacing_rule == WD_LINE_SPACING.ONE_POINT_FIVE
def test_emdash_default_false_in_pipeline():
from md2gost.pipeline import ConvertRequest
assert ConvertRequest().emdash_to_hyphen is False
def test_object_ref_unused_warning():
text = SAMPLE_OK.replace("@Рисунок:arch", "схема")
issues = check_markdown(text, "coursework")
assert any(i.id == "ref.unused" for i in issues)
def test_table_continuation_warning():
issues = check_markdown(SAMPLE_OK, "coursework", table_continuation="off")
assert any(i.id == "table.continuation" for i in issues)
issues2 = check_markdown(SAMPLE_OK, "coursework", table_continuation="caption")
assert not any(i.id == "table.continuation" for i in issues2)
issues3 = check_markdown(SAMPLE_OK, "coursework", table_continuation="word")
assert not any(i.id == "table.continuation" for i in issues3)
def test_appendix_list_warning():
text = SAMPLE_OK + "\n## Приложение Б Ещё\n\nТекст.\n"
# No list between ПРИЛОЖЕНИЯ and first appendix
issues = check_markdown(text, "coursework")
assert any(i.id == "appendix.toc" for i in issues)
def test_vkr_biblio_per_section():
text = """
# *СОДЕРЖАНИЕ
[TOC]
# *ВВЕДЕНИЕ
Текст.
# 1 Раздел
См. [1.1].
# *ЗАКЛЮЧЕНИЕ
Выводы.
# *СПИСОК ИСПОЛЬЗОВАННЫХ ИСТОЧНИКОВ
## Нормативные
[1.1]: ГОСТ 7.32-2017. — М., 2022.
## Научные
[2.1]: Иванов И. И. Книга. — М., 2023.
# *ПРИЛОЖЕНИЯ
## Приложение А Графический материал
Слайды.
"""
issues = check_markdown(text, "vkr")
assert any(i.id == "biblio.count" for i in issues)
def test_page_fill_evaluate_heuristic():
from md2gost.page_fill_check import PageMetric, evaluate_page_fill
pages = [
PageMetric(1, 0.4, "1 Анализ", "1 Анализ"),
PageMetric(2, 0.9, "1 Анализ", "2 Проект", is_last_doc_page=False),
PageMetric(3, 0.5, "2 Проект", None, is_last_doc_page=True),
]
issues = evaluate_page_fill(pages)
assert len(issues) == 1
assert issues[0].page_index == 1
assert "heuristic" in issues[0].message
# Last page of section — no issue
pages2 = [
PageMetric(1, 0.3, "1 Анализ", "2 Проект"),
PageMetric(2, 0.9, "2 Проект", None, is_last_doc_page=True),
]
assert evaluate_page_fill(pages2) == []
# Landscape skipped
pages3 = [
PageMetric(1, 0.2, "1 Анализ", "1 Анализ", is_landscape=True),
PageMetric(2, 0.9, "1 Анализ", None, is_last_doc_page=True),
]
assert evaluate_page_fill(pages3) == []
def test_landscape_valign_center():
from docx import Document
from docx.oxml.ns import qn
from md2gost import package_dir
import os
from md2gost.page_geometry import apply_section_geometry
doc = Document(os.path.join(package_dir(), "Template.docx"))
section = doc.sections[0]
apply_section_geometry(section, landscape=True)
valign = section._sectPr.find(qn("w:vAlign"))
assert valign is not None
assert valign.get(qn("w:val")) == "center"
apply_section_geometry(section, landscape=False)
assert section._sectPr.find(qn("w:vAlign")) is None