From 7b5d84f649f2bacb49cf791e165e5fa36022dbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Mon, 21 Oct 2024 17:47:43 +0200 Subject: [PATCH] [tests] Add test node with `GroupAttributes` and unit test 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. --- tests/nodes/test/GroupAttributes.py | 153 ++++++++++++++++++++++++++++ tests/test_io.py | 37 +++++++ 2 files changed, 190 insertions(+) create mode 100644 tests/nodes/test/GroupAttributes.py create mode 100644 tests/test_io.py diff --git a/tests/nodes/test/GroupAttributes.py b/tests/nodes/test/GroupAttributes.py new file mode 100644 index 0000000000..38d8c9f7fe --- /dev/null +++ b/tests/nodes/test/GroupAttributes.py @@ -0,0 +1,153 @@ +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="Integer in group.", + value=1024, + range=(-1, 2000, 10), + exposed=True, + ), + desc.IntParam( + name="firstGroupIntB", + label="Integer B", + description="Integer in group.", + value=1024, + range=(-1, 2000, 10), + exposed=True, + ), + desc.IntParam( + name="firstGroupIntC", + label="Integer C", + description="Integer in group.", + value=64, + range=(0, 500, 1), + exposed=True, + ), + desc.BoolParam( + name="firstGroupBool", + label="Boolean", + description="Boolean in group.", + value=True, + advanced=True, + 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.ChoiceParam( + name="listedGroupChoice", + label="Choice", + description="Choice attribute in a group in a list within a group.", + value="a", + values=["a", "b", "c", "d"], + exposed=True, + ), + desc.FloatParam( + name="listedGroupFloat", + label="Floating Number", + description="Floating number in a group in a list within a group.", + value=2.5, + range=(0.5, 30.0, 0.1), + exposed=True, + ), + 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.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, + ), + ], + ), + ] \ No newline at end of file diff --git a/tests/test_io.py b/tests/test_io.py new file mode 100644 index 0000000000..9c3b6c9762 --- /dev/null +++ b/tests/test_io.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# coding:utf-8 + +import os +import tempfile + +from meshroom.core import desc, registerNodeType +from meshroom.core.graph import Graph, loadGraph +from meshroom.core.node import CompatibilityNode + +def test_io_group_connections(): + """ + 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)