Skip to content

Commit

Permalink
fix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 15, 2024
1 parent ec05504 commit 062db5e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions pytest_examples/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ def replace_at_line(match: re.Match) -> str:
offset = re.sub(r'\d+', lambda m: str(int(m.group(0)) + example.start_line), match.group(2))
return f'{match.group(1)}{offset}{match.group(3)}'

# we could add `.replace(' ', '·')` to make white space easier to understand
return re.sub(r'^(@@\s*)(.*)(\s*@@)$', replace_at_line, diff, flags=re.M)
2 changes: 1 addition & 1 deletion pytest_examples/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __exit__(self, *args) -> None:
def check_print_statements(self, example: CodeExample) -> None:
with_prints = self._insert_print_statements(example)
# we check against the raw `with_prints` and `with_prints` with trailing whitespace removed
if example.source != with_prints and example.source != re.sub(r'\s+\n', '\n', with_prints):
if example.source != with_prints and example.source != re.sub(r'[ \t]+\n', '\n', with_prints):
diff = code_diff(example, with_prints)
pytest.fail(f'Print output changed code:\n{indent(diff, " ")}', pytrace=False)

Expand Down
1 change: 1 addition & 0 deletions tests/test_run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def test_print_check_spaces(pytester: pytest.Pytester):
```py
# note trailing space
print('hello ')
#> hello
```""",
Expand Down

0 comments on commit 062db5e

Please sign in to comment.