import sys import os # Ensure the src package is on the Python path for tests ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) SRC = os.path.join(ROOT, "src") if SRC not in sys.path: sys.path.insert(0, SRC) from idea74_polyport_studio_interactive import parse_dsl def test_parse_basic_dsl(): dsl = ( "ASSETS: AAPL, MSFT, GOOGL\n" "OBJECTIVES: maximize_return\n" "CONSTRAINTS: budget=1.0; max_risk=0.05; liquidity=0.2" ) result = parse_dsl(dsl) # Basic shape checks assert "LocalProblem" in result lp = result["LocalProblem"] assert isinstance(lp, dict) assert lp.get("Assets") == ["AAPL", "MSFT", "GOOGL"] assert lp.get("Objectives") == ["maximize_return"] constraints = lp.get("Constraints") assert isinstance(constraints, dict) # Check a couple of parsed values assert constraints.get("budget") == 1.0 assert constraints.get("max_risk") == 0.05