Simple test suite added

This commit is contained in:
2026-07-23 16:02:41 +02:00
parent 8e7c463567
commit d050d61701
5 changed files with 191 additions and 26 deletions

View 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