[tests] Add test node with GroupAttributes and unit tests

The test ensures that if the attributes within `GroupAttributes` are
connected to each other, the graph can be saved and reloaded without
triggering compatibility issues for these nodes.
This commit is contained in:
Candice Bentéjac 2024-10-21 17:47:43 +02:00
parent 521d7b7816
commit 50c4347db0
2 changed files with 255 additions and 0 deletions

View file

@ -0,0 +1,152 @@
from meshroom.core import desc
class GroupAttributes(desc.Node):
documentation = """ Test node to connect GroupAttributes to other GroupAttributes. """
category = 'Test'
# Inputs to the node
inputs = [
desc.GroupAttribute(
name="firstGroup",
label="First Group",
description="Group at the root level.",
group=None,
exposed=True,
groupDesc=[
desc.IntParam(
name="firstGroupIntA",
label="Integer A",
description="First integer in group.",
value=1024,
range=(-1, 2000, 10),
exposed=True,
),
desc.BoolParam(
name="firstGroupBool",
label="Boolean",
description="Boolean in group.",
value=True,
advanced=True,
exposed=True,
),
desc.ChoiceParam(
name="firstGroupExclusiveChoiceParam",
label="Exclusive Choice Param",
description="Exclusive choice parameter.",
value="one",
values=["one", "two", "three", "four"],
exclusive=True,
exposed=True,
),
desc.ChoiceParam(
name="firstGroupChoiceParam",
label="ChoiceParam",
description="Non-exclusive choice parameter.",
value=["one", "two"],
values=["one", "two", "three", "four"],
exclusive=False,
exposed=True
),
desc.GroupAttribute(
name="nestedGroup",
label="Nested Group",
description="A group within a group.",
group=None,
exposed=True,
groupDesc=[
desc.FloatParam(
name="nestedGroupFloat",
label="Floating Number",
description="Floating number in group.",
value=1.0,
range=(0.0, 100.0, 0.01),
exposed=True
),
],
),
desc.ListAttribute(
name="groupedList",
label="Grouped List",
description="List of groups within a group.",
advanced=True,
exposed=True,
elementDesc=desc.GroupAttribute(
name="listedGroup",
label="Listed Group",
description="Group in a list within a group.",
joinChar=":",
group=None,
groupDesc=[
desc.IntParam(
name="listedGroupInt",
label="Integer 1",
description="Integer in a group in a list within a group.",
value=12,
range=(3, 24, 1),
exposed=True,
),
],
),
),
desc.ListAttribute(
name="singleGroupedList",
label="Grouped List With Single Element",
description="List of integers within a group.",
advanced=True,
exposed=True,
elementDesc=desc.IntParam(
name="listedInt",
label="Integer In List",
description="Integer in a list within a group.",
value=40,
),
),
],
),
desc.IntParam(
name="exposedInt",
label="Exposed Integer",
description="Integer at the rool level, exposed.",
value=1000,
exposed=True,
),
desc.BoolParam(
name="unexposedBool",
label="Unexposed Boolean",
description="Boolean at the root level, unexposed.",
value=True,
),
desc.GroupAttribute(
name="inputGroup",
label="Input Group",
description="A group set as an input.",
group=None,
groupDesc=[
desc.BoolParam(
name="inputBool",
label="Input Bool",
description="",
value=False,
),
],
),
]
outputs = [
desc.GroupAttribute(
name="outputGroup",
label="Output Group",
description="A group set as an output.",
group=None,
exposed=True,
groupDesc=[
desc.BoolParam(
name="outputBool",
label="Output Bool",
description="",
value=False,
exposed=True,
),
],
),
]

View file

