This commit is contained in:
Yann Lanthony 2025-04-14 23:51:33 +00:00 committed by GitHub
commit 2695e99fc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 68 additions and 5 deletions

View file

@ -547,12 +547,12 @@ class ListAttribute(Attribute):
super(ListAttribute, self).__init__(node, attributeDesc, isOutput, root, parent)
def __len__(self):
if self._value is None:
if self.value is None:
return 0
return len(self._value)
return len(self.value)
def __iter__(self):
return iter(self._value)
return iter(self.value)
def getBaseType(self):
return self.attributeDesc.elementDesc.__class__.__name__
@ -561,10 +561,10 @@ class ListAttribute(Attribute):
""" Returns child attribute at index 'idx' """
# Implement 'at' rather than '__getitem__'
# since the later is called spuriously when object is used in QML
return self._value.at(idx)
return self.value.at(idx)
def index(self, item):
return self._value.indexOf(item)
return self.value.indexOf(item)
def initValue(self):
self.resetToDefaultValue()

View file

@ -0,0 +1,63 @@
from meshroom.core import desc
from meshroom.core.graph import Graph
from meshroom.core import registerNodeType, unregisterNodeType
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):
registerNodeType(NodeWithListAttribute)
@classmethod
def teardown_class(cls):
unregisterNodeType(NodeWithListAttribute)
def test_lengthUsesLinkParam(self):
graph = Graph("")
nodeA = graph.addNewNode(NodeWithListAttribute.__name__)
nodeB = graph.addNewNode(NodeWithListAttribute.__name__)
graph.addEdge(nodeA.listInput, 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__)
graph.addEdge(nodeA.listInput, 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__)
graph.addEdge(nodeA.listInput, nodeB.listInput)
nodeA.listInput.extend(["A", "B", "C"])
assert nodeB.listInput.at(0).node == nodeA
assert nodeB.listInput.index(nodeB.listInput.at(0)) == 0