Skip to content

Commit 39151be

Browse files
committed
[tests] Add test for InitNode
1 parent c5370b7 commit 39151be

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
__version__ = "1.0"
2+
3+
from meshroom.core import desc
4+
5+
6+
class PluginAInputInitNode(desc.InputNode, desc.InitNode):
7+
inputs = [
8+
desc.File(
9+
name="input",
10+
label="Input",
11+
description="",
12+
value="",
13+
),
14+
]
15+
16+
outputs = [
17+
desc.File(
18+
name="output",
19+
label="Output",
20+
description="",
21+
value="",
22+
),
23+
]
24+
25+
def initialize(self, node, inputs, recursiveInputs):
26+
if len(inputs) >= 1:
27+
self.setAttributes(node, {"input": inputs[0]})

tests/test_nodes.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,38 @@ def test_expVariables(self):
101101
assert n._expVars["uid"] == n._uid
102102
assert n.internalFolder
103103
assert n.internalFolder == n._expVars["nodeCacheFolder"]
104+
105+
106+
class TestInitNode:
107+
plugin = None
108+
109+
@classmethod
110+
def setup_class(cls):
111+
folder = os.path.join(os.path.dirname(__file__), "plugins", "meshroom")
112+
package = "pluginA"
113+
cls.plugin = Plugin(package, folder)
114+
nodes = loadClassesNodes(folder, package)
115+
for node in nodes:
116+
cls.plugin.addNodePlugin(node)
117+
pluginManager.addPlugin(cls.plugin)
118+
119+
@classmethod
120+
def teardown_class(cls):
121+
for node in cls.plugin.nodes.values():
122+
pluginManager.unregisterNode(node)
123+
pluginManager.removePlugin(cls.plugin)
124+
cls.plugin = None
125+
126+
def test_initNode(self):
127+
g = Graph("")
128+
129+
node = g.addNewNode("PluginAInputInitNode")
130+
131+
# Check that the init node is correctly detected
132+
initNodes = g.findInitNodes()
133+
assert len(initNodes) == 1 and node in initNodes
134+
135+
# Check that the init node's initialize method has been set
136+
inputs = ["/path/to/file", "/path/to/file/2"]
137+
node.nodeDesc.initialize(node, inputs, None)
138+
assert node.input.value == inputs[0]

0 commit comments

Comments
 (0)