diff --git a/pre_commit_hooks/string_fixer_for_jupyter_notebooks.py b/pre_commit_hooks/string_fixer_for_jupyter_notebooks.py index 1ab47f4..f363d57 100644 --- a/pre_commit_hooks/string_fixer_for_jupyter_notebooks.py +++ b/pre_commit_hooks/string_fixer_for_jupyter_notebooks.py @@ -30,8 +30,8 @@ def fix_strings(filename: str) -> int: if fixed != source_in_1_line: fixed_lines = fixed.split('\n') cell['source'] = ( - [_ + '\n' for _ in fixed_lines[:-1]] - + [fixed_lines[-1]] + [_ + '\n' for _ in fixed_lines[:-1]] + + [fixed_lines[-1]] ) return_value = 1 @@ -41,7 +41,7 @@ def fix_strings(filename: str) -> int: json.dump(notebook_contents, f, indent=1) # Jupyter notebooks (.ipynb) always ends with a new line # but json.dump does not. - f.write("\n") + f.write('\n') return return_value diff --git a/tests/string_fixer_for_jupyter_notebooks_test.py b/tests/string_fixer_for_jupyter_notebooks_test.py index f86fec9..e04efd2 100644 --- a/tests/string_fixer_for_jupyter_notebooks_test.py +++ b/tests/string_fixer_for_jupyter_notebooks_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from pre_commit_hooks.string_fixer_for_jupyter_notebooks import main @@ -10,6 +12,7 @@ TESTS = ( ('jupyter_case_2.ipynb', 'jupyter_case_2.ipynb', 0), ) + @pytest.mark.parametrize(('input_file', 'output_file', 'expected_retv'), TESTS) def test_rewrite(input_file, output_file, expected_retv, tmpdir): with open(get_resource_path(input_file)) as f: