Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for checking if notebooks use show_anim() and show_plot() instead of matplotlib functions #43

Closed
wants to merge 7 commits into from
Closed
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
39 changes: 39 additions & 0 deletions test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,42 @@ def test_third_cell_contains_colab_header(notebook_filename):
assert len(nb.cells) > 2
assert nb.cells[2].cell_type == "code"
assert nb.cells[2].source == COLAB_HEADER


def test_cell_contains_output(notebook_filename):
"""checks if all notebook cells have an output present"""
with open(notebook_filename, encoding="utf8") as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
for cell in nb.cells:
if cell.cell_type == "code":
assert hasattr(cell, "outputs")

def test_show_plot_used_instead_of_matplotlib(notebook):
"""checks if plotting is done with open_atmos_jupyter_utils show_plot()"""
with open(notebook_filename, encoding="utf8") as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
matplot_used = False
show_plot_used = False
for cell in nb.cells:
if cell.cell_type == "code":
if "matplotlib" or "pyplot" in cell.source:
matplot_used = True
if "show_plot()" in cell.source:
show_plot_used = True
if matplot_used and not show_plot_used:
raise AssertionError("if using matplotlib, please use open_atmos_jupyter_utils.show_plot()")

def test_show_anim_used_instead_of_matplotlib(notebook):
"""checks if animation generation is done with open_atmos_jupyter_utils show_anim()"""
with open(notebook_filename, encoding="utf8") as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
matplot_used = False
show_anim_used = False
for cell in nb.cells:
if cell.cell_type == "code":
if "funcAnimation" in cell.source:
matplot_used = True
if "show_anim()" in cell.source:
show_anim_used = True
if matplot_used and not show_anim_used:
raise AssertionError("if using matplotlib for animations, please use open_atmos_jupyter_utils.show_anim()")