|
3 | 3 |
|
4 | 4 | import os |
5 | 5 | from pathlib import Path |
| 6 | +import tempfile |
6 | 7 |
|
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 |
9 | 10 | from meshroom.core.plugins import Plugin |
10 | 11 |
|
11 | 12 | from .utils import registerNodeDesc |
@@ -136,3 +137,117 @@ def test_initNode(self): |
136 | 137 | inputs = ["/path/to/file", "/path/to/file/2"] |
137 | 138 | node.nodeDesc.initialize(node, inputs, None) |
138 | 139 | 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