mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-28 17:57:16 +02:00
Merge 072c0aa04e
into ee679fcf34
This commit is contained in:
commit
2695e99fc7
2 changed files with 68 additions and 5 deletions
|
@ -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()
|
||||
|
|
63
tests/test_listAttribute.py
Normal file
63
tests/test_listAttribute.py
Normal 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
|
Loading…
Add table
Reference in a new issue