Skip to content

Commit 8d01895

Browse files
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'
1 parent 0494ce7 commit 8d01895

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

scripts/prettyasserts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
'assert': ['assert'],
3636
'arrow': ['=>'],
3737
'string': [r'"(?:\\.|[^"])*"', r"'(?:\\.|[^'])\'"],
38-
'paren': ['\(', '\)'],
38+
'paren': [r'\(', r'\)'],
3939
'cmp': CMP.keys(),
40-
'logic': ['\&\&', '\|\|'],
41-
'sep': [':', ';', '\{', '\}', ','],
40+
'logic': [r'\&\&', r'\|\|'],
41+
'sep': [':', ';', r'\{', r'\}', ','],
4242
'op': ['->'], # specifically ops that conflict with cmp
4343
}
4444

scripts/test.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def parse_define(v):
102102
# the runner itself.
103103
for v_ in csplit(v):
104104
m = re.search(r'\brange\b\s*\('
105-
'(?P<start>[^,\s]*)'
106-
'\s*(?:,\s*(?P<stop>[^,\s]*)'
107-
'\s*(?:,\s*(?P<step>[^,\s]*)\s*)?)?\)',
105+
r'(?P<start>[^,\s]*)'
106+
r'\s*(?:,\s*(?P<stop>[^,\s]*)'
107+
r'\s*(?:,\s*(?P<step>[^,\s]*)\s*)?)?\)',
108108
v_)
109109
if m:
110110
start = (int(m.group('start'), 0)
@@ -163,8 +163,8 @@ def __init__(self, path, args={}):
163163
code_linenos = []
164164
for i, line in enumerate(f):
165165
match = re.match(
166-
'(?P<case>\[\s*cases\s*\.\s*(?P<name>\w+)\s*\])'
167-
'|' '(?P<code>code\s*=)',
166+
r'(?P<case>\[\s*cases\s*\.\s*(?P<name>\w+)\s*\])'
167+
r'|' r'(?P<code>code\s*=)',
168168
line)
169169
if match and match.group('case'):
170170
case_linenos.append((i+1, match.group('name')))
@@ -602,9 +602,9 @@ def find_perms(runner_, ids=[], **args):
602602
errors='replace',
603603
close_fds=False)
604604
pattern = re.compile(
605-
'^(?P<case>[^\s]+)'
606-
'\s+(?P<flags>[^\s]+)'
607-
'\s+(?P<filtered>\d+)/(?P<perms>\d+)')
605+
r'^(?P<case>[^\s]+)'
606+
r'\s+(?P<flags>[^\s]+)'
607+
r'\s+(?P<filtered>\d+)/(?P<perms>\d+)')
608608
# skip the first line
609609
for line in it.islice(proc.stdout, 1, None):
610610
m = pattern.match(line)
@@ -632,8 +632,8 @@ def find_perms(runner_, ids=[], **args):
632632
errors='replace',
633633
close_fds=False)
634634
pattern = re.compile(
635-
'^(?P<case>[^\s]+)'
636-
'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
635+
r'^(?P<case>[^\s]+)'
636+
r'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
637637
# skip the first line
638638
for line in it.islice(proc.stdout, 1, None):
639639
m = pattern.match(line)
@@ -676,8 +676,8 @@ def find_path(runner_, id, **args):
676676
errors='replace',
677677
close_fds=False)
678678
pattern = re.compile(
679-
'^(?P<case>[^\s]+)'
680-
'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
679+
r'^(?P<case>[^\s]+)'
680+
r'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
681681
# skip the first line
682682
for line in it.islice(proc.stdout, 1, None):
683683
m = pattern.match(line)
@@ -706,7 +706,7 @@ def find_defines(runner_, id, **args):
706706
errors='replace',
707707
close_fds=False)
708708
defines = co.OrderedDict()
709-
pattern = re.compile('^(?P<define>\w+)=(?P<value>.+)')
709+
pattern = re.compile(r'^(?P<define>\w+)=(?P<value>.+)')
710710
for line in proc.stdout:
711711
m = pattern.match(line)
712712
if m:
@@ -781,12 +781,12 @@ def run_stage(name, runner_, ids, stdout_, trace_, output_, **args):
781781
failures = []
782782
killed = False
783783

784-
pattern = re.compile('^(?:'
785-
'(?P<op>running|finished|skipped|powerloss) '
786-
'(?P<id>(?P<case>[^:]+)[^\s]*)'
787-
'|' '(?P<path>[^:]+):(?P<lineno>\d+):(?P<op_>assert):'
788-
' *(?P<message>.*)'
789-
')$')
784+
pattern = re.compile(r'^(?:'
785+
r'(?P<op>running|finished|skipped|powerloss) '
786+
r'(?P<id>(?P<case>[^:]+)[^\s]*)'
787+
r'|' r'(?P<path>[^:]+):(?P<lineno>\d+):(?P<op_>assert):'
788+
r' *(?P<message>.*)'
789+
r')$')
790790
locals = th.local()
791791
children = set()
792792

0 commit comments

Comments
 (0)