Skip to content

Commit cfa33b6

Browse files
committed
[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.
1 parent 2fe7cfe commit cfa33b6

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

meshroom/core/test.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
# coding:utf-8
3+
4+
from meshroom.core import pipelineTemplates, Version
5+
from meshroom.core.node import CompatibilityIssue, CompatibilityNode
6+
from meshroom.core.graphIO import GraphIO
7+
8+
import meshroom
9+
10+
import json
11+
12+
def checkTemplateVersions(path: str) -> bool:
13+
""" Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """
14+
meshroom.core.initNodes()
15+
16+
with open(path) as jsonFile:
17+
fileData = json.load(jsonFile)
18+
19+
graphData = fileData.get(GraphIO.Keys.Graph, fileData)
20+
if not isinstance(graphData, dict):
21+
return False
22+
23+
header = fileData.get(GraphIO.Keys.Header, {})
24+
if not header.get("template", False):
25+
return False
26+
nodesVersions = header.get(GraphIO.Keys.NodesVersions, {})
27+
28+
for _, nodeData in graphData.items():
29+
nodeType = nodeData["nodeType"]
30+
if not nodeType in meshroom.core.nodesDesc:
31+
return False
32+
33+
nodeDesc = meshroom.core.nodesDesc[nodeType]
34+
currentNodeVersion = meshroom.core.nodeVersion(nodeDesc)
35+
36+
inputs = nodeData.get("inputs", {})
37+
internalInputs = nodeData.get("internalInputs", {})
38+
version = nodesVersions.get(nodeType, None)
39+
40+
compatibilityIssue = None
41+
42+
if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major:
43+
compatibilityIssue = CompatibilityIssue.VersionConflict
44+
else:
45+
for attrName, value in inputs.items():
46+
if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value):
47+
compatibilityIssue = CompatibilityIssue.DescriptionConflict
48+
break
49+
for attrName, value in internalInputs.items():
50+
if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value):
51+
compatibilityIssue = CompatibilityIssue.DescriptionConflict
52+
break
53+
54+
if compatibilityIssue is not None:
55+
print("{} in {} for node {}".format(compatibilityIssue, path, nodeType))
56+
return False
57+
58+
return True
59+
60+
61+
def checkAllTemplatesVersions() -> bool:
62+
meshroom.core.initPipelines()
63+
64+
validVersions = []
65+
for _, path in pipelineTemplates.items():
66+
validVersions.append(checkTemplateVersions(path))
67+
68+
return all(validVersions)

0 commit comments

Comments
 (0)