From 83aa604ce5d6b3de956de2a116b8fa1c6caefc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Sz=C3=A9pk=C3=BAti?= Date: Fri, 29 Oct 2021 12:06:19 +0200 Subject: [PATCH] Simplify regex and use named capture groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bence Szépkúti --- tests/scripts/test_psa_compliance.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index ca9387954e..dfd23938a2 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -52,7 +52,10 @@ def main(): proc = subprocess.Popen(['./psa-arch-tests-crypto'], bufsize=1, stdout=subprocess.PIPE, universal_newlines=True) - test_re = re.compile('^TEST(?:: ([0-9]*)| RESULT: (FAILED|PASSED))') + test_re = re.compile( + '^TEST: (?P[0-9]*)|' + '^TEST RESULT: (?PFAILED|PASSED)' + ) test = -1 unexpected_successes = set(EXPECTED_FAILURES) expected_failures = [] @@ -61,9 +64,11 @@ def main(): print(line, end='') match = test_re.match(line) if match is not None: - if match.group(1) is not None: - test = int(match.group(1)) - elif match.group(2) == 'FAILED': + groupdict = match.groupdict() + test_num = groupdict['test_num'] + if test_num is not None: + test = int(test_num) + elif groupdict['test_result'] == 'FAILED': try: unexpected_successes.remove(test) expected_failures.append(test)