@ -0,0 +1,103 @@
#!/usr/bin/env python
# coding:utf-8
import os
import tempfile
from meshroom.core.graph import Graph, loadGraph
from meshroom.core.node import CompatibilityNode
from meshroom.core.attribute import GroupAttribute
GROUPATTRIBUTES_FIRSTGROUP_NB_CHILDREN = 8 # 1 int, 1 exclusive choice param, 1 choice param, 1 bool, 1 group, 1 float nested in the group, 2 lists
GROUPATTRIBUTES_FIRSTGROUP_NESTED_NB_CHILDREN = 1 # 1 float
GROUPATTRIBUTES_OUTPUTGROUP_NB_CHILDREN = 1 # 1 bool
GROUPATTRIBUTES_FIRSTGROUP_DEPTHS = [1, 1, 1, 1, 1, 2, 1, 1]
def test_saveLoadGroupConnections():
"""
Ensure that connecting attributes that are part of GroupAttributes does not cause
their nodes to have CompatibilityIssues when re-opening them.
"""
graph = Graph("Connections between GroupAttributes")
# Create two "GroupAttributes" nodes with their default parameters
nodeA = graph.addNewNode("GroupAttributes")
nodeB = graph.addNewNode("GroupAttributes")
# Connect attributes within groups at different depth levels
graph.addEdges(
(nodeA.firstGroup.firstGroupIntA, nodeB.firstGroup.firstGroupIntA),
(nodeA.firstGroup.nestedGroup.nestedGroupFloat, nodeB.firstGroup.nestedGroup.nestedGroupFloat)
)
# Save the graph in a file
graphFile = os.path.join(tempfile.mkdtemp(), "test_io_group_connections.mg")
graph.save(graphFile)
# Reload the graph
graph = loadGraph(graphFile)
# Ensure the nodes are not CompatibilityNodes
for node in graph.nodes:
assert not isinstance(node, CompatibilityNode)
def test_groupAttributesFlatChildren():
"""
Check that the list of static flat children is correct, even with list elements.
"""
graph = Graph("Children of GroupAttributes")
# Create two "GroupAttributes" nodes with their default parameters
node = graph.addNewNode("GroupAttributes")
intAttr = node.attribute("exposedInt")
assert not isinstance(intAttr, GroupAttribute)
assert len(intAttr.flatStaticChildren) == 0 # Not a Group, cannot have any child
inputGroup = node.attribute("firstGroup")
assert isinstance(inputGroup, GroupAttribute)
assert len(inputGroup.flatStaticChildren) == GROUPATTRIBUTES_FIRSTGROUP_NB_CHILDREN
# Add an element to a list within the group and check the number of children hasn't changed
groupedList = node.attribute("firstGroup.singleGroupedList")
groupedList.insert(0, 30)
assert len(groupedList.flatStaticChildren) == 0 # Not a Group, elements are not counted as children
assert len(inputGroup.flatStaticChildren) == GROUPATTRIBUTES_FIRSTGROUP_NB_CHILDREN
nestedGroup = node.attribute("firstGroup.nestedGroup")
assert isinstance(nestedGroup, GroupAttribute)
assert len(nestedGroup.flatStaticChildren) == GROUPATTRIBUTES_FIRSTGROUP_NESTED_NB_CHILDREN
outputGroup = node.attribute("outputGroup")
assert isinstance(outputGroup, GroupAttribute)
assert len(outputGroup.flatStaticChildren) == GROUPATTRIBUTES_OUTPUTGROUP_NB_CHILDREN
def test_groupAttributesDepthLevels():
"""
Check that the depth level of children attributes is correctly set.
"""
graph = Graph("Children of GroupAttributes")
# Create two "GroupAttributes" nodes with their default parameters
node = graph.addNewNode("GroupAttributes")
inputGroup = node.attribute("firstGroup")
assert isinstance(inputGroup, GroupAttribute)
assert inputGroup.depth == 0 # Root level
cnt = 0
for child in inputGroup.flatStaticChildren:
assert child.depth == GROUPATTRIBUTES_FIRSTGROUP_DEPTHS[cnt]
cnt = cnt + 1
outputGroup = node.attribute("outputGroup")
assert isinstance(outputGroup, GroupAttribute)
assert outputGroup.depth == 0
for child in outputGroup.flatStaticChildren: # Single element in the group
assert child.depth == 1
intAttr = node.attribute("exposedInt")
assert not isinstance(intAttr, GroupAttribute)
assert intAttr.depth == 0