From 01ad5e21ef573868ded73c574d9fdbf72f5b8066 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 12:23:55 +0100 Subject: [PATCH 1/3] added tests for show_anim() and show_plot() --- test_notebooks.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test_notebooks.py b/test_notebooks.py index 70baf99..374e9f6 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -182,3 +182,33 @@ def test_cell_contains_output(notebook_filename): for cell in nb.cells: if cell.cell_type == "code" and cell.source != "": assert cell.execution_count is not None + +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()") From 4c9493b0df26bb4a246fca2a73fd788c07213403 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 14:54:13 +0100 Subject: [PATCH 2/3] fixed formatting errors --- test_notebooks.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test_notebooks.py b/test_notebooks.py index 374e9f6..22f70df 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -183,7 +183,8 @@ def test_cell_contains_output(notebook_filename): if cell.cell_type == "code" and cell.source != "": assert cell.execution_count is not None -def test_show_plot_used_instead_of_matplotlib(notebook): + +def test_show_plot_used_instead_of_matplotlib(notebook_filename): """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) @@ -191,14 +192,17 @@ def test_show_plot_used_instead_of_matplotlib(notebook): show_plot_used = False for cell in nb.cells: if cell.cell_type == "code": - if "matplotlib" or "pyplot" in cell.source: + if "matplotlib" in cell.source 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()") + raise AssertionError( + "if using matplotlib, please use open_atmos_jupyter_utils.show_plot()" + ) -def test_show_anim_used_instead_of_matplotlib(notebook): + +def test_show_anim_used_instead_of_matplotlib(notebook_filename): """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) @@ -211,4 +215,6 @@ def test_show_anim_used_instead_of_matplotlib(notebook): 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()") + raise AssertionError( + "if using matplotlib for animations, please use open_atmos_jupyter_utils.show_anim()" + ) From 86cf40c4bdd1dcc735ad30dcc3c2bc053defdc7d Mon Sep 17 00:00:00 2001 From: sfonxu Date: Thu, 28 Nov 2024 23:01:55 +0100 Subject: [PATCH 3/3] fixed string formatting --- test_notebooks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_notebooks.py b/test_notebooks.py index 22f70df..94ec904 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -216,5 +216,6 @@ def test_show_anim_used_instead_of_matplotlib(notebook_filename): 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()" + """if using matplotlib for animations, + please use open_atmos_jupyter_utils.show_anim()""" )