1
1
#!/usr/bin/env python
2
2
# coding:utf-8
3
3
4
- from meshroom .core .graph import Graph
5
- from meshroom .core import pipelineTemplates , Version
4
+ from meshroom .core import unregisterNodeType , pipelineTemplates , Version
6
5
from meshroom .core .node import CompatibilityIssue , CompatibilityNode
7
6
from meshroom .core .graphIO import GraphIO
8
7
9
- import json
10
8
import meshroom
11
9
10
+ import json
12
11
13
- def test_templateVersions ():
14
- """
15
- This test checks that there is no compatibility issue with the nodes saved in the template files.
16
- It fails when an upgrade of a templates is needed. Any template can still be opened even if its
17
- nodes are not up-to-date, as they will be automatically upgraded.
18
- """
19
- meshroom .core .initNodes ()
20
- meshroom .core .initPipelines ()
21
-
22
- assert len (pipelineTemplates ) >= 1
12
+ def checkTemplateVersions (path : str , nodesAlreadyLoaded : bool = False ) -> bool :
13
+ """ Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """
14
+ if not nodesAlreadyLoaded :
15
+ meshroom .core .initNodes ()
23
16
24
- for _ , path in pipelineTemplates .items ():
25
- with open (path ) as jsonFile :
26
- fileData = json .load (jsonFile )
17
+ with open (path ) as jsonFile :
18
+ fileData = json .load (jsonFile )
27
19
20
+ try :
28
21
graphData = fileData .get (GraphIO .Keys .Graph , fileData )
29
-
30
- assert isinstance ( graphData , dict )
22
+ if not isinstance ( graphData , dict ):
23
+ return False
31
24
32
25
header = fileData .get (GraphIO .Keys .Header , {})
33
- assert header .get ("template" , False )
26
+ if not header .get ("template" , False ):
27
+ return False
34
28
nodesVersions = header .get (GraphIO .Keys .NodesVersions , {})
35
29
36
30
for _ , nodeData in graphData .items ():
37
31
nodeType = nodeData ["nodeType" ]
38
- assert nodeType in meshroom .core .nodesDesc
32
+ if not nodeType in meshroom .core .nodesDesc :
33
+ return False
39
34
40
35
nodeDesc = meshroom .core .nodesDesc [nodeType ]
41
36
currentNodeVersion = meshroom .core .nodeVersion (nodeDesc )
@@ -58,4 +53,25 @@ def test_templateVersions():
58
53
compatibilityIssue = CompatibilityIssue .DescriptionConflict
59
54
break
60
55
61
- assert compatibilityIssue is None , "{} in {} for node {}" .format (compatibilityIssue , path , nodeType )
56
+ if compatibilityIssue is not None :
57
+ print ("{} in {} for node {}" .format (compatibilityIssue , path , nodeType ))
58
+ return False
59
+
60
+ return True
61
+
62
+ finally :
63
+ if not nodesAlreadyLoaded :
64
+ nodeTypes = [nodeType for _ , nodeType in meshroom .core .nodesDesc .items ()]
65
+ for nodeType in nodeTypes :
66
+ unregisterNodeType (nodeType )
67
+
68
+
69
+ def checkAllTemplatesVersions () -> bool :
70
+ meshroom .core .initNodes ()
71
+ meshroom .core .initPipelines ()
72
+
73
+ validVersions = []
74
+ for _ , path in pipelineTemplates .items ():
75
+ validVersions .append (checkTemplateVersions (path , nodesAlreadyLoaded = True ))
76
+
77
+ return all (validVersions )
0 commit comments