11import time
22import subprocess
33import sys
4+
45if sys .version_info [0 ] < 3 :
56 print ("auto_test requires Python 3" )
67 exit (1 )
1011import json
1112
1213
13- if len (sys .argv ) == 2 and sys .argv [1 ] == ' -version_check' :
14+ if len (sys .argv ) == 2 and sys .argv [1 ] == " -version_check" :
1415 exit (sys .version_info [0 ])
1516
1617
1718def searchForPython (python_implementations ):
1819 py3_exec = None
19- py3_exec = shutil .which (' python3' )
20+ py3_exec = shutil .which (" python3" )
2021 if py3_exec is None :
21- exec_str = shutil .which (' python' )
22+ exec_str = shutil .which (" python" )
2223 if exec_str is not None :
23- version = subprocess .call ([exec_str , ' auto_test.py' , ' -version_check' ])
24+ version = subprocess .call ([exec_str , " auto_test.py" , " -version_check" ])
2425 if version >= 3 :
2526 py3_exec = exec_str
2627 if py3_exec is None :
27- print ("WARNING: Python 3 executable not found for auto_test. If desired, set manually" )
28+ print (
29+ "WARNING: Python 3 executable not found for auto_test. If desired, set manually"
30+ )
2831 else :
2932 python_implementations .add ((3 , py3_exec ))
3033
@@ -33,76 +36,89 @@ def searchForPython(python_implementations):
3336TIMEOUT = 120 # timeout for each test (in seconds)
3437CHARM_QUIET_AFTER_NUM_TESTS = 5
3538
36- commonArgs = [' ++local' ]
37- default_num_processes = int (os .environ .get (' CHARM4PY_TEST_NUM_PROCESSES' , 4 ))
39+ commonArgs = [" ++local" ]
40+ default_num_processes = int (os .environ .get (" CHARM4PY_TEST_NUM_PROCESSES" , 4 ))
3841
3942try :
4043 import numba
44+
4145 numbaInstalled = True
4246except :
4347 numbaInstalled = False
4448
4549# search for python executables
46- python_implementations = set () # python implementations can also be added here manually
50+ python_implementations = set () # python implementations can also be added here manually
4751searchForPython (python_implementations )
4852
49- interfaces = [' cython' ]
53+ interfaces = [" cython" ]
5054
51- with open (' test_config.json' , 'r' ) as infile :
55+ with open (" test_config.json" , "r" ) as infile :
5256 tests = json .load (infile )
5357
5458num_tests = 0
5559durations = defaultdict (dict )
5660for test in tests :
57- if ' condition' in test :
58- if test [' condition' ] == ' numbaInstalled' and not numbaInstalled :
61+ if " condition" in test :
62+ if test [" condition" ] == " numbaInstalled" and not numbaInstalled :
5963 continue
60- if test [' condition' ] == ' not numbaInstalled' and numbaInstalled :
64+ if test [" condition" ] == " not numbaInstalled" and numbaInstalled :
6165 continue
62- if ' timeout_override' in test :
63- TIMEOUT = test [' timeout_override' ]
66+ if " timeout_override" in test :
67+ TIMEOUT = test [" timeout_override" ]
6468 else :
6569 TIMEOUT = 120
66- num_processes = max (test .get ('force_min_processes' , default_num_processes ), default_num_processes )
70+ num_processes = max (
71+ test .get ("force_min_processes" , default_num_processes ), default_num_processes
72+ )
6773 for interface in interfaces :
68- durations [interface ][test [' path' ]] = []
74+ durations [interface ][test [" path" ]] = []
6975 for version , python in sorted (python_implementations ):
70- if version < test .get (' requires_py_version' , - 1 ):
76+ if version < test .get (" requires_py_version" , - 1 ):
7177 continue
7278 additionalArgs = []
73- if num_tests >= CHARM_QUIET_AFTER_NUM_TESTS and ' ++quiet' not in commonArgs :
74- additionalArgs .append (' ++quiet' )
75- cmd = [' charmrun/charmrun' ]
76- if test .get (' prefix' ):
77- cmd += [test [' prefix' ]]
78- if not test .get (' interactive' , False ):
79- cmd += [python ] + [test [' path' ]]
79+ if num_tests >= CHARM_QUIET_AFTER_NUM_TESTS and " ++quiet" not in commonArgs :
80+ additionalArgs .append (" ++quiet" )
81+ cmd = [" charmrun/charmrun" ]
82+ if test .get (" prefix" ):
83+ cmd += [test [" prefix" ]]
84+ if not test .get (" interactive" , False ):
85+ cmd += [python ] + [test [" path" ]]
8086 else :
81- cmd += [python ] + ['-m' , ' charm4py.interactive' ]
82- if ' args' in test :
83- cmd += test [' args' ].split (' ' )
87+ cmd += [python ] + ["-m" , " charm4py.interactive" ]
88+ if " args" in test :
89+ cmd += test [" args" ].split (" " )
8490 cmd += commonArgs
85- cmd += ['+p' + str (num_processes ), ' +libcharm_interface' , interface ]
91+ cmd += ["+p" + str (num_processes ), " +libcharm_interface" , interface ]
8692 cmd += additionalArgs
87- print (' Test command is ' + ' ' .join (cmd ))
93+ print (" Test command is " + " " .join (cmd ))
8894 startTime = time .time ()
8995 stdin = None
90- if test .get (' interactive' , False ):
91- stdin = open (test [' path' ])
96+ if test .get (" interactive" , False ):
97+ stdin = open (test [" path" ])
9298 p = subprocess .Popen (cmd , stdin = stdin )
9399 try :
94100 rc = p .wait (TIMEOUT )
95101 except subprocess .TimeoutExpired :
96- print ("Timeout (" + str (TIMEOUT ) + " secs) expired when running " + test ['path' ] + ", Killing process" )
102+ print (
103+ "Timeout ("
104+ + str (TIMEOUT )
105+ + " secs) expired when running "
106+ + test ["path" ]
107+ + ", Killing process"
108+ )
97109 p .kill ()
98110 rc = - 1
99111 if rc != 0 :
100- print ("ERROR running test " + test [' path' ] + " with " + python )
112+ print ("ERROR running test " + test [" path" ] + " with " + python )
101113 exit (1 )
102114 else :
103115 elapsed = round (time .time () - startTime , 3 )
104- durations [interface ][test ['path' ]].append (elapsed )
105- print ("\n \n --------------------- TEST PASSED (in " + str (elapsed ) + " secs) ---------------------\n \n " )
116+ durations [interface ][test ["path" ]].append (elapsed )
117+ print (
118+ "\n \n --------------------- TEST PASSED (in "
119+ + str (elapsed )
120+ + " secs) ---------------------\n \n "
121+ )
106122 num_tests += 1
107123
108124
0 commit comments