fix: align mechanical dynamic port validation

This commit is contained in:
huojiarong committed 2026-08-15 12:57:03 +00:00
1 parent 6a064892e2
commit 4e0b9fd8cc
7 files changed
+105 -7

No files matched your search

+24
View File
@@ -427,6 +427,30 @@ class AmesimMechanicalXmlTests(unittest.TestCase):
self.assertNotIn("node_1.port_21.f", result["series"])
self.assertAlmostEqual(result["series"]["mass_1.a"][0], 5.0)
def test_force_node_rejects_connection_to_inactive_reserved_port(self) -> None:
project = force_node_mass_project(2)
edge = next(
edge
for edge in project.edges
if edge.id == "edge-mass"
)
edge.sourceHandle = "port_9"
with self.assertRaisesRegex(ValueError, "missing endpoint node_1.port_9"):
build_reactflow_system_xml(project)
with self.assertRaisesRegex(ValueError, "port_9 is not active"):
compile_reactflow_network(project)
xml = build_reactflow_system_xml(force_node_mass_project(2))
root = ET.fromstring(xml)
endpoint = root.find("./Connections/Connection[@id='edge-mass']/Endpoint[@component='node_1']")
assert endpoint is not None
endpoint.set("port", "port_9")
report = validate_system_xml_document(ET.tostring(root, encoding="utf-8"))
self.assertFalse(report.valid)
self.assertIn("ENDPOINT_PORT_INACTIVE", {issue.code for issue in report.issues})
def test_elastic_contact_project_compiles_and_simulates(self) -> None:
xml = build_reactflow_system_xml(elastic_contact_project())
report = validate_system_xml_document(xml)