Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| from pathlib import Path | |
| import pytest | |
| from backend.config import REPO_ROOT, settings | |
| _BUNDLE_DIR = REPO_ROOT / "Master Standard report and paragraphs" | |
| _PDF = _BUNDLE_DIR / settings.report_template_filename | |
| _WORD = _BUNDLE_DIR / settings.standard_paragraphs_filename | |
| def test_real_pdf_schema_has_expected_sections(): | |
| from backend.core.template_discoverer import discover_report_template_schema | |
| from backend.core.rics_canonical_l3 import PARENT_SECTION_COUNT, valid_leaf_section_ids | |
| schema = discover_report_template_schema(_PDF) | |
| ids = schema.section_ids() | |
| assert len(ids) == len(valid_leaf_section_ids()) | |
| assert schema.additional_metadata.get("parent_section_count") == PARENT_SECTION_COUNT | |
| assert "D1" in ids | |
| assert "A1" in ids | |
| assert "B1" in ids | |
| assert "AS" not in ids | |
| assert "OF" not in ids | |
| def test_real_word_paragraphs_have_e1(): | |
| from backend.core.template_discoverer import discover_standard_paragraph_titles | |
| titles = discover_standard_paragraph_titles(_WORD) | |
| assert "E1" in titles | |
| assert "chimney" in titles["E1"].lower() | |
| def test_real_bundle_alias_maps_d1_to_e1(tmp_path, monkeypatch): | |
| from backend.core import ingest, template_discoverer | |
| monkeypatch.setattr(settings, "data_dir", str(tmp_path / "data")) | |
| monkeypatch.setattr(settings, "pii_use_spacy", False) | |
| monkeypatch.setattr(settings, "master_template_dir", str(_BUNDLE_DIR)) | |
| tenant = "bundle-smoke" | |
| ingest.ingest_report_template(tenant, _PDF) | |
| ingest.ingest_standard_paragraphs(tenant, _WORD) | |
| schema = template_discoverer.load_schema(tenant) | |
| assert schema is not None | |
| assert schema.report_template_source == _PDF.name | |
| assert schema.standard_paragraphs_source == _WORD.name | |
| if "D1" in schema.section_ids() and "E1" in schema.paragraph_section_titles: | |
| assert schema.section_alias_map.get("D1") == "E1" | |