规范仿真模型库并完善前端交互
归档仿真模型并补充组件目录、建模规范与校验。 完善控制台、默认节点、视图适配及前端自动化测试。
This commit is contained in:
1 parent
f7f1078911
commit
bbc88a6bbb
71 files changed
+4574
-806
No files matched your search
@@ -0,0 +1,87 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.simulation.components.experimental.library import LIBRARY
|
||||
from app.simulation.core.base import AlgebraicComponent
|
||||
from app.simulation.core.catalog import ComponentDisplaySpec, PortDisplaySpec
|
||||
from app.simulation.core.medium import IdealGasMedium
|
||||
from app.simulation.core.ports import PortDefinition
|
||||
from app.simulation.registry import (
|
||||
COMPONENT_LIBRARY_REGISTRY,
|
||||
COMPONENT_MODEL_REGISTRY,
|
||||
discover_component_registries,
|
||||
validate_component_model_class,
|
||||
)
|
||||
|
||||
|
||||
class ComponentRegistryTests(unittest.TestCase):
|
||||
def test_manifest_is_the_only_public_model_source(self) -> None:
|
||||
libraries, models = discover_component_registries()
|
||||
|
||||
self.assertEqual(libraries, COMPONENT_LIBRARY_REGISTRY)
|
||||
self.assertEqual(models, COMPONENT_MODEL_REGISTRY)
|
||||
self.assertEqual(
|
||||
tuple(models),
|
||||
("cylinder", "tank", "pipe", "orifice", "tee"),
|
||||
)
|
||||
self.assertNotIn(
|
||||
"app.simulation.components.experimental.flow.pipe:Pipe",
|
||||
LIBRARY.models,
|
||||
)
|
||||
|
||||
def test_every_public_model_owns_its_catalog_contract(self) -> None:
|
||||
for model_type, spec in COMPONENT_MODEL_REGISTRY.items():
|
||||
with self.subTest(model_type=model_type):
|
||||
declarations = spec.component_class.__dict__
|
||||
self.assertIn("MODEL_VERSION", declarations)
|
||||
self.assertIn("DISPLAY", declarations)
|
||||
self.assertIn("create", declarations)
|
||||
self.assertEqual(spec.display.library_id, LIBRARY.id)
|
||||
self.assertIn(
|
||||
spec.display.category_id,
|
||||
LIBRARY.category_by_id,
|
||||
)
|
||||
|
||||
def test_display_ports_must_match_physical_ports(self) -> None:
|
||||
class BrokenDisplayComponent(AlgebraicComponent):
|
||||
MODEL_TYPE = "broken_display"
|
||||
MODEL_VERSION = "1.0.0"
|
||||
PORTS = (
|
||||
PortDefinition.pneumatic(
|
||||
"port_a",
|
||||
nominal_role="bidirectional",
|
||||
),
|
||||
)
|
||||
PARAMETERS = ()
|
||||
RESULT_VARIABLES = ()
|
||||
DISPLAY = ComponentDisplaySpec(
|
||||
label="错误显示模型",
|
||||
library_id="experimental",
|
||||
category_id="flow",
|
||||
symbol="generic",
|
||||
ports=(PortDisplaySpec("port_b", "right"),),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create(
|
||||
cls,
|
||||
*,
|
||||
name: str,
|
||||
medium: IdealGasMedium,
|
||||
parameters,
|
||||
):
|
||||
return cls(name)
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"display ports must exactly match",
|
||||
):
|
||||
validate_component_model_class(
|
||||
BrokenDisplayComponent,
|
||||
library=LIBRARY,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user