mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 03:06:54 +00:00
Add more test cases
This commit is contained in:
parent
86dc39a572
commit
e49feed735
4 changed files with 172 additions and 4 deletions
|
|
@ -1,16 +1,25 @@
|
|||
import pytest
|
||||
|
||||
from pre_commit_hooks.string_fixer_for_jupyter_notebooks import main
|
||||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
def test_rewrite(tmpdir):
|
||||
with open(get_resource_path('before.ipynb')) as f:
|
||||
TESTS = (
|
||||
('jupyter_case_1_before.ipynb', 'jupyter_case_1_after.ipynb', 1),
|
||||
# the file in Case 2 is not altered, so we reload the same file
|
||||
('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:
|
||||
before_contents = f.read()
|
||||
|
||||
with open(get_resource_path('after.ipynb')) as f:
|
||||
with open(get_resource_path(output_file)) as f:
|
||||
after_contents = f.read()
|
||||
|
||||
path = tmpdir.join('file.ipynb')
|
||||
path.write(before_contents)
|
||||
retval = main([str(path)])
|
||||
assert path.read() == after_contents
|
||||
assert retval == 1
|
||||
assert retval == expected_retv
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue