diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-10-03 10:08:44 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-10-15 13:58:50 -0400 |
commit | c28544cc9a0c5113bd3a9279f47a2b7ea8826980 (patch) | |
tree | 66fc200a5044ead1a3a24d7a34b65a557ac5ac3e | |
parent | 7836b4faa320cccdeb25966dd8fefcf89107c564 (diff) | |
download | python-coveragepy-git-c28544cc9a0c5113bd3a9279f47a2b7ea8826980.tar.gz |
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.
-rw-r--r-- | coverage/misc.py | 6 | ||||
-rw-r--r-- | tests/test_files.py | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index 98a5d139..e3c67bc6 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -182,7 +182,11 @@ def bool_or_none(b): def join_regex(regexes): """Combine a series of regexes into one that matches any of them.""" - return "|".join(f"(?:{r})" for r in regexes) + regexes = list(regexes) + if len(regexes) == 1: + return regexes[0] + else: + return "|".join(f"(?:{r})" for r in regexes) def file_be_gone(path): diff --git a/tests/test_files.py b/tests/test_files.py index 3f3caae6..8ce2d5f7 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -309,9 +309,9 @@ class PathAliasesTest(CoverageTest): assert msgs == [ "Aliases (relative=True):", " Rule: '/home/*/src' -> './mysrc/' using regex " + - "'(?:(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/]))'", + "'(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/])'", " Rule: '/lib/*/libsrc' -> './mylib/' using regex " + - "'(?:(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/]))'", + "'(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/])'", "Matched path '/home/foo/src/a.py' to rule '/home/*/src' -> './mysrc/', " + "producing './mysrc/a.py'", "Matched path '/lib/foo/libsrc/a.py' to rule '/lib/*/libsrc' -> './mylib/', " + @@ -321,9 +321,9 @@ class PathAliasesTest(CoverageTest): assert msgs == [ "Aliases (relative=False):", " Rule: '/home/*/src' -> './mysrc/' using regex " + - "'(?:(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/]))'", + "'(?s:[\\\\\\\\/]home[\\\\\\\\/].*[\\\\\\\\/]src[\\\\\\\\/])'", " Rule: '/lib/*/libsrc' -> './mylib/' using regex " + - "'(?:(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/]))'", + "'(?s:[\\\\\\\\/]lib[\\\\\\\\/].*[\\\\\\\\/]libsrc[\\\\\\\\/])'", "Matched path '/home/foo/src/a.py' to rule '/home/*/src' -> './mysrc/', " + f"producing {files.canonical_filename('./mysrc/a.py')!r}", "Matched path '/lib/foo/libsrc/a.py' to rule '/lib/*/libsrc' -> './mylib/', " + |