Download tests/test_notebooks.py from markedet/agent-builder-notebooks: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/datasets/markedet/agent-builder-notebooks/resolve/main/tests/test_notebooks.py
- Command line
-
hf download hf://datasets/markedet/agent-builder-notebooks/tests/test_notebooks.py
-
curl -L -o test_notebooks.py https://huggingface.co/datasets/markedet/agent-builder-notebooks/resolve/main/tests/test_notebooks.py
1.21 kB
| import json, os, pathlib, sys | |
| import nbformat | |
| import pytest | |
| from nbclient import NotebookClient | |
| NB_DIR = pathlib.Path(__file__).resolve().parent.parent / "notebooks" | |
| NOTEBOOKS = sorted(NB_DIR.glob("*.ipynb")) | |
| NETWORK = {"01_query_the_mcp_registry.ipynb", "02_validate_a_server_json.ipynb"} | |
| def test_six_notebooks_clean(): | |
| assert len(NOTEBOOKS) == 6 | |
| for p in NOTEBOOKS: | |
| nb = json.loads(p.read_text()) | |
| assert set(nb["metadata"]) <= {"kernelspec", "language_info"} | |
| for c in nb["cells"]: | |
| assert c["metadata"] == {} and c.get("outputs", []) == [] and c.get("execution_count") is None | |
| src = " ".join("".join(c["source"]) for c in nb["cells"]).lower() | |
| assert "api_key" not in src and "token" not in src.replace("next_token", "") | |
| assert "MIT License" in "".join(nb["cells"][0]["source"]) | |
| def test_notebook_runs(path): | |
| if path.name in NETWORK and os.environ.get("OFFLINE"): | |
| pytest.skip("network notebook") | |
| nb = nbformat.read(path, as_version=4) | |
| NotebookClient(nb, timeout=120, kernel_name="python3").execute() # runs on a copy in memory; file stays clean | |