|
4 | 4 | import os |
5 | 5 |
|
6 | 6 | import copy |
| 7 | +from typing import Type |
7 | 8 | import pytest |
8 | 9 |
|
9 | 10 | import meshroom.core |
|
12 | 13 | from meshroom.core.graph import Graph, loadGraph |
13 | 14 | from meshroom.core.node import CompatibilityNode, CompatibilityIssue, Node |
14 | 15 |
|
| 16 | +from .utils import registeredNodeTypes |
| 17 | + |
15 | 18 |
|
16 | 19 | SampleGroupV1 = [ |
17 | 20 | desc.IntParam(name="a", label="a", description="", value=0, range=None), |
@@ -156,6 +159,12 @@ class SampleInputNodeV2(desc.InputNode): |
156 | 159 | ] |
157 | 160 |
|
158 | 161 |
|
| 162 | + |
| 163 | +def replaceNodeTypeDesc(nodeType: str, nodeDesc: Type[desc.Node]): |
| 164 | + """Change the `nodeDesc` associated to `nodeType`.""" |
| 165 | + meshroom.core.nodesDesc[nodeType] = nodeDesc |
| 166 | + |
| 167 | + |
159 | 168 | def test_unknown_node_type(): |
160 | 169 | """ |
161 | 170 | Test compatibility behavior for unknown node type. |
@@ -218,8 +227,7 @@ def test_description_conflict(): |
218 | 227 | g.save(graphFile) |
219 | 228 |
|
220 | 229 | # reload file as-is, ensure no compatibility issue is detected (no CompatibilityNode instances) |
221 | | - g = loadGraph(graphFile) |
222 | | - assert all(isinstance(n, Node) for n in g.nodes) |
| 230 | + loadGraph(graphFile, strictCompatibility=True) |
223 | 231 |
|
224 | 232 | # offset node types register to create description conflicts |
225 | 233 | # each node type name now reference the next one's implementation |
@@ -399,20 +407,68 @@ def test_conformUpgrade(): |
399 | 407 |
|
400 | 408 | class TestGraphLoadingWithStrictCompatibility: |
401 | 409 |
|
| 410 | + def test_failsOnUnknownNodeType(self, graphSavedOnDisk): |
| 411 | + with registeredNodeTypes([SampleNodeV1]): |
| 412 | + graph: Graph = graphSavedOnDisk |
| 413 | + graph.addNewNode(SampleNodeV1.__name__) |
| 414 | + graph.save() |
| 415 | + |
| 416 | + with pytest.raises(GraphCompatibilityError): |
| 417 | + loadGraph(graph.filepath, strictCompatibility=True) |
| 418 | + |
| 419 | + |
402 | 420 | def test_failsOnNodeDescriptionCompatibilityIssue(self, graphSavedOnDisk): |
403 | | - registerNodeType(SampleNodeV1) |
404 | | - registerNodeType(SampleNodeV2) |
405 | 421 |
|
406 | | - graph: Graph = graphSavedOnDisk |
407 | | - graph.addNewNode(SampleNodeV1.__name__) |
408 | | - graph.save() |
| 422 | + with registeredNodeTypes([SampleNodeV1, SampleNodeV2]): |
| 423 | + graph: Graph = graphSavedOnDisk |
| 424 | + graph.addNewNode(SampleNodeV1.__name__) |
| 425 | + graph.save() |
| 426 | + |
| 427 | + replaceNodeTypeDesc(SampleNodeV1.__name__, SampleNodeV2) |
| 428 | + |
| 429 | + with pytest.raises(GraphCompatibilityError): |
| 430 | + loadGraph(graph.filepath, strictCompatibility=True) |
409 | 431 |
|
410 | | - # Replace saved node description by V2 |
411 | | - meshroom.core.nodesDesc[SampleNodeV1.__name__] = SampleNodeV2 |
| 432 | + |
| 433 | +class TestGraphTemplateLoading: |
| 434 | + |
| 435 | + def test_failsOnUnknownNodeTypeError(self, graphSavedOnDisk): |
| 436 | + |
| 437 | + with registeredNodeTypes([SampleNodeV1, SampleNodeV2]): |
| 438 | + graph: Graph = graphSavedOnDisk |
| 439 | + graph.addNewNode(SampleNodeV1.__name__) |
| 440 | + graph.save(template=True) |
412 | 441 |
|
413 | 442 | with pytest.raises(GraphCompatibilityError): |
414 | 443 | loadGraph(graph.filepath, strictCompatibility=True) |
415 | 444 |
|
416 | | - unregisterNodeType(SampleNodeV1) |
417 | | - unregisterNodeType(SampleNodeV2) |
| 445 | + def test_loadsIfIncompatibleNodeHasDefaultAttributeValues(self, graphSavedOnDisk): |
| 446 | + with registeredNodeTypes([SampleNodeV1, SampleNodeV2]): |
| 447 | + graph: Graph = graphSavedOnDisk |
| 448 | + graph.addNewNode(SampleNodeV1.__name__) |
| 449 | + graph.save(template=True) |
| 450 | + |
| 451 | + replaceNodeTypeDesc(SampleNodeV1.__name__, SampleNodeV2) |
| 452 | + |
| 453 | + loadGraph(graph.filepath, strictCompatibility=True) |
| 454 | + |
| 455 | + def test_loadsIfValueSetOnCompatibleAttribute(self, graphSavedOnDisk): |
| 456 | + with registeredNodeTypes([SampleNodeV1, SampleNodeV2]): |
| 457 | + graph: Graph = graphSavedOnDisk |
| 458 | + node = graph.addNewNode(SampleNodeV1.__name__, paramA="foo") |
| 459 | + graph.save(template=True) |
| 460 | + |
| 461 | + replaceNodeTypeDesc(SampleNodeV1.__name__, SampleNodeV2) |
| 462 | + |
| 463 | + loadedGraph = loadGraph(graph.filepath, strictCompatibility=True) |
| 464 | + assert loadedGraph.nodes.get(node.name).paramA.value == "foo" |
418 | 465 |
|
| 466 | + def test_loadsIfValueSetOnIncompatibleAttribute(self, graphSavedOnDisk): |
| 467 | + with registeredNodeTypes([SampleNodeV1, SampleNodeV2]): |
| 468 | + graph: Graph = graphSavedOnDisk |
| 469 | + graph.addNewNode(SampleNodeV1.__name__, input="foo") |
| 470 | + graph.save(template=True) |
| 471 | + |
| 472 | + replaceNodeTypeDesc(SampleNodeV1.__name__, SampleNodeV2) |
| 473 | + |
| 474 | + loadGraph(graph.filepath, strictCompatibility=True) |
0 commit comments