Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten regex for output assertion parsing #157

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pytest_mypy_plugins/tests/test-regex-assertions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,22 @@
main: |
a = 'hello'
reveal_type(a) # NR: .*banana.*

- case: regex_against_callable_comment
main: |
from typing import Set, Union

def foo(bar: str, ham: int = 42) -> Set[Union[str, int]]:
return {bar, ham}
reveal_type(foo) # NR: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"

- case: regex_against_callable_out
regex: yes
main: |
from typing import Set, Union

def foo(bar: str, ham: int = 42) -> Set[Union[str, int]]:
return {bar, ham}
reveal_type(foo)
out: |
main:5: note: Revealed type is "def \(bar: builtins\.str, ham: builtins\.int =\) -> .*"
2 changes: 1 addition & 1 deletion pytest_mypy_plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex:
lines = render_template(out, params).split("\n")
for line in lines:
match = re.search(
r"^(?P<fname>.*):(?P<lnum>\d*): (?P<severity>.*):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
r"^(?P<fname>.+):(?P<lnum>\d+): (?P<severity>[A-Za-z]+):((?P<col>\d+):)? (?P<message>.*)$", line.strip()
)
if match:
if match.group("severity") == "E":
Expand Down
Loading