refact: replace callback with str for arrow in graph_set
This commit is contained in:
parent
f0315d09b9
commit
d1c1b7420d
@ -1,5 +1,4 @@
|
|||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
@ -12,10 +12,9 @@ class Node(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class EdgeOnSet(BaseModel):
|
class EdgeOnSet(BaseModel):
|
||||||
arrow: Callable
|
arrow: str
|
||||||
sources: dict[str, Node]
|
sources: list[Node]
|
||||||
targets: dict[str, Node]
|
targets: list[Node]
|
||||||
edge_kwrds: dict = {}
|
|
||||||
|
|
||||||
|
|
||||||
class GraphSet:
|
class GraphSet:
|
||||||
@ -25,8 +24,8 @@ class GraphSet:
|
|||||||
|
|
||||||
def append(self, edge: EdgeOnSet):
|
def append(self, edge: EdgeOnSet):
|
||||||
self._edges.append(edge)
|
self._edges.append(edge)
|
||||||
self._node_sets.add(frozenset(edge.sources.values()))
|
self._node_sets.add(frozenset(edge.sources))
|
||||||
self._node_sets.add(frozenset(edge.targets.values()))
|
self._node_sets.add(frozenset(edge.targets))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def node_sets(self):
|
def node_sets(self):
|
||||||
|
@ -2,17 +2,13 @@ from plesna.graph.graph_set import EdgeOnSet, GraphSet, Node
|
|||||||
|
|
||||||
|
|
||||||
def test_init():
|
def test_init():
|
||||||
|
graph_set = GraphSet()
|
||||||
|
|
||||||
nodeA = Node(name="A")
|
nodeA = Node(name="A")
|
||||||
nodeB = Node(name="B")
|
nodeB = Node(name="B")
|
||||||
nodeC = Node(name="C")
|
nodeC = Node(name="C")
|
||||||
|
edge1 = EdgeOnSet(arrow="arrow", sources=[nodeA, nodeB], targets=[nodeC])
|
||||||
|
|
||||||
def arrow(sources, targets):
|
|
||||||
targets["C"].infos["res"] = sources["A"].name + sources["B"].name
|
|
||||||
|
|
||||||
edge1 = EdgeOnSet(
|
|
||||||
arrow=arrow, sources={"A": nodeA, "B": nodeB}, targets={"C": nodeC}
|
|
||||||
)
|
|
||||||
graph_set = GraphSet()
|
|
||||||
graph_set.append(edge1)
|
graph_set.append(edge1)
|
||||||
|
|
||||||
assert graph_set.node_sets == {frozenset([nodeA, nodeB]), frozenset([nodeC])}
|
assert graph_set.node_sets == {frozenset([nodeA, nodeB]), frozenset([nodeC])}
|
||||||
|
Loading…
Reference in New Issue
Block a user