@staticmethod
def test_show_plot_used_if_notebook_uses_matplotlib(notebook):
""" checks if all notebooks use the open-atmos-jupyter-utils show_plot instead of pyplot.show() """
with open(notebook) as fp:
nb = nbformat.read(fp, nbformat.NO_CONVERT)
matplotlib_used = False
show_plot_used = False
for cell in nb.cells:
if cell.cell_type == "code":
if "matplotlib" in cell.source:
matplotlib_used = True
if "import open_atmos_jupyter_utils" in cell.source or "from open_atmos_jupyter_utils" in cell.source:
show_plot_used = True
if matplotlib_used and not show_plot_used:
raise AssertionError("if using matplotlib, please use open_atmos_jupyter_utils.show_plot()")
something like this should do: