Skip to content

Commit

Permalink
[test] Extra partial serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-lty committed Dec 13, 2024
1 parent 357575d commit dbafe84
Showing 1 changed file with 61 additions and 5 deletions.
66 changes: 61 additions & 5 deletions tests/test_graphIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ class SimpleNode(desc.Node):
]


class NodeWithListAttributes(desc.Node):
inputs = [
desc.ListAttribute(
name="listInput",
label="List Input",
description="",
elementDesc=desc.File(name="file", label="File", description="", value=""),
exposed=True,
),
desc.GroupAttribute(
name="group",
label="Group",
description="",
groupDesc=[
desc.ListAttribute(
name="listInput",
label="List Input",
description="",
elementDesc=desc.File(name="file", label="File", description="", value=""),
exposed=True,
),
],
),
]


def compareGraphsContent(graphA: Graph, graphB: Graph) -> bool:
"""Returns whether the content (node and deges) of two graphs are considered identical.
Expand All @@ -26,9 +52,10 @@ def _buildNodesSet(graph: Graph):
def _buildEdgesSet(graph: Graph):
return set([(edge.src.fullName, edge.dst.fullName) for edge in graph.edges])

return _buildNodesSet(graphA) == _buildNodesSet(graphB) and _buildEdgesSet(graphA) == _buildEdgesSet(
graphB
)
nodesSetA, edgesSetA = _buildNodesSet(graphA), _buildEdgesSet(graphA)
nodesSetB, edgesSetB = _buildNodesSet(graphB), _buildEdgesSet(graphB)

return nodesSetA == nodesSetB and edgesSetA == edgesSetB


class TestImportGraphContent:
Expand Down Expand Up @@ -197,7 +224,7 @@ def test_serializeAllNodesIsSimilarToStandardSerialization(self):
assert compareGraphsContent(graph, graphA)
assert compareGraphsContent(graphA, graphB)

def test_serializeSingleNodeWithInputConnection(self):
def test_singleNodeWithInputConnectionFromNonSerializedNodeRemovesEdge(self):
graph = Graph("")

with registeredNodeTypes([SimpleNode]):
Expand All @@ -215,6 +242,36 @@ def test_serializeSingleNodeWithInputConnection(self):
assert len(otherGraph.nodes) == 1
assert len(otherGraph.edges) == 0

def test_serializeSingleNodeWithInputConnectionToListAttributeRemovesListEntry(self):
graph = Graph("")

with registeredNodeTypes([SimpleNode, NodeWithListAttributes]):
nodeA = graph.addNewNode(SimpleNode.__name__)
nodeB = graph.addNewNode(NodeWithListAttributes.__name__)

nodeB.listInput.append("")
graph.addEdge(nodeA.output, nodeB.listInput.at(0))

otherGraph = Graph("")
otherGraph._deserialize(graph.serializePartial([nodeB]))

assert len(otherGraph.node(nodeB.name).listInput) == 0

def test_serializeSingleNodeWithInputConnectionToNestedListAttributeRemovesListEntry(self):
graph = Graph("")

with registeredNodeTypes([SimpleNode, NodeWithListAttributes]):
nodeA = graph.addNewNode(SimpleNode.__name__)
nodeB = graph.addNewNode(NodeWithListAttributes.__name__)

nodeB.group.listInput.append("")
graph.addEdge(nodeA.output, nodeB.group.listInput.at(0))

otherGraph = Graph("")
otherGraph._deserialize(graph.serializePartial([nodeB]))

assert len(otherGraph.node(nodeB.name).group.listInput) == 0


class TestGraphCopy:
def test_graphCopyIsIdenticalToOriginalGraph(self):
Expand All @@ -240,4 +297,3 @@ def test_graphCopyWithUnknownNodeTypesDiffersFromOriginalGraph(self):

graphCopy = graph.copy()
assert not compareGraphsContent(graph, graphCopy)

0 comments on commit dbafe84

Please sign in to comment.