From 11bea07a17a300f37414c8405a382952f6f3a2e9 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Fri, 15 Jan 2021 00:28:59 +0100 Subject: [PATCH] Test that `py:percent` scripts end with exactly one blank line (#682) --- docs/CHANGELOG.md | 3 +++ tests/test_pep8.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index abe4b7adf..f93601cb9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,9 @@ Jupytext ChangeLog **Changed** - Jupytext does not work properly with the new cell ids of the version 4.5 of `nbformat>=5.1.0` yet, so we added the requirement `nbformat<=5.0.8` (#715) +**Added** +- Added a test that ensures that `py:percent` scripts end with exactly one blank line (#682) + 1.9.1 (2021-01-06) ------------------ diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 00c5c8cde..1c16a0b29 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -1,4 +1,6 @@ import pytest +from nbformat.v4.nbbase import new_code_cell, new_notebook + from jupytext.compare import compare from jupytext import read, reads, writes from jupytext.pep8 import ( @@ -199,3 +201,19 @@ def test_no_metadata_when_py_is_pep8(py_file): assert cell.metadata == {"lines_to_next_cell": 0}, py_file else: assert not cell.metadata, (py_file, cell.source) + + +def test_notebook_ends_with_exactly_one_empty_line_682(): + """(Issue #682) + Steps to reproduce: + + Have a notebook that ends in a python code cell (with no empty lines at the end of the cell). + run jupytext --to py:percent notebookWithCodeCell.ipynb. + See that the generated python code file has two empty lines at the end. + + I would expect there to just be one new line.""" + nb = new_notebook( + cells=[new_code_cell("1+1")], metadata={"jupytext": {"main_language": "python"}} + ) + py = writes(nb, "py:percent") + assert py.endswith("1+1\n")