Refactor check_mprime_results() to use sets

This commit is contained in:
2Shirt 2023-07-03 20:16:37 -07:00
parent 9a7fdba3f9
commit 815cfde84a
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -83,8 +83,8 @@ def check_cooling_results(sensors, test_object) -> None:
def check_mprime_results(test_obj, working_dir) -> None: def check_mprime_results(test_obj, working_dir) -> None:
"""Check mprime log files and update test_obj.""" """Check mprime log files and update test_obj."""
passing_lines = {} passing_lines = set()
warning_lines = {} warning_lines = set()
def _read_file(log_name) -> list[str]: def _read_file(log_name) -> list[str]:
"""Read file and split into lines, returns list.""" """Read file and split into lines, returns list."""
@ -102,7 +102,7 @@ def check_mprime_results(test_obj, working_dir) -> None:
for line in _read_file('results.txt'): for line in _read_file('results.txt'):
line = line.strip() line = line.strip()
if re.search(r'(error|fail)', line, re.IGNORECASE): if re.search(r'(error|fail)', line, re.IGNORECASE):
warning_lines[line] = None warning_lines.add(line)
# prime.log (check if passed) # prime.log (check if passed)
for line in _read_file('prime.log'): for line in _read_file('prime.log'):
@ -112,10 +112,10 @@ def check_mprime_results(test_obj, working_dir) -> None:
if match: if match:
if int(match.group(2)) + int(match.group(3)) > 0: if int(match.group(2)) + int(match.group(3)) > 0:
# Errors and/or warnings encountered # Errors and/or warnings encountered
warning_lines[match.group(1).capitalize()] = None warning_lines.add(match.group(1).capitalize())
else: else:
# No errors/warnings # No errors/warnings
passing_lines[match.group(1).capitalize()] = None passing_lines.add(match.group(1).capitalize())
# Update status # Update status
if warning_lines: if warning_lines: