1+ #!/usr/bin/env python
2+ # coding:utf-8
3+
4+ import os
5+ import tempfile
6+
7+ from meshroom .core .graph import Graph , loadGraph
8+ from meshroom .core .node import CompatibilityNode
9+ from meshroom .core .attribute import GroupAttribute
10+
11+ GROUPATTRIBUTES_FIRSTGROUP_NB_CHILDREN = 8 # 3 ints, 1 bool, 1 group, 1 float nested in the group, 2 lists
12+ GROUPATTRIBUTES_FIRSTGROUP_NESTED_NB_CHILDREN = 1 # 1 float
13+ GROUPATTRIBUTES_OUTPUTGROUP_NB_CHILDREN = 1 # 1 bool
14+ GROUPATTRIBUTES_FIRSTGROUP_DEPTHS = [1 , 1 , 1 , 1 , 1 , 2 , 1 , 1 ]
15+
16+ def test_saveLoadGroupConnections ():
17+ """
18+ Ensure that connecting attributes that are part of GroupAttributes does not cause
19+ their nodes to have CompatibilityIssues when re-opening them.
20+ """
21+ graph = Graph ("Connections between GroupAttributes" )
22+
23+ # Create two "GroupAttributes" nodes with their default parameters
24+ nodeA = graph .addNewNode ("GroupAttributes" )
25+ nodeB = graph .addNewNode ("GroupAttributes" )
26+
27+ # Connect attributes within groups at different depth levels
28+ graph .addEdges (
29+ (nodeA .firstGroup .firstGroupIntA , nodeB .firstGroup .firstGroupIntA ),
30+ (nodeA .firstGroup .nestedGroup .nestedGroupFloat , nodeB .firstGroup .nestedGroup .nestedGroupFloat )
31+ )
32+
33+ # Save the graph in a file
34+ graphFile = os .path .join (tempfile .mkdtemp (), "test_io_group_connections.mg" )
35+ graph .save (graphFile )
36+
37+ # Reload the graph
38+ graph = loadGraph (graphFile )
39+
40+ # Ensure the nodes are not CompatibilityNodes
41+ for node in graph .nodes :
42+ assert not isinstance (node , CompatibilityNode )
43+
44+
45+ def test_groupAttributesFlatChildren ():
46+ """
47+ Check that the list of static flat children is correct, even with list elements.
48+ """
49+ graph = Graph ("Children of GroupAttributes" )
50+
51+ # Create two "GroupAttributes" nodes with their default parameters
52+ node = graph .addNewNode ("GroupAttributes" )
53+
54+ intAttr = node .attribute ("exposedInt" )
55+ assert not isinstance (intAttr , GroupAttribute )
56+ assert len (intAttr .flatStaticChildren ) == 0 # Not a Group, cannot have any child
57+
58+ inputGroup = node .attribute ("firstGroup" )
59+ assert isinstance (inputGroup , GroupAttribute )
60+ assert len (inputGroup .flatStaticChildren ) == GROUPATTRIBUTES_FIRSTGROUP_NB_CHILDREN
61+
62+ # Add an element to a list within the group and check the number of children hasn't changed
63+ groupedList = node .attribute ("firstGroup.singleGroupedList" )
64+ groupedList .insert (0 , 30 )
65+ assert len (groupedList .flatStaticChildren ) == 0 # Not a Group, elements are not counted as children
66+ assert len (inputGroup .flatStaticChildren ) == GROUPATTRIBUTES_FIRSTGROUP_NB_CHILDREN
67+
68+ nestedGroup = node .attribute ("firstGroup.nestedGroup" )
69+ assert isinstance (nestedGroup , GroupAttribute )
70+ assert len (nestedGroup .flatStaticChildren ) == GROUPATTRIBUTES_FIRSTGROUP_NESTED_NB_CHILDREN
71+
72+ outputGroup = node .attribute ("outputGroup" )
73+ assert isinstance (outputGroup , GroupAttribute )
74+ assert len (outputGroup .flatStaticChildren ) == GROUPATTRIBUTES_OUTPUTGROUP_NB_CHILDREN
75+
76+
77+ def test_groupAttributesDepthLevels ():
78+ """
79+ Check that the depth level of children attributes is correctly set.
80+ """
81+ graph = Graph ("Children of GroupAttributes" )
82+
83+ # Create two "GroupAttributes" nodes with their default parameters
84+ node = graph .addNewNode ("GroupAttributes" )
85+ inputGroup = node .attribute ("firstGroup" )
86+ assert isinstance (inputGroup , GroupAttribute )
87+ assert inputGroup .depth == 0 # Root level
88+
89+ cnt = 0
90+ for child in inputGroup .flatStaticChildren :
91+ assert child .depth == GROUPATTRIBUTES_FIRSTGROUP_DEPTHS [cnt ]
92+ cnt = cnt + 1
93+
94+ outputGroup = node .attribute ("outputGroup" )
95+ assert isinstance (outputGroup , GroupAttribute )
96+ assert outputGroup .depth == 0
97+ for child in outputGroup .flatStaticChildren : # Single element in the group
98+ assert child .depth == 1
99+
100+
101+ intAttr = node .attribute ("exposedInt" )
102+ assert not isinstance (intAttr , GroupAttribute )
103+ assert intAttr .depth == 0
0 commit comments