Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nbstripout/_nbstripout.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ def process_jupyter_notebook(
)

any_change = nb_orig != nb_stripped
# Early exit when writing in-place and nothing changes.
if not any_change and output_stream is input_stream:
return any_change

if args.dry_run:
if any_change:
Expand Down Expand Up @@ -410,6 +413,9 @@ def process_zeppelin_notebook(
nb_stripped = strip_zeppelin_output(nb)

any_change = nb_orig != nb_stripped
# Early exit when writing in-place and nothing changes.
if not any_change and output_stream is input_stream:
return any_change

if args.dry_run:
if any_change:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,21 @@ def test_make_errors(input_file: str, expected_errs: List[Union[str, Pattern]],
assert e.search(err_output)
else:
assert e in err_output


def test_nochange_notebook_unchanged():
ipynb_file = NOTEBOOKS_FOLDER / 'test_nochange.ipynb'
ipynb_mtime_before = ipynb_file.stat().st_mtime_ns

run([nbstripout_exe(), ipynb_file])
ipynb_mtime_after = ipynb_file.stat().st_mtime_ns

assert ipynb_mtime_after == ipynb_mtime_before

zpln_file = NOTEBOOKS_FOLDER / 'test_zeppelin.zpln.expected'
zpln_mtime_before = zpln_file.stat().st_mtime_ns

run([nbstripout_exe(), '--force', '--mode', 'zeppelin', zpln_file])
zpln_mtime_after = zpln_file.stat().st_mtime_ns

assert zpln_mtime_after == zpln_mtime_before