68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from xml.etree import ElementTree as ET
|
|
|
|
from app.main import ReactFlowProjectPayload, build_reactflow_system_xml
|
|
|
|
|
|
class SystemXmlProtocolTests(unittest.TestCase):
|
|
def test_v1_xml_contains_simulation_and_stable_section_order(self) -> None:
|
|
project = ReactFlowProjectPayload(
|
|
name="protocol-test",
|
|
nodes=[
|
|
{
|
|
"id": "cylinder_1",
|
|
"type": "simulationComponent",
|
|
"position": {"x": 12.5, "y": 24.0},
|
|
"data": {
|
|
"label": "source-cylinder",
|
|
"componentType": "cylinder",
|
|
"modelType": "cylinder",
|
|
"ports": ["port_b"],
|
|
"parameters": {"volume": 0.01, "p0": 35000000, "T0": 300},
|
|
},
|
|
}
|
|
],
|
|
edges=[],
|
|
simulation={
|
|
"t_start": 1.0,
|
|
"t_stop": 5.0,
|
|
"step": 0.2,
|
|
"max_step": 0.01,
|
|
"method": "BDF",
|
|
},
|
|
)
|
|
|
|
root = ET.fromstring(build_reactflow_system_xml(project))
|
|
|
|
self.assertEqual(root.tag, "System")
|
|
self.assertEqual(root.attrib["name"], "protocol-test")
|
|
self.assertEqual(root.attrib["schemaVersion"], "1")
|
|
self.assertEqual(root.attrib["unitSystem"], "SI")
|
|
self.assertEqual([child.tag for child in root], ["Simulation", "Components", "Connections"])
|
|
|
|
simulation = root.find("Simulation")
|
|
self.assertIsNotNone(simulation)
|
|
assert simulation is not None
|
|
self.assertEqual(
|
|
simulation.attrib,
|
|
{
|
|
"tStart": "1.0",
|
|
"tStop": "5.0",
|
|
"step": "0.2",
|
|
"maxStep": "0.01",
|
|
"method": "BDF",
|
|
},
|
|
)
|
|
|
|
component = root.find("./Components/Component")
|
|
self.assertIsNotNone(component)
|
|
assert component is not None
|
|
self.assertEqual(component.attrib["id"], "cylinder_1")
|
|
self.assertEqual(component.find("./Parameter[@name='p0']").attrib["value"], "35000000")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|