mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-07 20:26:54 +00:00
Merge branch 'check-strings-in-jupyter-notebooks' of https://github.com/cyyc1/pre-commit-hooks into check-strings-in-jupyter-notebooks
This commit is contained in:
commit
5ea4ae8e87
2 changed files with 6 additions and 3 deletions
|
|
@ -30,8 +30,8 @@ def fix_strings(filename: str) -> int:
|
||||||
if fixed != source_in_1_line:
|
if fixed != source_in_1_line:
|
||||||
fixed_lines = fixed.split('\n')
|
fixed_lines = fixed.split('\n')
|
||||||
cell['source'] = (
|
cell['source'] = (
|
||||||
[_ + '\n' for _ in fixed_lines[:-1]]
|
[_ + '\n' for _ in fixed_lines[:-1]] +
|
||||||
+ [fixed_lines[-1]]
|
[fixed_lines[-1]]
|
||||||
)
|
)
|
||||||
return_value = 1
|
return_value = 1
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ def fix_strings(filename: str) -> int:
|
||||||
json.dump(notebook_contents, f, indent=1)
|
json.dump(notebook_contents, f, indent=1)
|
||||||
# Jupyter notebooks (.ipynb) always ends with a new line
|
# Jupyter notebooks (.ipynb) always ends with a new line
|
||||||
# but json.dump does not.
|
# but json.dump does not.
|
||||||
f.write("\n")
|
f.write('\n')
|
||||||
|
|
||||||
return return_value
|
return return_value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pre_commit_hooks.string_fixer_for_jupyter_notebooks import main
|
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),
|
('jupyter_case_2.ipynb', 'jupyter_case_2.ipynb', 0),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('input_file', 'output_file', 'expected_retv'), TESTS)
|
@pytest.mark.parametrize(('input_file', 'output_file', 'expected_retv'), TESTS)
|
||||||
def test_rewrite(input_file, output_file, expected_retv, tmpdir):
|
def test_rewrite(input_file, output_file, expected_retv, tmpdir):
|
||||||
with open(get_resource_path(input_file)) as f:
|
with open(get_resource_path(input_file)) as f:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue