From 7b5634ae3dd56a01c904deed50ed1975fffc2462 Mon Sep 17 00:00:00 2001 From: Kyle Johnsen Date: Thu, 1 Feb 2024 12:37:04 -0500 Subject: [PATCH] fix overview nb execution test --- tests/test_docs.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/test_docs.py b/tests/test_docs.py index 4fc0a11..20ee498 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,22 +1,29 @@ -import os +from logging import getLogger +from pathlib import Path -from myst_nb.converter import myst_to_notebook -from myst_parser.main import MdParserConfig -from nbconvert.preprocessors import ExecutePreprocessor import pytest +from myst_nb.core.config import NbParserConfig +from myst_nb.core.execute import create_client +from myst_nb.core.read import read_myst_markdown_notebook @pytest.mark.slow def test_overview_notebook_execution(): - notebook_path = os.path.join(os.getcwd(), "docs", "overview.md") + current_dir = Path(__file__).resolve().parent + project_root = current_dir.parent + notebook_path = project_root / "docs" / "overview.md" + with open(notebook_path, "r") as file: - text = file.read() - config = MdParserConfig() - nb = myst_to_notebook(text, config) - ep = ExecutePreprocessor(timeout=600, kernel_name="python3") + nb = read_myst_markdown_notebook(file.read()) + + with create_client( + nb, notebook_path, NbParserConfig(), getLogger(), None + ) as nb_client: + pass # executes notebook + exec_result = nb_client.exec_metadata + assert exec_result["succeeded"] + assert exec_result["runtime"] > 0 - # Execute the notebook - ep.preprocess(nb) for cell in nb["cells"]: if cell["cell_type"] == "code": last_code_cell = cell