-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_attributes.py
More file actions
235 lines (169 loc) · 6.52 KB
/
Copy pathtest_attributes.py
File metadata and controls
235 lines (169 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import logging
import pytest
from meshroom.core.attribute import Attribute
from meshroom.core.graph import Graph
from tests.utils import registerNodeDesc
from tests.nodes.test.nodeValidators import NodeWithValidators
logger = logging.getLogger('test')
valid3DExtensionFiles = [(f'test.{ext}', True) for ext in ('obj', 'stl', 'fbx', 'gltf', 'abc', 'ply', 'usda', 'usdc')]
invalid3DExtensionFiles = [(f'test.{ext}', False) for ext in ('', 'exe', 'jpg', 'png', 'py')]
valid2DSemantics= [(semantic, True) for semantic in ('image', 'imageList', 'sequence')]
invalid2DSemantics = [(semantic, False) for semantic in ('3d', '', 'multiline', 'color/hue')]
registerNodeDesc(NodeWithValidators)
validTextExtensionFiles = [(f'test{ext}', True) for ext in ('.txt', '.json', '.log', '.csv', '.md')]
invalidTextExtensionFiles = [(f'test{ext}', False) for ext in ('', '.exe', '.jpg', '.obj', '.py')]
def test_attribute_retrieve_linked_input_and_output_attributes():
"""
Check that an attribute can retrieve the linked input and output attributes
"""
# n0 -- n1 -- n2
# \ \
# ---------- n3
g = Graph('')
n0 = g.addNewNode('Ls', input='')
n1 = g.addNewNode('Ls', input=n0.output)
n2 = g.addNewNode('Ls', input=n1.output)
n3 = g.addNewNode('AppendFiles', input=n1.output, input2=n2.output)
# check that the attribute can retrieve its linked input attributes
assert n0.output.hasAnyOutputLinks
assert not n3.output.hasAnyOutputLinks
assert len(n0.input.allInputLinks) == 0
assert len(n1.input.allInputLinks) == 1
assert n1.input.allInputLinks[0] == n0.output
assert len(n1.output.allOutputLinks) == 2
assert n1.output.allOutputLinks[0] == n2.input
assert n1.output.allOutputLinks[1] == n3.input
n0.graph = None
# Bounding cases
assert not n0.output.hasAnyOutputLinks
assert len(n0.input.allInputLinks) == 0
assert len(n0.output.allOutputLinks) == 0
@pytest.mark.parametrize("givenFile,expected", valid3DExtensionFiles + invalid3DExtensionFiles)
def test_attribute_is3D_file_extensions(givenFile, expected):
"""
Check what makes an attribute a valid 3d media
"""
g = Graph('')
n0 = g.addNewNode('Ls', input='')
# Given
assert not n0.input.is3dDisplayable
# When
n0.input.value = givenFile
# Then
assert n0.input.is3dDisplayable == expected
def test_attribute_i3D_by_description_semantic():
""" """
# Given
g = Graph('')
n0 = g.addNewNode('Ls', input='')
assert not n0.output.is3dDisplayable
# When
n0.output.desc._semantic = "3d"
# Then
assert n0.output.is3dDisplayable
@pytest.mark.parametrize("givenSemantic,expected", valid2DSemantics + invalid2DSemantics)
def test_attribute_is2D_file_semantic(givenSemantic, expected):
"""
Check what makes an attribute a valid 2d media
"""
g = Graph('')
n0 = g.addNewNode('Ls', input='')
# Given
n0.input.desc._semantic = ""
assert not n0.input.is2dDisplayable
# When
n0.input.desc._semantic = givenSemantic
# Then
assert n0.input.is2dDisplayable == expected
def test_attribute_notEmpty_validation():
# Given
g = Graph('')
node = g.addNewNode('NodeWithValidators')
# When
node.mandatory.value = ''
# Then
assert not node.mandatory.isValid
assert len(node.mandatory.getErrorMessages()) == 1
assert node.mandatory.isMandatory is True
assert node.hasInvalidAttribute
# When
node.mandatory.value = 'test'
# Then
assert node.mandatory.isValid
assert len(node.mandatory.getErrorMessages()) == 0
assert not node.hasInvalidAttribute
def test_attribute_range_validation():
# Given
g = Graph('')
node = g.addNewNode('NodeWithValidators')
node.mandatory.value = 'test'
# When
node.floatRange.value = 2.0
# Then
assert not node.floatRange.isValid
assert len(node.floatRange.getErrorMessages()) == 2
assert node.mandatory.isMandatory is True
assert node.hasInvalidAttribute
# When
node.floatRange.value = 0.25
# Then
assert node.floatRange.isValid
assert len(node.floatRange.getErrorMessages()) == 0
assert not node.hasInvalidAttribute
@pytest.mark.parametrize("givenFile,expected", validTextExtensionFiles + invalidTextExtensionFiles)
def test_attribute_isText_file_extensions(givenFile, expected):
"""
Check what makes an attribute a valid text file
"""
g = Graph('')
n0 = g.addNewNode('Ls', input='')
# Given
assert not n0.input.isTextDisplayable
# When
n0.input.value = givenFile
# Then
assert n0.input.isTextDisplayable == expected
def test_attribute_isText_by_description_semantic():
"""
Check that an attribute with semantic 'textFile' is considered a text file
"""
# Given
g = Graph('')
n0 = g.addNewNode('Ls', input='')
# The input attribute has an empty default value, so it is not text displayable
assert not n0.input.isTextDisplayable
# When
n0.input.desc._semantic = "textFile"
# Then
assert n0.input.isTextDisplayable
def test_attribute_isInsideList():
"""
Check whether an attribute is, either directly or indirectly, contained within a ListAttribute.
"""
graph = Graph("")
node = graph.addNewNode("GroupAttributes")
# IntParam within a GroupAttribute: it has a parent, but it is not inside a list
attr1 = node.attribute("firstGroup.firstGroupIntA")
assert attr1.root
assert attr1.depth == 1
assert not attr1.isInsideList
# FloatParam within a nested GroupAttribute: it has parents, but it is not inside a list
attr2 = node.attribute("firstGroup.nestedGroup.nestedGroupFloat")
assert attr2.root
assert attr2.depth == 2
assert not attr2.isInsideList
# ListAttribute within a GroupAttribute: it has a parent but is not inside a list
attr3 = node.attribute("firstGroup.singleGroupedList")
assert attr3.root
assert attr3.depth == 1
assert not attr3.isInsideList
# Insert an IntParam into the ListAttribute: the list attribute is not inside a list, but the IntParam is inside a list
attr3.insert(0, 1)
# Check that the value was correctly inserted
assert isinstance(attr3.value[0], Attribute)
assert attr3.value[0].value == 1
assert not attr3.isInsideList # Check that the ListAttribute itself is still not inside a list
# Check that the IntParam inside the ListAttribute is considered to be inside a list
assert attr3.value[0].root
assert attr3.value[0].depth == 2
assert attr3.value[0].isInsideList