Simple test suite added
This commit is contained in:
12
tests/manual_test.py
Normal file
12
tests/manual_test.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import sys
|
||||
from bedit_core.serialization import load, save
|
||||
from bedit_core.bondgraph import causality_inference
|
||||
|
||||
def main(path: str):
|
||||
doc = load(path)
|
||||
for id, root in doc.root.items():
|
||||
doc.root[id] = causality_inference(doc.root[id])
|
||||
save(doc, path)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1])
|
||||
88
tests/unit/test_bondgraph_flatten.py
Normal file
88
tests/unit/test_bondgraph_flatten.py
Normal file
@@ -0,0 +1,88 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from bedit_core.bondgraph import flatten_bondgraph
|
||||
from bedit_core.models import (
|
||||
BondConnection,
|
||||
BondPort,
|
||||
Component,
|
||||
ComponentID,
|
||||
ConnectionID,
|
||||
EquationImplementation,
|
||||
Graph,
|
||||
GraphImplementation,
|
||||
Interface,
|
||||
PortID,
|
||||
SignalDirection,
|
||||
)
|
||||
|
||||
|
||||
def _leaf(name: str, port_id: PortID) -> Component:
|
||||
return Component(
|
||||
name=name,
|
||||
interface=Interface(
|
||||
{port_id: BondPort(name="p", direction=SignalDirection.INPUT)}
|
||||
),
|
||||
parameters={},
|
||||
implementation=EquationImplementation(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_flattens_bonds_across_a_component_boundary() -> None:
|
||||
boundary_id = PortID("boundary")
|
||||
inner_id = PortID("inner")
|
||||
outer_id = PortID("outer")
|
||||
inner = _leaf("Inner", inner_id)
|
||||
subsystem = Component(
|
||||
name="Subsystem",
|
||||
interface=Interface(
|
||||
{
|
||||
boundary_id: BondPort(
|
||||
name="boundary",
|
||||
direction=SignalDirection.INPUT,
|
||||
)
|
||||
}
|
||||
),
|
||||
parameters={},
|
||||
implementation=GraphImplementation(
|
||||
Graph(
|
||||
components={ComponentID("inner"): inner},
|
||||
connections={
|
||||
ConnectionID("inside"): BondConnection(
|
||||
boundary_id,
|
||||
inner_id,
|
||||
)
|
||||
},
|
||||
)
|
||||
),
|
||||
)
|
||||
outer = _leaf("Outer", outer_id)
|
||||
root = Component(
|
||||
name="Root",
|
||||
interface=Interface(),
|
||||
parameters={},
|
||||
implementation=GraphImplementation(
|
||||
Graph(
|
||||
components={
|
||||
ComponentID("subsystem"): subsystem,
|
||||
ComponentID("outer"): outer,
|
||||
},
|
||||
connections={
|
||||
ConnectionID("outside"): BondConnection(
|
||||
outer_id,
|
||||
boundary_id,
|
||||
)
|
||||
},
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
network = flatten_bondgraph(root)
|
||||
boundary = next(port for port in network.ports if port.port_id == boundary_id)
|
||||
|
||||
assert len(network.components) == 4
|
||||
assert len(network.ports) == 3
|
||||
assert len(network.bonds) == 2
|
||||
assert len(network.bonds_for(boundary)) == 2
|
||||
14
tests/unit/test_graphviz_util.py
Normal file
14
tests/unit/test_graphviz_util.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from bedit_core.models import Document
|
||||
from bedit_util.graphviz import document_to_dot
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_dot_contains_component_name_path(minimal_document: Document) -> None:
|
||||
dot = document_to_dot(minimal_document, "Root")
|
||||
|
||||
assert 'label="Root"' in dot
|
||||
assert 'xlabel="Root"' in dot
|
||||
Reference in New Issue
Block a user