规范化xml内容,并在xml中添加仿真设置,规范化版本号等内容,补充xml规范md文件
This commit is contained in:
1 parent
c52266ba11
commit
104d41d294
6 files changed
+254
-2
No files matched your search
@@ -0,0 +1,67 @@
|
||||
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()
|
||||
Reference in new issue
Block a user