Skip to content

Commit 3f731dc

Browse files
committed
unittests runner: extract modules which could not be imported in report
1 parent d129a07 commit 3f731dc

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

graalpython/com.oracle.graal.python.test/src/python_unittests.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
r'^OK \((failures=(?P<failures>\d+))?(, )?(errors=(?P<errors>\d+))?(, )?(skipped=(?P<skipped>\d+))?\)$')
7373
PTRN_JAVA_EXCEPTION = re.compile(r'^(?P<exception>com\.oracle\.[^:]*):(?P<message>.*)')
7474
PTRN_MODULE_NOT_FOUND = re.compile(r'.*ModuleNotFound: \'(?P<module>.*)\'\..*', re.DOTALL)
75-
75+
PTRN_IMPORT_ERROR = re.compile(r".*cannot import name \'(?P<module>.*)\'.*", re.DOTALL)
7676

7777
# ----------------------------------------------------------------------------------------------------------------------
7878
#
@@ -279,11 +279,14 @@ def process_output(output_lines):
279279
# python error processing
280280
#
281281
# ----------------------------------------------------------------------------------------------------------------------
282-
def process_errors(unittests, error_messages, error=None, msg_processor=None):
282+
def process_errors(unittests, error_messages, err=None, msg_processor=None):
283+
if isinstance(err, str):
284+
err = {err,}
285+
283286
def _err_filter(item):
284-
if not error:
287+
if not err:
285288
return True
286-
return item[0] == error
289+
return item[0] in err
287290

288291
def _processor(msg):
289292
if not msg_processor:
@@ -304,6 +307,11 @@ def get_missing_module(msg):
304307
return match.group('module') if match else None
305308

306309

310+
def get_cannot_import_module(msg):
311+
match = re.match(PTRN_IMPORT_ERROR, msg)
312+
return match.group('module') if match else None
313+
314+
307315
# ----------------------------------------------------------------------------------------------------------------------
308316
#
309317
# csv reporting
@@ -499,7 +507,7 @@ def save_as_csv(report_path, unittests, error_messages, java_exceptions, stats):
499507
'''
500508

501509

502-
def save_as_html(report_name, rows, totals, missing_modules, java_issues, current_date):
510+
def save_as_html(report_name, rows, totals, missing_modules, cannot_import_modules, java_issues, current_date):
503511
def grid(*components):
504512
def _fmt(cmp):
505513
if isinstance(cmp, tuple):
@@ -601,6 +609,11 @@ def format_val(row, k):
601609
for cnt, name in sorted(((cnt, name) for name, cnt in missing_modules.items()), reverse=True)
602610
])
603611

612+
cannot_import_modules_info = ul('modules which could not be imported', [
613+
'<b>{}</b>&nbsp;<span class="text-muted">could not be imported by {} unittests</span>'.format(name, cnt)
614+
for cnt, name in sorted(((cnt, name) for name, cnt in cannot_import_modules.items()), reverse=True)
615+
])
616+
604617
java_issues_info = ul('Java issues', [
605618
'<b>{}</b>&nbsp;<span class="text-muted">caused by {} unittests</span>'.format(name, cnt)
606619
for cnt, name in sorted(((cnt, name) for name, cnt in java_issues.items()), reverse=True)
@@ -619,7 +632,10 @@ def format_val(row, k):
619632

620633
table_stats = table('stats', CSV_HEADER, rows)
621634

622-
content = ' <br> '.join([total_stats_info, table_stats, missing_modules_info, java_issues_info])
635+
content = ' <br> '.join([total_stats_info, table_stats,
636+
missing_modules_info,
637+
cannot_import_modules_info,
638+
java_issues_info])
623639

624640
report = HTML_TEMPLATE.format(
625641
title='GraalPython Unittests Stats',
@@ -688,15 +704,19 @@ def _fmt(t):
688704
csv_report_path = file_name(CSV_RESULTS_NAME, current_date)
689705
rows, totals = save_as_csv(csv_report_path, unittests, error_messages, java_exceptions, stats)
690706

691-
missing_modules = process_errors(unittests, error_messages, error='ModuleNotFoundError',
707+
missing_modules = process_errors(unittests, error_messages, 'ModuleNotFoundError',
692708
msg_processor=get_missing_module)
693709
log("[MISSING MODULES] \n{}", pformat(dict(missing_modules)))
694710

711+
cannot_import_modules = process_errors(unittests, error_messages, err='ImportError',
712+
msg_processor=get_cannot_import_module)
713+
log("[CANNOT IMPORT MODULES] \n{}", pformat(dict(cannot_import_modules)))
714+
695715
java_issues = process_errors(unittests, java_exceptions)
696716
log("[JAVA ISSUES] \n{}", pformat(dict(java_issues)))
697717

698718
html_report_path = file_name(HTML_RESULTS_NAME, current_date)
699-
save_as_html(html_report_path, rows, totals, missing_modules, java_issues, current_date)
719+
save_as_html(html_report_path, rows, totals, missing_modules, cannot_import_modules, java_issues, current_date)
700720

701721
if flags.path:
702722
log("[SAVE] saving results to {} ... ", flags.path)

0 commit comments

Comments
 (0)