This commit is contained in:
2026-09-14 11:10:05 +03:00
parent 458571576e
commit 181bbc3603
6 changed files with 242 additions and 68 deletions

View File

@@ -1,4 +1,4 @@
"""Корица + Съдържание + глава 1 → 2 секции (не 4)."""
"""Корица + Съдържание + глави: преамбюл + по една секция на номерирана глава."""
from pathlib import Path
from help_processor import (
@@ -8,7 +8,9 @@ from help_processor import (
Section,
)
FIXTURE = Path(__file__).parent / "fixtures" / "nespertcam_launcher_preamble.html"
FIXTURES = Path(__file__).parent / "fixtures"
PREAMBLE = FIXTURES / "nespertcam_launcher_preamble.html"
CHAPTERS = FIXTURES / "nespertcam_launcher_chapters.html"
def _titles(sections):
@@ -16,7 +18,7 @@ def _titles(sections):
def test_nespertcam_preamble_yields_two_sections():
sections = merge_preamble_sections(merge_short_sections(parse_html(FIXTURE)))
sections = merge_preamble_sections(merge_short_sections(parse_html(PREAMBLE)))
assert len(sections) == 2
assert sections[0].title == "NESPERTCAM Launcher - Пълно ръководство на потребителя"
assert sections[1].title == "1. Преглед на приложението"
@@ -26,8 +28,27 @@ def test_nespertcam_preamble_yields_two_sections():
assert "NESPERTCAM64.exe" in sections[1].text
def test_nespertcam_h2_chapters_split_not_one_section():
"""Като atra-manual.docx: H1=корица, TOC като Normal, глави като H2 → ≥3 секции."""
sections = merge_preamble_sections(merge_short_sections(parse_html(CHAPTERS)))
assert len(sections) >= 3
assert sections[0].title == "NESPERTCAM Launcher - Пълно ръководство на потребителя"
assert "Съдържание" in sections[0].text
assert "1. Преглед на приложението" in sections[0].text
assert sections[1].title == "1. Преглед на приложението"
assert sections[2].title == "2. Инсталация и настройка"
assert "Какво е NESPERTCAM Launcher?" in sections[1].text
assert "Основни предимства" in sections[1].text
assert "Фигура 1:" in sections[1].text
assert "Системни изисквания" in sections[2].text
assert "Windows 10" in sections[2].text
# H3/bold/фигура не отварят собствени секции
assert "Какво е NESPERTCAM Launcher?" not in _titles(sections)
assert "Основни предимства" not in _titles(sections)
def test_h2_and_bold_do_not_split_inside_chapter():
html = Path(__file__).parent / "fixtures" / "_tmp_h2.html"
html = FIXTURES / "_tmp_h2.html"
html.write_text(
"""<!DOCTYPE html><html><body>
<h1>Глава А</h1>
@@ -64,7 +85,7 @@ def test_toc_heading_as_h1_merges_into_cover():
def test_heading1_chapters_still_split():
html = Path(__file__).parent / "fixtures" / "_tmp_chapters.html"
html = FIXTURES / "_tmp_chapters.html"
html.write_text(
"""<!DOCTYPE html><html><body>
<h1>1. Първа</h1><p>Аа аа аа.</p>