From 98958b493bfd4c5e59cf3692bdb72f624eb07e27 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Fri, 15 Nov 2024 20:25:27 +0000 Subject: [PATCH] pass config down --- pytest_examples/lint.py | 10 +++++----- pytest_examples/run_code.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pytest_examples/lint.py b/pytest_examples/lint.py index 0aa9239..cec01cb 100644 --- a/pytest_examples/lint.py +++ b/pytest_examples/lint.py @@ -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)) @@ -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 diff --git a/pytest_examples/run_code.py b/pytest_examples/run_code.py index 7a925c1..737cd28 100644 --- a/pytest_examples/run_code.py +++ b/pytest_examples/run_code.py @@ -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: