Skip to content

Commit 5d89e38

Browse files
committed
fix notebook test
1 parent 7efde37 commit 5d89e38

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tests/test_notebook_demos_extra.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,31 @@ def test_demo_notebook_09en_dynamic_traffic_assignment():
183183
exception_words = [ "ResultGUIViewer", "%matplotlib"]
184184

185185
notebook_dir = "demos_and_examples"
186+
186187
for notebook in os.listdir(notebook_dir):
187-
if notebook.endswith(".ipynb") and "demo_notebook_09en_dynamic_traffic_assignment" in notebook :
188+
if notebook.endswith(".ipynb") and "demo_notebook_09en_dynamic_traffic_assignment" in notebook:
188189
full_path = os.path.join(notebook_dir, notebook)
190+
189191
with open(full_path, "r", encoding="utf-8") as f:
190192
nb = nbformat.read(f, as_version=4)
191193

192-
for cell in nb.cells:
193-
if cell.cell_type == "code":
194-
if sum([word in cell.source for word in exception_words]) > 0:
195-
print(f"Skipping cell in {notebook}: {cell.source[:50]}...")
196-
continue
197-
198-
print("Testing:", cell.source[:50])
199-
try:
200-
exec(cell.source)
201-
except Exception as e:
202-
pytest.fail(f"Error in notebook {notebook}, cell:\n{cell.source}\n\nError: {str(e)}")
194+
# カスタムプリプロセッサを使用
195+
ep = SkipCellsPreprocessor(
196+
exception_words=exception_words,
197+
timeout=1800,
198+
kernel_name='python3'
199+
)
200+
201+
try:
202+
# ノートブックを実行
203+
print(f"Testing notebook: {notebook}")
204+
ep.preprocess(nb, {'metadata': {'path': notebook_dir}})
205+
print(f"Successfully executed all non-skipped cells in {notebook}")
206+
except CellExecutionError as e:
207+
# エラーが発生したセルの情報を出力
208+
print(f"Error executing notebook {notebook}")
209+
print(f"Error: {str(e)}")
210+
pytest.fail(f"Error executing notebook {notebook}: {str(e)}")
203211

204212

205213

0 commit comments

Comments
 (0)