-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_listAttribute.py
More file actions
157 lines (118 loc) · 5.67 KB
/
test_listAttribute.py
File metadata and controls
157 lines (118 loc) · 5.67 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
from meshroom.core import desc
from meshroom.core.graph import Graph
from .utils import registerNodeDesc, unregisterNodeDesc
class NodeWithListAttribute(desc.Node):
inputs = [
desc.ListAttribute(
name="listInput",
label="List Input",
description="ListAttribute of StringParams.",
elementDesc=desc.StringParam(name="value", label="Value", description="", value=""),
)
]
class TestListAttribute:
@classmethod
def setup_class(cls):
registerNodeDesc(NodeWithListAttribute)
@classmethod
def teardown_class(cls):
unregisterNodeDesc(NodeWithListAttribute)
def test_lengthUsesLinkParam(self):
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
nodeA.listInput.connectTo(nodeB.listInput)
nodeA.listInput.append("test")
assert len(nodeB.listInput) == 1
def test_iterationUsesLinkParam(self):
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
nodeA.listInput.connectTo(nodeB.listInput)
nodeA.listInput.extend(["A", "B", "C"])
for value in nodeB.listInput:
assert value.node == nodeA
def test_elementAccessUsesLinkParam(self):
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
nodeA.listInput.connectTo(nodeB.listInput)
nodeA.listInput.extend(["A", "B", "C"])
assert nodeB.listInput.at(0).node == nodeA
assert nodeB.listInput.index(nodeB.listInput.at(0)) == 0
def test_connectToTwoListAttributesReplacesLink(self):
"""
Test that connecting two different ListAttributes to the same destination
ListAttribute using connectTo replaces the first link with the second one.
"""
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
nodeC = graph.addNewNode(NodeWithListAttribute.__name__)
nodeA.listInput.extend(["A1", "A2", "A3"])
nodeB.listInput.extend(["B1", "B2"])
# First connection: nodeA.listInput -> nodeC.listInput
nodeA.listInput.connectTo(nodeC.listInput)
assert nodeC.listInput.isLink
assert len(nodeC.listInput) == 3
assert nodeC.listInput.at(0).node == nodeA
# Second connection replaces the first (connectTo disconnects root)
nodeB.listInput.connectTo(nodeC.listInput)
assert nodeC.listInput.isLink
assert len(nodeC.listInput) == 2
assert nodeC.listInput.at(0).node == nodeB
assert nodeC.listInput.at(1).node == nodeB
assert not nodeA.listInput.hasAnyOutputLinks
def test_addListEdgesAccumulatesElements(self):
"""
Test that Graph.addListEdges correctly decomposes an existing list-level
link and accumulates individual element-level links from multiple sources.
"""
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
nodeC = graph.addNewNode(NodeWithListAttribute.__name__)
nodeA.listInput.extend(["A1", "A2"])
nodeB.listInput.extend(["B1", "B2"])
# First addListEdges: nodeA -> nodeC
createdEdges, deletedEdges = graph.addListEdges(nodeA.listInput, nodeC.listInput)
assert len(createdEdges) == 2
assert len(deletedEdges) == 0
assert len(nodeC.listInput) == 2
assert nodeC.listInput.at(0).isLink
assert nodeC.listInput.at(1).isLink
assert nodeC.listInput.at(0).inputLink.node == nodeA
assert nodeC.listInput.at(1).inputLink.node == nodeA
# Second addListEdges: nodeB -> nodeC (accumulates)
createdEdges, deletedEdges = graph.addListEdges(nodeB.listInput, nodeC.listInput)
assert len(createdEdges) == 2
assert len(deletedEdges) == 0
# All 4 element-level links should be preserved
assert len(nodeC.listInput) == 4
assert nodeC.listInput.at(0).inputLink.node == nodeA
assert nodeC.listInput.at(1).inputLink.node == nodeA
assert nodeC.listInput.at(2).inputLink.node == nodeB
assert nodeC.listInput.at(3).inputLink.node == nodeB
def test_addListEdgesDecomposesExistingViewLink(self):
"""
Test that Graph.addListEdges decomposes an existing list-level 'view' link
into individual element links before adding new ones.
"""
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
nodeC = graph.addNewNode(NodeWithListAttribute.__name__)
nodeA.listInput.extend(["A1", "A2"])
nodeB.listInput.extend(["B1"])
# Create a list-level "view" link: nodeA.listInput -> nodeC.listInput
nodeA.listInput.connectTo(nodeC.listInput)
assert nodeC.listInput.isLink
assert len(nodeC.listInput) == 2
# addListEdges should decompose the view and add nodeB's elements
createdEdges, deletedEdges = graph.addListEdges(nodeB.listInput, nodeC.listInput)
# The view link was deleted, individual links from nodeA were re-created,
# plus a new link from nodeB
assert len(nodeC.listInput) == 3
assert nodeC.listInput.at(0).inputLink.node == nodeA
assert nodeC.listInput.at(1).inputLink.node == nodeA
assert nodeC.listInput.at(2).inputLink.node == nodeB