1-
21from concurrent .futures import ThreadPoolExecutor
32from dataclasses import dataclass
43from datetime import timedelta
1413
1514
1615class Test (object ):
17-
1816 STAGES : dict [str , list [str ]] = {
1917 "autogen" : ["autogen.sh" ],
2018 "configure" : ["configure.sh" ],
@@ -23,16 +21,22 @@ class Test(object):
2321 "cargo.transpile" : ["cargo.transpile.gen.sh" , "cargo.transpile.sh" ],
2422 "refactor" : ["refactor.gen.sh" , "refactor.sh" ],
2523 "cargo.refactor" : ["cargo.refactor.gen.sh" , "cargo.refactor.sh" ],
26- "check" : ["check.sh" , "test.sh" ]
24+ "check" : ["check.sh" , "test.sh" ],
2725 }
2826
2927 def __init__ (self , directory : Path , generated_scripts : set [Path ]):
3028 # We only want scripts that have been generated by us now,
3129 # but non `*.gen*` scripts we can search for.
32- non_gen_script_paths = { f for f in directory .iterdir () if f .suffix == ".sh" and ".gen" not in f .suffixes }
33- gen_script_paths = { path for path in generated_scripts if path .is_relative_to (directory ) }
30+ non_gen_script_paths = {
31+ f
32+ for f in directory .iterdir ()
33+ if f .suffix == ".sh" and ".gen" not in f .suffixes
34+ }
35+ gen_script_paths = {
36+ path for path in generated_scripts if path .is_relative_to (directory )
37+ }
3438 script_paths = non_gen_script_paths | gen_script_paths
35- self .scripts = { str (script .relative_to (directory )) for script in script_paths }
39+ self .scripts = {str (script .relative_to (directory )) for script in script_paths }
3640 self .dir = str (directory )
3741 self .conf_file = str (directory / CONF_YML )
3842 self .name = directory .name
@@ -45,41 +49,43 @@ def run_script(self, stage, script, verbose=False, xfail=False) -> bool:
4549 def print_log_tail_on_fail (script_path ):
4650 logfile = f"{ script_path } .log"
4751 if os .path .isfile (logfile ):
48- grep_cmd = [' grep' , '-i' , '-A' , '20' , '-E' , ' panicked|error' , logfile ]
52+ grep_cmd = [" grep" , "-i" , "-A" , "20" , "-E" , " panicked|error" , logfile ]
4953 grep = subprocess .Popen (grep_cmd , stdout = subprocess .PIPE )
5054 assert grep .stdout is not None
5155 for line in grep .stdout :
5256 print (line .decode ().rstrip ())
5357
5458 # fall back to tail if grep didn't find anything
5559 if grep .returncode != 0 :
56- tail = subprocess .Popen (['tail' , '-n' , '20' , logfile ], stdout = subprocess .PIPE )
60+ tail = subprocess .Popen (
61+ ["tail" , "-n" , "20" , logfile ], stdout = subprocess .PIPE
62+ )
5763 assert tail .stdout is not None
5864 for line in tail .stdout :
5965 print (line .decode ().rstrip ())
6066 else :
61- print ("{color}Missing log file: {logf}{nocolor}" . format (
62- color = Colors . WARNING ,
63- logf = logfile ,
64- nocolor = Colors . NO_COLOR )
67+ print (
68+ "{ color}Missing log file: {logf}{nocolor}" . format (
69+ color = Colors . WARNING , logf = logfile , nocolor = Colors . NO_COLOR
70+ )
6571 )
6672
6773 script_path = os .path .join (self .dir , script )
6874
6975 if not os .path .isfile (script_path ):
70- print ("{color}Missing script: {script}{nocolor}" .format (
71- color = Colors .FAIL ,
72- script = script_path ,
73- nocolor = Colors .NO_COLOR )
76+ print (
77+ "{color}Missing script: {script}{nocolor}" .format (
78+ color = Colors .FAIL , script = script_path , nocolor = Colors .NO_COLOR
7479 )
80+ )
7581 return False
7682
7783 if not os .access (script_path , os .X_OK ):
78- print ("{color}Script is not executable: {script}{nocolor}" .format (
79- color = Colors .FAIL ,
80- script = script_path ,
81- nocolor = Colors .NO_COLOR )
84+ print (
85+ "{color}Script is not executable: {script}{nocolor}" .format (
86+ color = Colors .FAIL , script = script_path , nocolor = Colors .NO_COLOR
8287 )
88+ )
8389 return False
8490
8591 if not verbose :
@@ -89,7 +95,8 @@ def print_log_tail_on_fail(script_path):
8995 name = self .name ,
9096 nc = Colors .NO_COLOR ,
9197 stage = stage ,
92- script = relpath )
98+ script = relpath ,
99+ )
93100 else :
94101 line = ""
95102
@@ -192,7 +199,9 @@ def run(self, conf: Config) -> bool:
192199 requested_stages = ", " .join (conf .stages )
193200 stages = ", " .join (Test .STAGES .keys ())
194201 y , nc = Colors .WARNING , Colors .NO_COLOR
195- die (f"invalid stages: { y } { requested_stages } { nc } . valid stages: { stages } " )
202+ die (
203+ f"invalid stages: { y } { requested_stages } { nc } . valid stages: { stages } "
204+ )
196205
197206 stages = conf .stages
198207
@@ -234,5 +243,5 @@ def run(test: Test) -> TestResult:
234243 for result in results :
235244 print (f"{ result .test .name } took { result .time } " )
236245 if not all (result .passed for result in results ):
237- print (f"projects failed: { " " .join (result .test .name for result in results )} " )
246+ print (f"projects failed: { ' ' .join (result .test .name for result in results )} " )
238247 exit (1 )
0 commit comments