From 4f8725996d75555ca8fd9918783a201dc18a84c9 Mon Sep 17 00:00:00 2001 From: Toru Seo <34780089+toruseo@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:14:15 +0900 Subject: [PATCH] add notebook 05 (colab) for test --- tests/test_notebook_demos.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_notebook_demos.py b/tests/test_notebook_demos.py index 3e9ea0e..44b9ecd 100644 --- a/tests/test_notebook_demos.py +++ b/tests/test_notebook_demos.py @@ -1,5 +1,5 @@ """ -This script test `demo_notebook_01en.ipynb` and `demo_notebook_01jp.ipynb` can run without error. +This script test `demo_notebook_01en.ipynb`, `demo_notebook_01jp.ipynb`, and `demo_notebook_05en_for_google_colab.ipynb` can run without error. Implementation is awkward, but it works. Other jupyter notebook demos are not tested. """ @@ -51,3 +51,23 @@ def test_demo_notebook_01jp(): except Exception as e: pytest.fail(f"Error in notebook {notebook}, cell:\n{cell.source}\n\nError: {str(e)}") +def test_demo_notebook_05en(): + notebook_dir = "demos_and_examples" + for notebook in os.listdir(notebook_dir): + if notebook.endswith(".ipynb") and "demo_notebook_05en_for_google_colab" in notebook : + full_path = os.path.join(notebook_dir, notebook) + with open(full_path, "r", encoding="utf-8") as f: + nb = nbformat.read(f, as_version=4) + + for cell in nb.cells: + if cell.cell_type == "code": + if "ResultGUIViewer" in cell.source or "%matplotlib" in cell.source or "!pip" in cell.source: + print(f"Skipping cell in {notebook}: {cell.source[:50]}...") + continue + + print("Testing:", cell.source[:50]) + try: + exec(cell.source) + except Exception as e: + pytest.fail(f"Error in notebook {notebook}, cell:\n{cell.source}\n\nError: {str(e)}") +