-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_attributes.py
More file actions
144 lines (99 loc) · 3.77 KB
/
test_attributes.py
File metadata and controls
144 lines (99 loc) · 3.77 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
from meshroom.core.graph import Graph
import pytest
import logging
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')]
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
@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