Skip to content

Commit

Permalink
add notebook 05 (colab) for test
Browse files Browse the repository at this point in the history
  • Loading branch information
toruseo committed Oct 8, 2024
1 parent 978dbdf commit 4f87259
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/test_notebook_demos.py
Original file line number Diff line number Diff line change
@@ -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.
"""

Expand Down Expand Up @@ -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)}")

0 comments on commit 4f87259

Please sign in to comment.