Skip to content

Commit

Permalink
test single_blank_line_after_doc_string() with module docstring and l…
Browse files Browse the repository at this point in the history
…onger comment in test notebooks
  • Loading branch information
janosh committed Mar 3, 2024
1 parent 04efa4a commit 14360fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ no_implicit_optional = false
target-version = "py310"
select = ["ALL"]
ignore = [
"COM812", # trailing comma missing
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D205", # 1 blank line required between summary line and description
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/clean_nb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""module doc string."""

# %%
foo = "hello"

Expand All @@ -9,6 +11,7 @@
# %% a comment following a cell delimiter with too much space
baz = 42

"""longer comment"""

# %% empty cell with comment (should not be removed despite empty)

Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/raw_nb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"""module doc string."""


# %%
foo = "hello"
# %%a comment following a cell delimiter without space
bar = "world"
# %% a comment following a cell delimiter with too much space
baz = 42

"""longer comment"""



# %% empty cell with comment (should not be removed despite empty)


Expand Down
15 changes: 12 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import difflib
import filecmp
import shutil
from importlib.metadata import version
Expand All @@ -15,10 +16,18 @@ def test_main_format_cells(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -
shutil.copy2(clean_nb, clean_tmp := str(tmp_path / "clean_nb.py"))

ret = main((raw_tmp, clean_tmp))

assert ret == 1
assert filecmp.cmp(raw_tmp, clean_nb), "Formatted file has unexpected content"
assert filecmp.cmp(clean_tmp, clean_nb), "clean file should not have changed"

with open(clean_nb) as file, open(clean_tmp) as tmp_file:
clean_lines, tmp_lines = file.readlines(), tmp_file.readlines()
file_diff = "\n".join(difflib.unified_diff(clean_lines, tmp_lines))

assert filecmp.cmp(
raw_tmp, clean_nb, shallow=False
), f"Formatted file has unexpected content:\n{file_diff}"
assert filecmp.cmp(
clean_tmp, clean_nb, shallow=False
), "clean file should not have changed"

out, err = capsys.readouterr()
assert out == f"Rewriting {raw_tmp}\n"
Expand Down

0 comments on commit 14360fc

Please sign in to comment.