11#!/usr/bin/env python
22# coding:utf-8
33
4- from meshroom .core .graph import Graph
5- from meshroom .core import pipelineTemplates , Version
4+ from meshroom .core import unregisterNodeType , pipelineTemplates , Version
65from meshroom .core .node import CompatibilityIssue , CompatibilityNode
76from meshroom .core .graphIO import GraphIO
87
9- import json
108import meshroom
119
10+ import json
1211
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 ()
2316
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 )
2719
20+ try :
2821 graphData = fileData .get (GraphIO .Keys .Graph , fileData )
29-
30- assert isinstance ( graphData , dict )
22+ if not isinstance ( graphData , dict ):
23+ return False
3124
3225 header = fileData .get (GraphIO .Keys .Header , {})
33- assert header .get ("template" , False )
26+ if not header .get ("template" , False ):
27+ return False
3428 nodesVersions = header .get (GraphIO .Keys .NodesVersions , {})
3529
3630 for _ , nodeData in graphData .items ():
3731 nodeType = nodeData ["nodeType" ]
38- assert nodeType in meshroom .core .nodesDesc
32+ if not nodeType in meshroom .core .nodesDesc :
33+ return False
3934
4035 nodeDesc = meshroom .core .nodesDesc [nodeType ]
4136 currentNodeVersion = meshroom .core .nodeVersion (nodeDesc )
@@ -58,4 +53,25 @@ def test_templateVersions():
5853 compatibilityIssue = CompatibilityIssue .DescriptionConflict
5954 break
6055
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