Skip to content

Commit 98cabba

Browse files
authored
Notebook tests (#978)
* 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
1 parent 8a9a2f7 commit 98cabba

File tree

5 files changed

+86
-93
lines changed

5 files changed

+86
-93
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

.github/workflows/python-ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ jobs:
8484
poetry run python -m pip install gensim
8585
poetry install
8686
87-
- name: Check Semversioner
88-
run: |
89-
poetry run semversioner check
90-
9187
- name: Check
9288
run: |
9389
poetry run poe check
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Python Notebook Tests
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
# Only run the for the latest commit
15+
cancel-in-progress: true
16+
17+
env:
18+
POETRY_VERSION: 1.8.3
19+
20+
jobs:
21+
python-ci:
22+
strategy:
23+
matrix:
24+
python-version: ["3.11"]
25+
os: [ubuntu-latest, windows-latest]
26+
fail-fast: false # Continue running all jobs even if one fails
27+
env:
28+
DEBUG: 1
29+
GRAPHRAG_API_KEY: ${{ secrets.OPENAI_NOTEBOOK_KEY }}
30+
GRAPHRAG_LLM_MODEL: ${{ secrets.GRAPHRAG_LLM_MODEL }}
31+
GRAPHRAG_EMBEDDING_MODEL: ${{ secrets.GRAPHRAG_EMBEDDING_MODEL }}
32+
33+
runs-on: ${{ matrix.os }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- uses: dorny/paths-filter@v3
38+
id: changes
39+
with:
40+
filters: |
41+
python:
42+
- 'graphrag/**/*'
43+
- 'poetry.lock'
44+
- 'pyproject.toml'
45+
- '**/*.py'
46+
- '**/*.toml'
47+
- '**/*.ipynb'
48+
- '.github/workflows/python*.yml'
49+
50+
- name: Set up Python ${{ matrix.python-version }}
51+
uses: actions/setup-python@v5
52+
with:
53+
python-version: ${{ matrix.python-version }}
54+
55+
- name: Install Poetry
56+
uses: abatilo/actions-poetry@v3.0.0
57+
with:
58+
poetry-version: $POETRY_VERSION
59+
60+
- name: Install dependencies
61+
shell: bash
62+
run: |
63+
poetry self add setuptools wheel
64+
poetry run python -m pip install gensim
65+
poetry install
66+
67+
68+
- name: Notebook Test
69+
run: |
70+
poetry run poe test_notebook

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ _test_all = "coverage run -m pytest ./tests"
125125
test_unit = "pytest ./tests/unit"
126126
test_integration = "pytest ./tests/integration"
127127
test_smoke = "pytest ./tests/smoke"
128+
test_notebook = "pytest ./tests/notebook"
128129
index = "python -m graphrag.index"
129130
query = "python -m graphrag.query"
130131
prompt_tune = "python -m graphrag.prompt_tune"

tests/notebook/test_notebooks.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
# Copyright (c) 2024 Microsoft Corporation.
22
# Licensed under the MIT License
33
import subprocess
4-
import tempfile
54
from pathlib import Path
65

76
import nbformat
87
import pytest
98

10-
DOCS_PATH = Path("../../docsite")
9+
NOTEBOOKS_PATH = Path("examples_notebooks")
1110

12-
notebooks_list = list(DOCS_PATH.rglob("*.ipynb"))
11+
notebooks_list = list(NOTEBOOKS_PATH.rglob("*.ipynb"))
1312

1413

1514
def _notebook_run(filepath: Path):
1615
"""Execute a notebook via nbconvert and collect output.
1716
:returns execution errors
1817
"""
19-
with tempfile.NamedTemporaryFile(suffix=".ipynb") as temp_file:
20-
args = [
21-
"jupyter",
22-
"nbconvert",
23-
"--to",
24-
"notebook",
25-
"--execute",
26-
"-y",
27-
"--no-prompt",
28-
"--output",
29-
temp_file.name,
30-
filepath.absolute().as_posix(),
31-
]
32-
subprocess.check_call(args)
33-
34-
temp_file.seek(0)
35-
nb = nbformat.read(temp_file, nbformat.current_nbformat)
18+
args = [
19+
"jupyter",
20+
"nbconvert",
21+
"--to",
22+
"notebook",
23+
"--execute",
24+
"-y",
25+
"--no-prompt",
26+
"--stdout",
27+
filepath.absolute().as_posix(),
28+
]
29+
notebook = subprocess.check_output(args)
30+
nb = nbformat.reads(notebook, nbformat.current_nbformat)
3631

3732
return [
3833
output

0 commit comments

Comments
 (0)