mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-01 15:58:36 +02:00
[core] Add a test.py
file that contains sanity methods used for validation
For now, it contains methods allowing to check whether a template provided as an argument is valid (i.e. has no compatibility issue). It performs a check that's very similar to what `test_templatesVersions` was doing, but it allows this check to be performed from outside of Meshroom.
This commit is contained in:
parent
2fe7cfe95e
commit
cfa33b6442
1 changed files with 68 additions and 0 deletions
68
meshroom/core/test.py
Normal file
68
meshroom/core/test.py
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# coding:utf-8
|
||||||
|
|
||||||
|
from meshroom.core import pipelineTemplates, Version
|
||||||
|
from meshroom.core.node import CompatibilityIssue, CompatibilityNode
|
||||||
|
from meshroom.core.graphIO import GraphIO
|
||||||
|
|
||||||
|
import meshroom
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
def checkTemplateVersions(path: str) -> bool:
|
||||||
|
""" Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """
|
||||||
|
meshroom.core.initNodes()
|
||||||
|
|
||||||
|
with open(path) as jsonFile:
|
||||||
|
fileData = json.load(jsonFile)
|
||||||
|
|
||||||
|
graphData = fileData.get(GraphIO.Keys.Graph, fileData)
|
||||||
|
if not isinstance(graphData, dict):
|
||||||
|
return False
|
||||||
|
|
||||||
|
header = fileData.get(GraphIO.Keys.Header, {})
|
||||||
|
if not header.get("template", False):
|
||||||
|
return False
|
||||||
|
nodesVersions = header.get(GraphIO.Keys.NodesVersions, {})
|
||||||
|
|
||||||
|
for _, nodeData in graphData.items():
|
||||||
|
nodeType = nodeData["nodeType"]
|
||||||
|
if not nodeType in meshroom.core.nodesDesc:
|
||||||
|
return False
|
||||||
|
|
||||||
|
nodeDesc = meshroom.core.nodesDesc[nodeType]
|
||||||
|
currentNodeVersion = meshroom.core.nodeVersion(nodeDesc)
|
||||||
|
|
||||||
|
inputs = nodeData.get("inputs", {})
|
||||||
|
internalInputs = nodeData.get("internalInputs", {})
|
||||||
|
version = nodesVersions.get(nodeType, None)
|
||||||
|
|
||||||
|
compatibilityIssue = None
|
||||||
|
|
||||||
|
if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major:
|
||||||
|
compatibilityIssue = CompatibilityIssue.VersionConflict
|
||||||
|
else:
|
||||||
|
for attrName, value in inputs.items():
|
||||||
|
if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value):
|
||||||
|
compatibilityIssue = CompatibilityIssue.DescriptionConflict
|
||||||
|
break
|
||||||
|
for attrName, value in internalInputs.items():
|
||||||
|
if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value):
|
||||||
|
compatibilityIssue = CompatibilityIssue.DescriptionConflict
|
||||||
|
break
|
||||||
|
|
||||||
|
if compatibilityIssue is not None:
|
||||||
|
print("{} in {} for node {}".format(compatibilityIssue, path, nodeType))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def checkAllTemplatesVersions() -> bool:
|
||||||
|
meshroom.core.initPipelines()
|
||||||
|
|
||||||
|
validVersions = []
|
||||||
|
for _, path in pipelineTemplates.items():
|
||||||
|
validVersions.append(checkTemplateVersions(path))
|
||||||
|
|
||||||
|
return all(validVersions)
|
Loading…
Add table
Add a link
Reference in a new issue