From 07fe570805f4a8142ebf504a9f22a1a59a1de906 Mon Sep 17 00:00:00 2001 From: Sfonxu <89732829+Sfonxu@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:39:43 +0100 Subject: [PATCH 1/7] add test to check if all code cells have outputs --- test_notebooks.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test_notebooks.py b/test_notebooks.py index 11d3681..4e8eed7 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -171,3 +171,12 @@ 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(hasatrr(cell, "outputs") + From 5ced687c0d5fb7438724a6ae04ad4eac772246bb Mon Sep 17 00:00:00 2001 From: Sfonxu <89732829+Sfonxu@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:44:34 +0100 Subject: [PATCH 2/7] added missing delimiter --- test_notebooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_notebooks.py b/test_notebooks.py index 4e8eed7..303270e 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -178,5 +178,5 @@ def test_cell_contains_output(notebook_filename): nb = nbformat.read(fp, nbformat.NO_CONVERT) for cell in nb.cells: if cell.cell_type == "code": - assert(hasatrr(cell, "outputs") + assert(hasatrr(cell, "outputs")) From 5df082223b360ea5876685f552b94d4e123b733d Mon Sep 17 00:00:00 2001 From: Sfonxu <89732829+Sfonxu@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:47:06 +0100 Subject: [PATCH 3/7] fixed formatting --- test_notebooks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test_notebooks.py b/test_notebooks.py index 303270e..ef73123 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -178,5 +178,4 @@ def test_cell_contains_output(notebook_filename): nb = nbformat.read(fp, nbformat.NO_CONVERT) for cell in nb.cells: if cell.cell_type == "code": - assert(hasatrr(cell, "outputs")) - + assert hasattr(cell, "outputs") From 2d708cb64ad9ce5daf91e6f273f8c006fa8c7dbe Mon Sep 17 00:00:00 2001 From: sfonxu Date: Fri, 15 Nov 2024 19:53:54 +0100 Subject: [PATCH 4/7] formmating commit --- test_notebooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_notebooks.py b/test_notebooks.py index ef73123..b370911 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -178,4 +178,4 @@ def test_cell_contains_output(notebook_filename): nb = nbformat.read(fp, nbformat.NO_CONVERT) for cell in nb.cells: if cell.cell_type == "code": - assert hasattr(cell, "outputs") + assert hasattr(cell, "outputs")a From 9b03d30f9c398583010cedc2dd5c22b59fa15c37 Mon Sep 17 00:00:00 2001 From: sfonxu Date: Fri, 15 Nov 2024 19:55:15 +0100 Subject: [PATCH 5/7] formmating commit --- test_notebooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_notebooks.py b/test_notebooks.py index b370911..ef73123 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -178,4 +178,4 @@ def test_cell_contains_output(notebook_filename): nb = nbformat.read(fp, nbformat.NO_CONVERT) for cell in nb.cells: if cell.cell_type == "code": - assert hasattr(cell, "outputs")a + assert hasattr(cell, "outputs") From 73b46fd31f2cf1df36bbdfa3da2d30c2e555ae9d Mon Sep 17 00:00:00 2001 From: sfonxu Date: Fri, 15 Nov 2024 19:57:27 +0100 Subject: [PATCH 6/7] formmating commit --- test_notebooks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_notebooks.py b/test_notebooks.py index ef73123..64e8cd1 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -172,6 +172,7 @@ def test_third_cell_contains_colab_header(notebook_filename): 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: From 14e98bdcaaf252c30bb24a8fa859cf8497ac6cbc Mon Sep 17 00:00:00 2001 From: sfonxu Date: Wed, 27 Nov 2024 12:14:08 +0100 Subject: [PATCH 7/7] added tests for open_atmos_jupyter_utils show_plot() and show_anim() usage --- test_notebooks.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test_notebooks.py b/test_notebooks.py index 64e8cd1..912fe42 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -180,3 +180,33 @@ def test_cell_contains_output(notebook_filename): 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()")