SPB Git forge

spb/uqo-chat

Public
14commits 1branches 0releases
1.4 MBsize
maindefault branch
17 days agolast push
Python 64.6% TypeScript 33.7% CSS 0.8%
1.8 KB · 44 lines python
Raw Blame History
1import io23import pytest4from openpyxl import load_workbook56from app.tools.create_excel import build_workbook7from app.tools.excel_templates import TEMPLATES8910@pytest.mark.parametrize("name", list(TEMPLATES))11def test_templates_build_and_reload(name: str) -> None:12    spec = TEMPLATES[name]({})13    data, summaries = build_workbook(spec)14    wb = load_workbook(io.BytesIO(data))15    assert wb.sheetnames[0] == "Lisez-moi"16    assert len(wb.sheetnames) >= 217    assert summaries and all(s["rows"] > 2 for s in summaries)18    ws = wb.worksheets[1]19    formulas = [c.value for row in ws.iter_rows() for c in row20                if isinstance(c.value, str) and c.value.startswith("=")]21    assert formulas, "templates must contain live formulas"222324def test_methode_du_cout_formulas_reference_existing_cells() -> None:25    data, _ = build_workbook(TEMPLATES["methode_du_cout"]({}))26    ws = load_workbook(io.BytesIO(data))["Méthode du coût"]27    assert ws["B17"].value == "=B4*B5"28    assert ws["A28"].value.startswith("VALEUR INDIQUÉE")29    assert ws["B28"].value == "=B25+B26+B27"30    names = set(load_workbook(io.BytesIO(data)).defined_names.keys())31    assert {"Valeur_Terrain", "Valeur_Indiquee", "DVE"} <= names323334def test_free_spec() -> None:35    spec = {"filename": "t.xlsx", "sheets": [{"name": "Test", "title": "T",36            "inputs": [{"cell": "B4", "label": "x", "value": 2, "format": "number"}],37            "tables": [{"anchor": "A6", "columns": [{"header": "a", "type": "text"},38                                                    {"header": "b", "type": "currency"}],39                        "rows": [["un", "=B4*10"], ["deux", 5]],40                        "totals": {"label": "T", "formula": "=B7+B8"}}]}]}41    data, _ = build_workbook(spec)42    ws = load_workbook(io.BytesIO(data))["Test"]43    assert ws["B7"].value == "=B4*10" and ws["B9"].value == "=B7+B8"44