From c5ca2d92cd455180e94b35d61d19117992e75e65 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 14 Jan 2020 14:13:36 +0100 Subject: [PATCH] Enhance TypeError and rename variable in test --- easybuild/tools/run.py | 7 +++++-- test/framework/run.py | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/easybuild/tools/run.py b/easybuild/tools/run.py index da6960f92b..356c169976 100644 --- a/easybuild/tools/run.py +++ b/easybuild/tools/run.py @@ -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): @@ -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) diff --git a/test/framework/run.py b/test/framework/run.py index a52c9b340c..a5f1000e05 100644 --- a/test/framework/run.py +++ b/test/framework/run.py @@ -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():