76
76
PTRN_IMPORT_ERROR = re .compile (r".*cannot import name \'(?P<module>.*)\'.*" , re .DOTALL )
77
77
PTRN_REMOTE_HOST = re .compile (r"(?P<user>\w+)@(?P<host>[\w.]+):(?P<path>.+)" )
78
78
PTRN_VALID_CSV_NAME = re .compile (r"unittests-\d{4}-\d{2}-\d{2}.csv" )
79
+ PTRN_TEST_STATUS_INDIVIDUAL = re .compile (r"(?P<name>test[\w_]+ \(.+?\)) ... (?P<status>.+)" )
80
+ PTRN_TEST_STATUS_ERROR = re .compile (r"(?P<status>.+): (?P<name>test[\w_]+ \(.+?\))" )
79
81
80
82
81
83
# ----------------------------------------------------------------------------------------------------------------------
@@ -216,6 +218,13 @@ def read_csv(path):
216
218
return rows
217
219
218
220
221
+ class TestStatus (object ):
222
+ ERROR = 'error'
223
+ FAIL = 'fail'
224
+ SKIPPED = 'skipped'
225
+ OK = 'ok'
226
+
227
+
219
228
# ----------------------------------------------------------------------------------------------------------------------
220
229
#
221
230
# result (output processing)
@@ -224,35 +233,88 @@ def read_csv(path):
224
233
class StatEntry (object ):
225
234
def __init__ (self ):
226
235
self .num_tests = - 1
227
- self .num_errors = - 1
228
- self .num_fails = - 1
229
- self .num_skipped = - 1
236
+ # reported stats
237
+ self ._num_errors = - 1
238
+ self ._num_fails = - 1
239
+ self ._num_skipped = - 1
240
+ # tracked stats
241
+ self ._tracked = False
242
+
243
+ def _reset (self ):
244
+ self ._num_fails = 0
245
+ self ._num_errors = 0
246
+ self ._num_skipped = 0
230
247
231
248
def all_ok (self ):
232
- self .num_fails = 0
233
- self .num_errors = 0
234
- self .num_skipped = 0
249
+ self ._reset ()
250
+
251
+ @property
252
+ def num_errors (self ):
253
+ return self ._num_errors
254
+
255
+ @num_errors .setter
256
+ def num_errors (self , value ):
257
+ if not self ._tracked :
258
+ self ._num_errors = value
259
+
260
+ @property
261
+ def num_fails (self ):
262
+ return self ._num_fails
263
+
264
+ @num_fails .setter
265
+ def num_fails (self , value ):
266
+ if not self ._tracked :
267
+ self ._num_fails = value
268
+
269
+ @property
270
+ def num_skipped (self ):
271
+ return self ._num_skipped
272
+
273
+ @num_skipped .setter
274
+ def num_skipped (self , value ):
275
+ if not self ._tracked :
276
+ self ._num_skipped = value
235
277
236
278
@property
237
279
def num_passes (self ):
238
280
if self .num_tests > 0 :
239
- return self .num_tests - (self .num_fails + self .num_errors + self .num_skipped )
281
+ return self .num_tests - (self ._num_fails + self ._num_errors + self ._num_skipped )
240
282
return - 1
241
283
284
+ def update (self , test_detailed_stats ):
285
+ if len (test_detailed_stats ) > 0 :
286
+ self ._tracked = True
287
+ self ._reset ()
288
+ for test , stats in test_detailed_stats .items ():
289
+ stats = {s .lower () for s in stats }
290
+ if TestStatus .ERROR in stats :
291
+ self ._num_errors += 1
292
+ elif TestStatus .FAIL in stats :
293
+ self ._num_fails += 1
294
+ else :
295
+ for s in stats :
296
+ if s .startswith (TestStatus .SKIPPED ):
297
+ self ._num_skipped += 1
298
+ break
299
+
242
300
243
301
def process_output (output_lines ):
244
302
if isinstance (output_lines , str ):
245
303
output_lines = output_lines .split ("\n " )
246
304
247
305
unittests = []
306
+ # stats tracked per unittest
307
+ unittest_tests = defaultdict (list )
248
308
error_messages = defaultdict (set )
249
309
java_exceptions = defaultdict (set )
250
310
stats = defaultdict (StatEntry )
251
311
252
312
for line in output_lines :
253
313
match = re .match (PTRN_UNITTEST , line )
254
314
if match :
255
- unittests .append (match .group ('unittest' ))
315
+ unittest = match .group ('unittest' )
316
+ unittests .append (unittest )
317
+ unittest_tests .clear ()
256
318
continue
257
319
258
320
# extract python reported python error messages
@@ -268,6 +330,16 @@ def process_output(output_lines):
268
330
continue
269
331
270
332
# stats
333
+ # tracking stats
334
+ match = re .match (PTRN_TEST_STATUS_INDIVIDUAL , line )
335
+ if not match :
336
+ match = re .match (PTRN_TEST_STATUS_ERROR , line )
337
+ if match :
338
+ name = match .group ('name' )
339
+ status = match .group ('status' )
340
+ unittest_tests [name ].append (status )
341
+ continue
342
+
271
343
if line .strip () == 'OK' :
272
344
stats [unittests [- 1 ]].all_ok ()
273
345
continue
@@ -286,6 +358,8 @@ def process_output(output_lines):
286
358
match = re .match (PTRN_NUM_TESTS , line )
287
359
if match :
288
360
stats [unittests [- 1 ]].num_tests = int (match .group ('num_tests' ))
361
+ stats [unittests [- 1 ]].update (unittest_tests )
362
+ unittest_tests .clear ()
289
363
continue
290
364
291
365
match = re .match (PTRN_FAILED , line )
@@ -299,6 +373,7 @@ def process_output(output_lines):
299
373
stats [unittests [- 1 ]].num_fails = int (fails ) if fails else 0
300
374
stats [unittests [- 1 ]].num_errors = int (errs ) if errs else 0
301
375
stats [unittests [- 1 ]].num_skipped = int (skipped ) if skipped else 0
376
+ continue
302
377
303
378
return unittests , error_messages , java_exceptions , stats
304
379
@@ -712,6 +787,8 @@ def main(prog, args):
712
787
parser = argparse .ArgumentParser (prog = prog ,
713
788
description = "Run the standard python unittests." )
714
789
parser .add_argument ("-v" , "--verbose" , help = "Verbose output." , action = "store_true" )
790
+ parser .add_argument ("-n" , "--no_cpython" , help = "Do not run the tests with cpython (for comparison)." ,
791
+ action = "store_true" )
715
792
parser .add_argument ("-l" , "--limit" , help = "Limit the number of unittests to run." , default = None , type = int )
716
793
parser .add_argument ("-t" , "--tests_path" , help = "Unittests path." , default = PATH_UNITTESTS )
717
794
parser .add_argument ("-T" , "--timeout" , help = "Timeout per unittest run." , default = TIMEOUT , type = int )
@@ -754,7 +831,7 @@ def _fmt(t):
754
831
unittests = get_unittests (flags .tests_path , limit = flags .limit , skip_tests = skip_tests )
755
832
756
833
# get cpython stats
757
- if not flags .gate :
834
+ if not flags .gate and not flags . no_cpython :
758
835
log (HR )
759
836
log ("[INFO] get cpython stats" )
760
837
cpy_results = run_unittests (unittests , 60 * 5 , with_cpython = True )
0 commit comments