Skip to content

Commit 1408962

Browse files
committed
[tests] Add extra compatibility tests
Add a new test suite for graph template loading.
1 parent 06d8b3c commit 1408962

File tree

2 files changed

+82
-11
lines changed

2 files changed

+82
-11
lines changed

tests/test_compatibility.py

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55

66
import copy
7+
from typing import Type
78
import pytest
89

910
import meshroom.core
@@ -12,6 +13,8 @@
1213
from meshroom.core.graph import Graph, loadGraph
1314
from meshroom.core.node import CompatibilityNode, CompatibilityIssue, Node
1415

16+
from .utils import registeredNodeTypes
17+
1518

1619
SampleGroupV1 = [
1720
desc.IntParam(name="a", label="a", description="", value=0, range=None),
@@ -156,6 +159,12 @@ class SampleInputNodeV2(desc.InputNode):
156159
]
157160

158161

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+
159168
def test_unknown_node_type():
160169
"""
161170
Test compatibility behavior for unknown node type.
@@ -218,8 +227,7 @@ def test_description_conflict():
218227
g.save(graphFile)
219228

220229
# 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)
223231

224232
# offset node types register to create description conflicts
225233
# each node type name now reference the next one's implementation
@@ -399,20 +407,68 @@ def test_conformUpgrade():
399407

400408
class TestGraphLoadingWithStrictCompatibility:
401409

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+
402420
def test_failsOnNodeDescriptionCompatibilityIssue(self, graphSavedOnDisk):
403-
registerNodeType(SampleNodeV1)
404-
registerNodeType(SampleNodeV2)
405421

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)
409431

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)
412441

413442
with pytest.raises(GraphCompatibilityError):
414443
loadGraph(graph.filepath, strictCompatibility=True)
415444

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"
418465

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)

tests/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from contextlib import contextmanager
2+
from typing import Type
3+
from meshroom.core import registerNodeType, unregisterNodeType
4+
5+
from meshroom.core import desc
6+
7+
@contextmanager
8+
def registeredNodeTypes(nodeTypes: list[Type[desc.Node]]):
9+
for nodeType in nodeTypes:
10+
registerNodeType(nodeType)
11+
12+
yield
13+
14+
for nodeType in nodeTypes:
15+
unregisterNodeType(nodeType)

0 commit comments

Comments
 (0)