Fixed Syntax validation and autocompletion. Fixed unit tests

This commit is contained in:
2026-02-15 18:32:34 +01:00
parent 789c06b842
commit 27f12b2c32
13 changed files with 532 additions and 640 deletions

View File

@@ -4,7 +4,8 @@ Tests for the FormulaEngine facade.
import numpy as np
import pytest
from myfasthtml.core.formula.dsl.exceptions import FormulaSyntaxError, FormulaCycleError
from myfasthtml.core.dsl.exceptions import DSLSyntaxError
from myfasthtml.core.formula.dsl.exceptions import FormulaCycleError
from myfasthtml.core.formula.engine import FormulaEngine
@@ -72,9 +73,9 @@ class TestSetFormula:
assert totals[2] == 50
def test_i_cannot_set_invalid_formula(self):
"""Test that invalid formula syntax raises FormulaSyntaxError."""
"""Test that invalid formula syntax raises DSLSyntaxError."""
engine = make_engine()
with pytest.raises(FormulaSyntaxError):
with pytest.raises(DSLSyntaxError):
engine.set_formula("t", "col", "{Price} * * {Qty}")
def test_i_cannot_set_formula_with_cycle(self):

View File

@@ -11,7 +11,7 @@ from myfasthtml.core.formula.dataclasses import (
LiteralNode,
FormulaDefinition,
)
from myfasthtml.core.formula.dsl.exceptions import FormulaSyntaxError
from myfasthtml.core.dsl.exceptions import DSLSyntaxError
from myfasthtml.core.formula.engine import parse_formula
@@ -177,12 +177,12 @@ def test_i_can_parse_nested_functions():
"123 + + 456", # double operator
])
def test_i_cannot_parse_invalid_syntax(formula_text):
"""Test that invalid syntax raises FormulaSyntaxError."""
with pytest.raises(FormulaSyntaxError):
"""Test that invalid syntax raises DSLSyntaxError."""
with pytest.raises(DSLSyntaxError):
parse_formula(formula_text)
def test_i_cannot_parse_unclosed_brace():
"""Test that an unclosed brace raises FormulaSyntaxError."""
with pytest.raises(FormulaSyntaxError):
"""Test that an unclosed brace raises DSLSyntaxError."""
with pytest.raises(DSLSyntaxError):
parse_formula("{Price")

View File

@@ -30,7 +30,9 @@ def session():
@pytest.fixture
def parent(session):
return SingleInstance(session=session, _id="test_parent_id")
instance = SingleInstance(session=session, _id="test_parent_id")
instance.get_formula_engine = lambda: None
return instance
@pytest.fixture