Skip to content

Commit

Permalink
Enhance TypeError and rename variable in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Jan 14, 2020
1 parent f1e6f0e commit 8bf84ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ def extract_errors_from_log(log_txt, reg_exps):
or tuple of regular expression and action (any of [IGNORE, WARN, ERROR])
:return (warnings, errors) as lists of lines containing a match
"""
actions = (IGNORE, WARN, ERROR)

# promote single string value to list, since code below expects a list
if isinstance(reg_exps, string_type):
Expand All @@ -611,8 +612,10 @@ def extract_errors_from_log(log_txt, reg_exps):
reg_exp, action = cur, ERROR
else:
reg_exp, action = cur
if not isinstance(reg_exp, str) or action not in (IGNORE, WARN, ERROR):
raise TypeError("Invalid types")
if not isinstance(reg_exp, str):
raise TypeError("RegExp must be passed as string")
if action not in actions:
raise TypeError("action must be one of %s" % action)
re_tuples.append((re.compile(reg_exp), action))
except Exception as e:
raise EasyBuildError("Invalid input: No RegExp or tuple of RegExp and action '%s' (%s)", str(cur), e)
Expand Down
24 changes: 12 additions & 12 deletions test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,38 +544,38 @@ def test_check_log_for_errors(self):
"enabling -Werror",
"the process crashed with 0"
])
expected_error_msg = r"Found 2 error\(s\) in command output "\
r"\(output: error found\n\tthe process crashed with 0\)"
expected_msg = r"Found 2 error\(s\) in command output "\
r"\(output: error found\n\tthe process crashed with 0\)"

# String promoted to list
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text,
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
r"\b(error|crashed)\b")
# List of string(s)
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text,
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
[r"\b(error|crashed)\b"])
# List of tuple(s)
self.assertErrorRegex(EasyBuildError, expected_error_msg, check_log_for_errors, input_text,
self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text,
[(r"\b(error|crashed)\b", ERROR)])

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

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


def suite():
Expand Down

0 comments on commit 8bf84ab

Please sign in to comment.