Download tests/test_preprod.py from Surajnitp/flowmarg: direct link, hf CLI and curl.
- Browser
- Download file 3.32 kB
-
https://huggingface.co/spaces/Surajnitp/flowmarg/resolve/main/tests/test_preprod.py
- Command line
-
hf download hf://spaces/Surajnitp/flowmarg/tests/test_preprod.py
-
curl -L -o test_preprod.py https://huggingface.co/spaces/Surajnitp/flowmarg/resolve/main/tests/test_preprod.py
3.32 kB
| """Pre-production checks: VBA, Form A/B, drawing review, database indexes.""" | |
| from pathlib import Path | |
| from core.database import get_connection, insert_chainages, insert_provenance, query_geometry | |
| from core.drawing_reviewer import DrawingReviewer | |
| from core.form_ab_assistant import FormABAssistant | |
| from agent.code_tools import generate_all_vba_scripts, generate_vba_from_template | |
| ROOT = Path(__file__).resolve().parents[1] | |
| TEMPLATES = ROOT / "templates" / "vba" | |
| def test_vba_templates_have_required_placeholders(): | |
| required = ("{{CHAINAGE_LIST}}", "{{ALIGNMENT_NAME}}", "{{PROJECT_NAME}}") | |
| for path in TEMPLATES.glob("*.bas.template"): | |
| text = path.read_text(encoding="utf-8") | |
| for token in required: | |
| assert token in text, f"{path.name} missing {token}" | |
| long_section = (TEMPLATES / "long_section.bas.template").read_text(encoding="utf-8") | |
| assert "{{LEVEL_LIST}}" in long_section | |
| def test_generate_vba_from_template_fills_placeholders(): | |
| script = generate_vba_from_template( | |
| "survey_check", | |
| { | |
| "CHAINAGE_LIST": "1000, 1010", | |
| "ALIGNMENT_NAME": "CL_Existing", | |
| "PROJECT_NAME": "AuditProject", | |
| }, | |
| ) | |
| assert "1000, 1010" in script | |
| assert "CL_Existing" in script | |
| assert "AuditProject" in script | |
| assert "{{CHAINAGE_LIST}}" not in script | |
| def test_generate_all_vba_scripts_from_sqlite(): | |
| import pandas as pd | |
| df = pd.DataFrame( | |
| { | |
| "datum_chainage": [1000.0, 1010.0], | |
| "level_m": [12.1, 12.2], | |
| "offset_alignment": ["Main_Line", "Main_Line"], | |
| } | |
| ) | |
| insert_chainages(df, "proposed", source_file="vba_test.xml") | |
| scripts = generate_all_vba_scripts([], project_name="SQLiteVBA", alignment="Main_Line") | |
| assert "survey_check" in scripts | |
| assert "long_section" in scripts | |
| assert "1000" in scripts["survey_check"] or "1010" in scripts["survey_check"] | |
| def test_form_ab_draft_sections(): | |
| draft = FormABAssistant().generate_draft({"project_name": "FormABTest", "stage": "GRIP 4"}) | |
| assert "project_background" in draft | |
| assert "FormABTest" in draft["project_background"] | |
| assert "assumptions" in draft | |
| def test_drawing_reviewer_handles_invalid_pdf(): | |
| issues = DrawingReviewer().review_pdf(b"not-a-pdf", {"number": "NR-001", "revision": "P01"}) | |
| assert isinstance(issues, list) | |
| assert issues | |
| def test_lift_slue_export_columns(): | |
| from core.orchestrator import build_lift_slue_df | |
| df = build_lift_slue_df( | |
| {1: {"lift": {1000: 10}, "slue": {1000: 5}, "pr_cant": {1000: 20}, "pr_radius": {1000: 200}}}, | |
| [1000], | |
| {1: "Main"}, | |
| ) | |
| for col in ["Track", "Chainage", "Lift (mm)", "Slue (mm)", "Cant (mm)", "Radius (m)", "Source", "Standard clause"]: | |
| assert col in df.columns | |
| conn = get_connection() | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT name FROM sqlite_master WHERE type='index'") | |
| names = {row[0] for row in cursor.fetchall()} | |
| conn.close() | |
| assert "idx_chainages_alignment" in names | |
| assert "idx_chainages_type" in names | |
| assert "idx_chainages_chainage" in names or "idx_chainages_ch" in names | |
| insert_provenance("test", "1", source_file="audit.xml", chainage=1000.0) | |
| geom = query_geometry() | |
| assert geom is not None | |