mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-29 14:37:26 +02:00
[core][graphIO] Improve node type version handling
* Deserialization: Replace the logic that defaulted the node type version to "0.0" when unspecified, and assume that unspecified version on a node is targetting current node type version. * Serialization: Only serialize node type versions for which a version info is available. * Test suites: * Add helper context manager to manually override the version of a given node type. * Add new unit tests to cover version conflicts handling is various scenarios.
This commit is contained in:
parent
d9e59e330a
commit
87fbcee06d
7 changed files with 98 additions and 9 deletions
|
@ -1,7 +1,11 @@
|
|||
import json
|
||||
from textwrap import dedent
|
||||
|
||||
from meshroom.core import desc
|
||||
from meshroom.core.graph import Graph
|
||||
from meshroom.core.node import CompatibilityIssue
|
||||
|
||||
from .utils import registeredNodeTypes
|
||||
from .utils import registeredNodeTypes, overrideNodeTypeVersion
|
||||
|
||||
|
||||
class SimpleNode(desc.Node):
|
||||
|
@ -193,6 +197,21 @@ class TestImportGraphContent:
|
|||
assert len(otherGraph.compatibilityNodes) == 2
|
||||
assert not compareGraphsContent(graph, otherGraph)
|
||||
|
||||
def test_importingDifferentNodeVersionCreatesCompatibilityNodes(self, graphSavedOnDisk):
|
||||
graph: Graph = graphSavedOnDisk
|
||||
|
||||
with registeredNodeTypes([SimpleNode]):
|
||||
with overrideNodeTypeVersion(SimpleNode, "1.0"):
|
||||
node = graph.addNewNode(SimpleNode.__name__)
|
||||
graph.save()
|
||||
|
||||
with overrideNodeTypeVersion(SimpleNode, "2.0"):
|
||||
otherGraph = Graph("")
|
||||
nodes = otherGraph.importGraphContentFromFile(graph.filepath)
|
||||
|
||||
assert len(nodes) == 1
|
||||
assert len(otherGraph.compatibilityNodes) == 1
|
||||
assert otherGraph.node(node.name).issue is CompatibilityIssue.VersionConflict
|
||||
|
||||
class TestGraphPartialSerialization:
|
||||
def test_emptyGraph(self):
|
||||
|
@ -297,3 +316,23 @@ class TestGraphCopy:
|
|||
|
||||
graphCopy = graph.copy()
|
||||
assert not compareGraphsContent(graph, graphCopy)
|
||||
|
||||
|
||||
class TestImportGraphContentFromMinimalGraphData:
|
||||
def test_nodeWithoutVersionInfoIsUpgraded(self):
|
||||
graph = Graph("")
|
||||
|
||||
with (
|
||||
registeredNodeTypes([SimpleNode]),
|
||||
overrideNodeTypeVersion(SimpleNode, "2.0"),
|
||||
):
|
||||
sampleGraphContent = dedent("""
|
||||
{
|
||||
"SimpleNode_1": { "nodeType": "SimpleNode" }
|
||||
}
|
||||
""")
|
||||
graph._deserialize(json.loads(sampleGraphContent))
|
||||
|
||||
assert len(graph.nodes) == 1
|
||||
assert len(graph.compatibilityNodes) == 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue