Skip to content

Commit a241857

Browse files
committed
refactor: since we are showing regexes, make them a bit simpler
The old code would always wrap the regex in a needless `(?s:...)` parenthesis. Path aliases are always single regexes, so they don't need that extra wrapping. This makes logged path maps easier to understand.
1 parent edbb54a commit a241857

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

coverage/misc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ def bool_or_none(b):
182182

183183
def join_regex(regexes):
184184
"""Combine a series of regexes into one that matches any of them."""
185-
return "|".join(f"(?:{r})" for r in regexes)
185+
regexes = list(regexes)
186+
if len(regexes) == 1:
187+
return regexes[0]
188+
else:
189+
return "|".join(f"(?:{r})" for r in regexes)
186190

187191

188192
def file_be_gone(path):

tests/test_files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ def test_multiple_patterns(self, rel_yn):
309309
assert msgs == [
310310
"Aliases (relative=True):",
311311
" Rule: '/home/*/src' -> './mysrc/' using regex " +
312-
"'(?:(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/]))'",
312+
"'(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/])'",
313313
" Rule: '/lib/*/libsrc' -> './mylib/' using regex " +
314-
"'(?:(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/]))'",
314+
"'(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/])'",
315315
"Matched path '/home/foo/src/a.py' to rule '/home/*/src' -> './mysrc/', " +
316316
"producing './mysrc/a.py'",
317317
"Matched path '/lib/foo/libsrc/a.py' to rule '/lib/*/libsrc' -> './mylib/', " +
@@ -321,9 +321,9 @@ def test_multiple_patterns(self, rel_yn):
321321
assert msgs == [
322322
"Aliases (relative=False):",
323323
" Rule: '/home/*/src' -> './mysrc/' using regex " +
324-
"'(?:(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/]))'",
324+
"'(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/])'",
325325
" Rule: '/lib/*/libsrc' -> './mylib/' using regex " +
326-
"'(?:(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/]))'",
326+
"'(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/])'",
327327
"Matched path '/home/foo/src/a.py' to rule '/home/*/src' -> './mysrc/', " +
328328
f"producing {files.canonical_filename('./mysrc/a.py')!r}",
329329
"Matched path '/lib/foo/libsrc/a.py' to rule '/lib/*/libsrc' -> './mylib/', " +

0 commit comments

Comments
 (0)