Skip to content

Commit

Permalink
add test checking if all notebook code cells have execution_count att…
Browse files Browse the repository at this point in the history
…ribute (#29)
  • Loading branch information
slayoo committed Mar 17, 2024
1 parent d7f7ee8 commit f119020
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ jobs:
- run: pip install -r requirements.txt
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pytest -We .
run: pytest -vv -We .

15 changes: 15 additions & 0 deletions test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ def test_no_errors_or_warnings_in_output(notebook_filename):
for output in cell.outputs:
if "name" in output and output["name"] == "stderr":
raise AssertionError(output["text"])


def test_jetbrains_bug_py_66491(notebook_filename):
"""checks if all notebooks have the execution_count key for each cell in JSON what is
required by GitHub renderer and what happens not to be the case if generating the notebook
using buggy versions of PyCharm: https://youtrack.jetbrains.com/issue/PY-66491"""
with open(notebook_filename, encoding="utf8") as notebook_file:
notebook = nbformat.read(notebook_file, nbformat.NO_CONVERT)
for cell in notebook.cells:
if cell.cell_type == "code" and not hasattr(cell, "execution_count"):
raise AssertionError(
"notebook cell is missing the execution_count attribute"
+ " (could be due to a bug in PyCharm,"
+ " see https://youtrack.jetbrains.com/issue/PY-66491)"
)

0 comments on commit f119020

Please sign in to comment.