Skip to content

Commit c5ca2d9

Browse files
committed
Enhance TypeError and rename variable in test
1 parent f1e6f0e commit c5ca2d9

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

easybuild/tools/run.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ def extract_errors_from_log(log_txt, reg_exps):
599599
or tuple of regular expression and action (any of [IGNORE, WARN, ERROR])
600600
:return (warnings, errors) as lists of lines containing a match
601601
"""
602+
actions = (IGNORE, WARN, ERROR)
602603

603604
# promote single string value to list, since code below expects a list
604605
if isinstance(reg_exps, string_type):
@@ -611,8 +612,10 @@ def extract_errors_from_log(log_txt, reg_exps):
611612
reg_exp, action = cur, ERROR
612613
else:
613614
reg_exp, action = cur
614-
if not isinstance(reg_exp, str) or action not in (IGNORE, WARN, ERROR):
615-
raise TypeError("Invalid types")
615+
if not isinstance(reg_exp, str):
616+
raise TypeError("RegExp must be passed as string")
617+
if action not in actions:
618+
raise TypeError("action must be one of %s" % action)
616619
re_tuples.append((re.compile(reg_exp), action))
617620
except Exception as e:
618621
raise EasyBuildError("Invalid input: No RegExp or tuple of RegExp and action '%s' (%s)", str(cur), e)

test/framework/run.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,38 +544,38 @@ def test_check_log_for_errors(self):
544544
"enabling -Werror",
545545
"the process crashed with 0"
546546
])
547-
expected_error_msg = r"Found 2 error\(s\) in command output "\
548-
r"\(output: error found\n\tthe process crashed with 0\)"
547+
expected_msg = r"Found 2 error\(s\) in command output "\
548+
r"\(output: error found\n\tthe process crashed with 0\)"
549549

550550
# String promoted to list
551-
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text,
551+
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
552552
r"\b(error|crashed)\b")
553553
# List of string(s)
554-
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text,
554+
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
555555
[r"\b(error|crashed)\b"])
556556
# List of tuple(s)
557-
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text,
557+
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
558558
[(r"\b(error|crashed)\b", ERROR)])
559559

560-
expected_error_msg = "Found 2 potential error(s) in command output " \
561-
"(output: error found\n\tthe process crashed with 0)"
560+
expected_msg = "Found 2 potential error(s) in command output " \
561+
"(output: error found\n\tthe process crashed with 0)"
562562
init_logging(logfile, silent=True)
563563
check_log_for_errors(input_text, [(r"\b(error|crashed)\b", WARN)])
564564
stop_logging(logfile)
565-
self.assertTrue(expected_error_msg in read_file(logfile))
565+
self.assertTrue(expected_msg in read_file(logfile))
566566

567-
expected_error_msg = r"Found 2 error\(s\) in command output \(output: error found\n\ttest failed\)"
567+
expected_msg = r"Found 2 error\(s\) in command output \(output: error found\n\ttest failed\)"
568568
write_file(logfile, '')
569569
init_logging(logfile, silent=True)
570-
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text, [
570+
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, [
571571
r"\berror\b",
572572
(r"\ballowed-test failed\b", IGNORE),
573573
(r"(?i)\bCRASHED\b", WARN),
574574
"fail"
575575
])
576576
stop_logging(logfile)
577-
expected_error_msg = "Found 1 potential error(s) in command output (output: the process crashed with 0)"
578-
self.assertTrue(expected_error_msg in read_file(logfile))
577+
expected_msg = "Found 1 potential error(s) in command output (output: the process crashed with 0)"
578+
self.assertTrue(expected_msg in read_file(logfile))
579579

580580

581581
def suite():

0 commit comments

Comments
 (0)