Skip to content

Commit ef186d9

Browse files
committed
[tests] test_nodes: Add test for BackdropNodes
1 parent 313a1da commit ef186d9

File tree

1 file changed

+117
-2
lines changed

1 file changed

+117
-2
lines changed

tests/test_nodes.py

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
import os
55
from pathlib import Path
6+
import tempfile
67

7-
from meshroom.core import pluginManager, loadClassesNodes
8-
from meshroom.core.graph import Graph
8+
from meshroom.core import pluginManager, loadClassesNodes, initNodes
9+
from meshroom.core.graph import Graph, loadGraph
910
from meshroom.core.plugins import Plugin
1011

1112
from .utils import registerNodeDesc
@@ -136,3 +137,117 @@ def test_initNode(self):
136137
inputs = ["/path/to/file", "/path/to/file/2"]
137138
node.nodeDesc.initialize(node, inputs, None)
138139
assert node.input.value == inputs[0]
140+
141+
142+
class TestBackdropNode:
143+
loadedPlugins = pluginManager.getPlugins()
144+
145+
@classmethod
146+
def setup_class(cls):
147+
initNodes()
148+
149+
@classmethod
150+
def teardown_class(cls):
151+
for plugin in pluginManager.getPlugins():
152+
if plugin not in cls.loadedPlugins:
153+
for node in plugin.nodes.values():
154+
pluginManager.unregisterNode(node)
155+
pluginManager.removePlugin(plugin)
156+
157+
def test_backdropNode(self):
158+
""" Test that a backdrop node can be added to a graph with its expected default values. """
159+
g = Graph("Default Backdrop node")
160+
backdrop = g.addNewNode("Backdrop")
161+
162+
# Check that the default values for backdrop are as expected
163+
assert backdrop is not None
164+
assert backdrop.nodeWidth == 600
165+
assert backdrop.nodeHeight == 400
166+
assert backdrop.fontSize == 12
167+
assert backdrop.color == ""
168+
assert backdrop.comment == ""
169+
170+
# Add a non-backdrop node and check that its default values are not backdrop's ones
171+
node = g.addNewNode("CopyFiles")
172+
assert node is not None
173+
assert node.nodeWidth == 0
174+
assert node.nodeHeight == 0
175+
assert node.fontSize == 0
176+
assert node.color == ""
177+
assert node.comment == ""
178+
179+
def test_backdropNode_customAttributes(self):
180+
""" Test that a backdrop node's attributes can be correctly updated. """
181+
g = Graph("Backdrop node with custom values")
182+
backdrop = g.addNewNode("Backdrop")
183+
184+
# Set custom values for backdrop and assert the properties are correctly updated
185+
width = backdrop.internalAttribute("nodeWidth")
186+
width.value = 400
187+
assert backdrop.nodeWidth == 400
188+
189+
height = backdrop.internalAttribute("nodeHeight")
190+
height.value = 200
191+
assert backdrop.nodeHeight == 200
192+
193+
fontSize = backdrop.internalAttribute("fontSize")
194+
fontSize.value = 10
195+
assert backdrop.fontSize == 10
196+
197+
color = backdrop.internalAttribute("color")
198+
color.value = "#FF0000"
199+
assert backdrop.color == "#FF0000"
200+
201+
comment = backdrop.internalAttribute("comment")
202+
comment.value = "hello world"
203+
assert backdrop.comment == "hello world"
204+
205+
def test_backdropNode_defaultSerialization(self):
206+
""" Test that a backdrop node with default values is correctly serialized and deserialized. """
207+
g = Graph("Backdrop node default serialization")
208+
backdrop = g.addNewNode("Backdrop")
209+
210+
# Save the graph in a file
211+
graphFile = os.path.join(tempfile.mkdtemp(), "test_backdrop_serialization.mg")
212+
g.save(graphFile)
213+
214+
# Reload the graph and check the values for the backdrop node are the default ones
215+
g = loadGraph(graphFile)
216+
backdrop = g.node("Backdrop_1")
217+
assert backdrop is not None
218+
assert backdrop.nodeWidth == 600
219+
assert backdrop.nodeHeight == 400
220+
assert backdrop.fontSize == 12
221+
assert backdrop.color == ""
222+
assert backdrop.comment == ""
223+
224+
def test_backdropNode_customSerialization(self):
225+
""" Test that a backdrop node with custom values is correctly serialized and deserialized. """
226+
g = Graph("Backdrop node custom serialization")
227+
backdrop = g.addNewNode("Backdrop")
228+
229+
# Set custom values for backdrop
230+
width = backdrop.internalAttribute("nodeWidth")
231+
width.value = 400
232+
height = backdrop.internalAttribute("nodeHeight")
233+
height.value = 200
234+
fontSize = backdrop.internalAttribute("fontSize")
235+
fontSize.value = 10
236+
color = backdrop.internalAttribute("color")
237+
color.value = "#FF0000"
238+
comment = backdrop.internalAttribute("comment")
239+
comment.value = "hello world"
240+
241+
# Save the graph in a file
242+
graphFile = os.path.join(tempfile.mkdtemp(), "test_backdrop_serialization.mg")
243+
g.save(graphFile)
244+
245+
# Reload the graph and check the values for the backdrop node are the default ones
246+
g = loadGraph(graphFile)
247+
backdrop = g.node("Backdrop_1")
248+
assert backdrop is not None
249+
assert backdrop.nodeWidth == 400
250+
assert backdrop.nodeHeight == 200
251+
assert backdrop.fontSize == 10
252+
assert backdrop.color == "#FF0000"
253+
assert backdrop.comment == "hello world"

0 commit comments

Comments
 (0)