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

Remove the behavior of removing the double line breaks in python files #12

Merged
merged 1 commit into from
Jul 11, 2023
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
2 changes: 1 addition & 1 deletion pytest_examples/eval_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def format_black(self, example: CodeExample) -> None:
"""
self._check_update(example)

new_content = black_format(example.source, self.config, remove_double_blank=example.in_py_file())
new_content = black_format(example.source, self.config)
if new_content != example.source:
example.source = new_content
self._mark_for_update(example)
Expand Down
6 changes: 2 additions & 4 deletions pytest_examples/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,17 @@ def replace_offset(m: re.Match):
return stdout


def black_format(source: str, config: ExamplesConfig, *, remove_double_blank: bool = False) -> str:
def black_format(source: str, config: ExamplesConfig) -> str:
# hack to avoid black complaining about our print output format
before_black = re.sub(r'^( *#)> ', r'\1 > ', source, flags=re.M)
after_black = black_format_str(before_black, mode=config.black_mode())
# then revert it back
after_black = re.sub(r'^( *#) > ', r'\1> ', after_black, flags=re.M)
if remove_double_blank:
after_black = re.sub(r'\n{3}', '\n\n', after_black)
return after_black


def black_check(example: CodeExample, config: ExamplesConfig) -> None:
after_black = black_format(example.source, config, remove_double_blank=example.in_py_file())
after_black = black_format(example.source, config)
if example.source != after_black:
diff = code_diff(example, after_black)
raise FormatError(f'black failed:\n{indent(diff, " ")}')
Expand Down
2 changes: 2 additions & 0 deletions tests/cases_update/python_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def foobar():
```py
x = 4


class A:
pass


print(x)
#> 4
```
Expand Down