mirror of
https://github.com/microsoft/graphrag.git
synced 2025-07-06 16:41:34 +00:00

* Fix notebook test runs * Delete old issue template * Add notebook CI action * Print temp directories * Print more env * Move printing up * Use runner_temp * Try using current directory * Try TMP env * Re-write TMP * Wrong yml * Fix echo * Only export if windows * More logging * Move export * Reformat env write * Fix braces * Switch to in-memory execution * Downgrade action perms * Unused import
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
# Copyright (c) 2024 Microsoft Corporation.
|
|
# Licensed under the MIT License
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import nbformat
|
|
import pytest
|
|
|
|
NOTEBOOKS_PATH = Path("examples_notebooks")
|
|
|
|
notebooks_list = list(NOTEBOOKS_PATH.rglob("*.ipynb"))
|
|
|
|
|
|
def _notebook_run(filepath: Path):
|
|
"""Execute a notebook via nbconvert and collect output.
|
|
:returns execution errors
|
|
"""
|
|
args = [
|
|
"jupyter",
|
|
"nbconvert",
|
|
"--to",
|
|
"notebook",
|
|
"--execute",
|
|
"-y",
|
|
"--no-prompt",
|
|
"--stdout",
|
|
filepath.absolute().as_posix(),
|
|
]
|
|
notebook = subprocess.check_output(args)
|
|
nb = nbformat.reads(notebook, nbformat.current_nbformat)
|
|
|
|
return [
|
|
output
|
|
for cell in nb.cells
|
|
if "outputs" in cell
|
|
for output in cell["outputs"]
|
|
if output.output_type == "error"
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("notebook_path", notebooks_list)
|
|
def test_notebook(notebook_path: Path):
|
|
assert _notebook_run(notebook_path) == []
|