65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import unittest
|
|
|
|
from equicompiler_algebraic_portfolio_dsl_to_.core import parse_dsl_to_ir
|
|
|
|
|
|
class TestCore(unittest.TestCase):
|
|
def test_parse_basic(self):
|
|
dsl = (
|
|
"assets: AAPL, MSFT, GOOG\n"
|
|
"objectives: maximize_return\n"
|
|
"constraints: max_drawdown=0.2, var=0.95"
|
|
)
|
|
ir = parse_dsl_to_ir(dsl)
|
|
self.assertEqual(ir["assets"], ["AAPL", "MSFT", "GOOG"])
|
|
self.assertIn("maximize_return", ir["objectives"])
|
|
self.assertEqual(ir["constraints"]["max_drawdown"], "0.2")
|
|
self.assertEqual(ir["constraints"]["var"], "0.95")
|
|
|
|
def test_execution_policy_parsing(self):
|
|
dsl = (
|
|
"assets: AAPL, MSFT, GOOG\n"
|
|
"objectives: maximize_return\n"
|
|
"constraints: max_drawdown=0.2, var=0.95\n"
|
|
"execution_policy: offline, delta_sync"
|
|
)
|
|
ir = parse_dsl_to_ir(dsl)
|
|
self.assertIn("execution_policy", ir)
|
|
self.assertEqual(ir["execution_policy"], ["offline", "delta_sync"])
|
|
|
|
def test_goC_skeleton_presence(self):
|
|
dsl = (
|
|
"assets: AAPL, MSFT, GOOG\n"
|
|
"objectives: maximize_return\n"
|
|
"constraints: max_drawdown=0.2, var=0.95"
|
|
)
|
|
ir = parse_dsl_to_ir(dsl)
|
|
self.assertIn("graph_of_contracts", ir)
|
|
goC = ir["graph_of_contracts"]
|
|
self.assertIsInstance(goC, dict)
|
|
self.assertIn("version", goC)
|
|
self.assertIn("metadata", goC)
|
|
self.assertIn("generated_at", goC["metadata"])
|
|
self.assertIn("registry_digest", goC["metadata"])
|
|
def test_attestations_present_and_digest_format(self):
|
|
dsl = (
|
|
"assets: AAPL, MSFT, GOOG\n"
|
|
"objectives: maximize_return\n"
|
|
"constraints: max_drawdown=0.2, var=0.95"
|
|
)
|
|
ir = parse_dsl_to_ir(dsl)
|
|
# Attestations should be present and include digest fields with hex digest
|
|
self.assertIn("attestations", ir)
|
|
attestations = ir["attestations"]
|
|
self.assertIsInstance(attestations, list)
|
|
self.assertGreaterEqual(len(attestations), 1)
|
|
import re
|
|
for att in attestations:
|
|
self.assertIn("digest", att)
|
|
self.assertIsInstance(att["digest"], str)
|
|
self.assertRegex(att["digest"], r"^[0-9a-f]{64}$")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|