Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListAttribute: fix methods not considering connected attribute's value #2660

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,12 @@ def __init__(self, node, attributeDesc, isOutput, root=None, parent=None):
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__
Expand All @@ -516,10 +516,10 @@ def at(self, idx):
""" 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()
Expand Down
63 changes: 63 additions & 0 deletions tests/test_listAttribute.py
Original file line number Diff line number Diff line change
@@ -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