From 8d01895b325f0ca70577fe01ef013875770d3a09 Mon Sep 17 00:00:00 2001 From: Tim Nordell Date: Mon, 13 Jan 2025 16:52:57 -0600 Subject: [PATCH] scripts: Fixed several SyntaxWarning for python test helpers Many of these require a r'' string context to avoid errors like: scripts/test.py:105: SyntaxWarning: invalid escape sequence '\s' --- scripts/prettyasserts.py | 6 +++--- scripts/test.py | 38 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/scripts/prettyasserts.py b/scripts/prettyasserts.py index 925c14f0..ff33e27a 100755 --- a/scripts/prettyasserts.py +++ b/scripts/prettyasserts.py @@ -35,10 +35,10 @@ LEXEMES = { 'assert': ['assert'], 'arrow': ['=>'], 'string': [r'"(?:\\.|[^"])*"', r"'(?:\\.|[^'])\'"], - 'paren': ['\(', '\)'], + 'paren': [r'\(', r'\)'], 'cmp': CMP.keys(), - 'logic': ['\&\&', '\|\|'], - 'sep': [':', ';', '\{', '\}', ','], + 'logic': [r'\&\&', r'\|\|'], + 'sep': [':', ';', r'\{', r'\}', ','], 'op': ['->'], # specifically ops that conflict with cmp } diff --git a/scripts/test.py b/scripts/test.py index 6e8a201c..e7f78e4c 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -102,9 +102,9 @@ class TestCase: # the runner itself. for v_ in csplit(v): m = re.search(r'\brange\b\s*\(' - '(?P[^,\s]*)' - '\s*(?:,\s*(?P[^,\s]*)' - '\s*(?:,\s*(?P[^,\s]*)\s*)?)?\)', + r'(?P[^,\s]*)' + r'\s*(?:,\s*(?P[^,\s]*)' + r'\s*(?:,\s*(?P[^,\s]*)\s*)?)?\)', v_) if m: start = (int(m.group('start'), 0) @@ -163,8 +163,8 @@ class TestSuite: code_linenos = [] for i, line in enumerate(f): match = re.match( - '(?P\[\s*cases\s*\.\s*(?P\w+)\s*\])' - '|' '(?Pcode\s*=)', + r'(?P\[\s*cases\s*\.\s*(?P\w+)\s*\])' + r'|' r'(?Pcode\s*=)', line) if match and match.group('case'): case_linenos.append((i+1, match.group('name'))) @@ -602,9 +602,9 @@ def find_perms(runner_, ids=[], **args): errors='replace', close_fds=False) pattern = re.compile( - '^(?P[^\s]+)' - '\s+(?P[^\s]+)' - '\s+(?P\d+)/(?P\d+)') + r'^(?P[^\s]+)' + r'\s+(?P[^\s]+)' + r'\s+(?P\d+)/(?P\d+)') # skip the first line for line in it.islice(proc.stdout, 1, None): m = pattern.match(line) @@ -632,8 +632,8 @@ def find_perms(runner_, ids=[], **args): errors='replace', close_fds=False) pattern = re.compile( - '^(?P[^\s]+)' - '\s+(?P[^:]+):(?P\d+)') + r'^(?P[^\s]+)' + r'\s+(?P[^:]+):(?P\d+)') # skip the first line for line in it.islice(proc.stdout, 1, None): m = pattern.match(line) @@ -676,8 +676,8 @@ def find_path(runner_, id, **args): errors='replace', close_fds=False) pattern = re.compile( - '^(?P[^\s]+)' - '\s+(?P[^:]+):(?P\d+)') + r'^(?P[^\s]+)' + r'\s+(?P[^:]+):(?P\d+)') # skip the first line for line in it.islice(proc.stdout, 1, None): m = pattern.match(line) @@ -706,7 +706,7 @@ def find_defines(runner_, id, **args): errors='replace', close_fds=False) defines = co.OrderedDict() - pattern = re.compile('^(?P\w+)=(?P.+)') + pattern = re.compile(r'^(?P\w+)=(?P.+)') for line in proc.stdout: m = pattern.match(line) if m: @@ -781,12 +781,12 @@ def run_stage(name, runner_, ids, stdout_, trace_, output_, **args): failures = [] killed = False - pattern = re.compile('^(?:' - '(?Prunning|finished|skipped|powerloss) ' - '(?P(?P[^:]+)[^\s]*)' - '|' '(?P[^:]+):(?P\d+):(?Passert):' - ' *(?P.*)' - ')$') + pattern = re.compile(r'^(?:' + r'(?Prunning|finished|skipped|powerloss) ' + r'(?P(?P[^:]+)[^\s]*)' + r'|' r'(?P[^:]+):(?P\d+):(?Passert):' + r' *(?P.*)' + r')$') locals = th.local() children = set()