Skip to content

Commit

Permalink
pass config down
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 15, 2024
1 parent 4b8bffb commit 98958b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pytest_examples/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def black_format(source: str, config: ExamplesConfig, *, remove_double_blank: bo
def black_check(example: CodeExample, config: ExamplesConfig) -> None:
after_black = black_format(example.source, config, remove_double_blank=example.in_py_file())
if example.source != after_black:
diff = code_diff(example, after_black, config.white_space_dot)
diff = code_diff(example, after_black, config)
raise FormatError(f'black failed:\n{indent(diff, " ")}')


def code_diff(example: CodeExample, after: str, white_space_dot: bool) -> str:
diff = black_diff(sub_space(example.source, white_space_dot), sub_space(after, white_space_dot), 'before', 'after')
def code_diff(example: CodeExample, after: str, config: ExamplesConfig) -> str:
diff = black_diff(sub_space(example.source, config), sub_space(after, config), 'before', 'after')

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))
Expand All @@ -95,8 +95,8 @@ def replace_at_line(match: re.Match) -> str:
return re.sub(r'^(@@\s*)(.*)(\s*@@)$', replace_at_line, diff, flags=re.M)


def sub_space(text: str, white_space_dot: bool) -> str:
if white_space_dot:
def sub_space(text: str, config: ExamplesConfig) -> str:
if config.white_space_dot:
return text.replace(' ', '·')
else:
return text
2 changes: 1 addition & 1 deletion pytest_examples/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __exit__(self, *args) -> None:
def check_print_statements(self, example: CodeExample) -> None:
new_code = self.updated_print_statements(example)
if new_code is not None:
diff = code_diff(example, new_code, self.config.white_space_dot)
diff = code_diff(example, new_code, self.config)
pytest.fail(f'Print output changed code:\n{indent(diff, " ")}', pytrace=False)

def updated_print_statements(self, example: CodeExample) -> str | None:
Expand Down

0 comments on commit 98958b4

Please sign in to comment.