44import logging
55import os
66import os .path
7+ import random
78import re
89import sys
910from collections import OrderedDict
5152
5253REQUIRED_MACROS = [REQUIREMENTS_MACRO_NAME , STDIO_MACRO_NAME , ADVANCED_OPTIONS_NAME + "_macro" ]
5354
55+ random .seed (42 )
56+
5457
5558class ExitCode :
5659 def __init__ (self , code_range = "" , level = "" , description = None ):
@@ -1749,14 +1752,27 @@ def create_tests(parent, inputs=None, outputs=None):
17491752 for a in attrib :
17501753 del node .attrib [a ]
17511754 node .attrib [a ] = attrib [a ]
1755+ # this should be batch mode conditionals
1756+ # select yes/no at random
1757+ if node .tag == "conditional" :
1758+ select = node .find ("./param" )
1759+ options = [x .attrib ["value" ] for x in select .findall ("./option" )]
1760+ option = random .choice (options )
1761+ select .attrib ["value" ] = option
1762+ for when in node .findall (".//when" ):
1763+ when .tag = "delete_node"
1764+ if when .attrib ["value" ] != option :
1765+ continue
1766+ for p in when :
1767+ node .append (p )
1768+
17521769 if node .tag == "expand" and node .attrib ["macro" ] == ADVANCED_OPTIONS_NAME + "_macro" :
17531770 node .tag = "section"
17541771 node .attrib ["name" ] = ADVANCED_OPTIONS_NAME
17551772 if "type" not in node .attrib :
17561773 continue
17571774
1758- if (node .attrib ["type" ] == "select" and "true" in {_ .attrib .get ("selected" , "false" ) for _ in node }) or \
1759- (node .attrib ["type" ] == "select" and node .attrib .get ("value" , "" ) != "" ):
1775+ if node .attrib ["type" ] == "select" and node .getparent ().tag != "conditional" and (("true" in {_ .attrib .get ("selected" , "false" ) for _ in node }) or (node .attrib .get ("value" , "" ) != "" )):
17601776 node .tag = "delete_node"
17611777 continue
17621778
@@ -1777,7 +1793,9 @@ def create_tests(parent, inputs=None, outputs=None):
17771793 elif node .attrib ["type" ] == "float" and node .attrib ["value" ] == "" :
17781794 node .attrib ["value" ] = "1.0"
17791795 elif node .attrib ["type" ] == "select" :
1780- if node .attrib .get ("display" , None ) == "radio" or node .attrib .get ("multiple" , "false" ) == "false" :
1796+ if node .getparent ().tag == "conditional" : # set batch mode conditional select, this is done elsewhere
1797+ pass
1798+ elif node .attrib .get ("display" , None ) == "radio" or node .attrib .get ("multiple" , "false" ) == "false" :
17811799 node .attrib ["value" ] = node [0 ].attrib ["value" ]
17821800 elif node .attrib .get ("multiple" , None ) == "true" :
17831801 node .attrib ["value" ] = "," .join ([_ .attrib ["value" ] for _ in node if "value" in _ .attrib ])
0 commit comments