Skip to content

Commit c1b69d4

Browse files
committed
split tests into notebooks and regular
1 parent 81267cd commit c1b69d4

2 files changed

Lines changed: 136 additions & 70 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Notebook Testing Workflow
2+
#
3+
# This workflow tests Jupyter notebooks and runs by default on:
4+
# - Pull requests targeting the 'main' branch
5+
#
6+
# To manually trigger this workflow on any branch:
7+
# 1. Go to Actions tab in GitHub
8+
# 2. Select "Test Notebooks" workflow
9+
# 3. Click "Run workflow" dropdown
10+
# 4. Select your branch and click "Run workflow"
11+
12+
name: Test Notebooks
13+
14+
on:
15+
pull_request:
16+
branches:
17+
- main
18+
# Allow manual triggering from the Actions tab
19+
workflow_dispatch:
20+
21+
jobs:
22+
test-notebooks:
23+
name: Notebooks (${{ matrix.python-version }}, ${{ matrix.os }})
24+
runs-on: ${{ matrix.os }}
25+
defaults:
26+
run:
27+
shell: bash
28+
strategy:
29+
fail-fast: true
30+
matrix:
31+
os: ["ubuntu-latest"]
32+
python-version: ["3.10", "3.11", "3.12"]
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Install uv
38+
uses: astral-sh/setup-uv@v3
39+
with:
40+
version: "latest"
41+
42+
- name: Set up Python ${{ matrix.python-version }}
43+
run: uv python install ${{ matrix.python-version }}
44+
45+
- name: Cache MTH5 test files
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.cache/aurora
49+
key: mth5-test-files-${{ runner.os }}-${{ hashFiles('tests/conftest.py') }}
50+
restore-keys: |
51+
mth5-test-files-${{ runner.os }}-
52+
53+
- name: Create virtual environment and install dependencies
54+
run: |
55+
uv venv --python ${{ matrix.python-version }}
56+
source .venv/bin/activate
57+
uv pip install --upgrade pip
58+
uv pip install 'setuptools<68'
59+
uv pip install -e ".[dev,test]"
60+
uv pip install mt_metadata[obspy]
61+
uv pip install "mt_metadata[obspy]"
62+
uv pip install mth5
63+
uv pip install git+https://github.com/kujaku11/mth5_test_data.git
64+
# Explicitly include nbconvert & ipykernel
65+
uv pip install jupyter nbconvert nbformat ipykernel
66+
python -m ipykernel install --user --name "python3"
67+
68+
- name: Install system dependencies
69+
run: |
70+
sudo apt-get update
71+
sudo apt-get install -y pandoc
72+
73+
- name: Execute Jupyter Notebooks
74+
run: |
75+
source .venv/bin/activate
76+
# debugging: print locations of key packages
77+
python -c "import pkg_resources; print('pkg_resources location:', pkg_resources.__file__)"
78+
python -c "import setuptools; print('setuptools location:', setuptools.__file__)"
79+
80+
python << 'EOF'
81+
import nbformat
82+
import subprocess
83+
import sys
84+
85+
notebooks = [
86+
"docs/examples/dataset_definition.ipynb",
87+
"docs/examples/operate_aurora.ipynb",
88+
"docs/tutorials/pkd_units_check.ipynb",
89+
"docs/tutorials/pole_zero_fitting/lemi_pole_zero_fitting_example.ipynb",
90+
"docs/tutorials/processing_configuration.ipynb",
91+
"docs/tutorials/process_cas04_multiple_station.ipynb",
92+
"docs/tutorials/synthetic_data_processing.ipynb"
93+
]
94+
95+
failures = []
96+
97+
for nb_path in notebooks:
98+
# Update kernel spec
99+
print(f"Updating kernel in {nb_path}")
100+
try:
101+
with open(nb_path, "r", encoding="utf-8") as f:
102+
nb = nbformat.read(f, as_version=4)
103+
104+
nb["metadata"]["kernelspec"]["name"] = "python3"
105+
nb["metadata"]["kernelspec"]["display_name"] = "Python (python3)"
106+
107+
with open(nb_path, "w", encoding="utf-8") as f:
108+
nbformat.write(nb, f)
109+
print(f"✓ Updated kernel in {nb_path}")
110+
except Exception as e:
111+
print(f"✗ Failed to update kernel in {nb_path}: {e}")
112+
failures.append(nb_path)
113+
continue
114+
115+
# Execute notebook
116+
print(f"Executing {nb_path}")
117+
result = subprocess.run(
118+
["jupyter", "nbconvert", "--to", "notebook", "--execute", nb_path],
119+
capture_output=True,
120+
text=True
121+
)
122+
123+
if result.returncode != 0:
124+
print(f"✗ Failed to execute {nb_path}")
125+
print(result.stderr)
126+
failures.append(nb_path)
127+
else:
128+
print(f"✓ Successfully executed {nb_path}")
129+
130+
if failures:
131+
print("\n======= Summary =======")
132+
print(f"Failed notebooks: {failures}")
133+
sys.exit(1)
134+
else:
135+
print("\n✓ All notebooks executed successfully!")
136+
EOF

.github/workflows/tests.yaml

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -63,76 +63,6 @@ jobs:
6363
uv pip install jupyter nbconvert nbformat ipykernel pytest pytest-cov pytest-timeout codecov
6464
python -m ipykernel install --user --name "python3"
6565
66-
- name: Install system dependencies
67-
run: |
68-
sudo apt-get update
69-
sudo apt-get install -y pandoc
70-
71-
- name: Set kernel and execute Jupyter Notebooks
72-
run: |
73-
source .venv/bin/activate
74-
# debugging: print locations of key packages
75-
python -c "import pkg_resources; print('pkg_resources location:', pkg_resources.__file__)"
76-
python -c "import setuptools; print('setuptools location:', setuptools.__file__)"
77-
78-
python << 'EOF'
79-
import nbformat
80-
import subprocess
81-
import sys
82-
83-
notebooks = [
84-
"docs/examples/dataset_definition.ipynb",
85-
"docs/examples/operate_aurora.ipynb",
86-
"docs/tutorials/pkd_units_check.ipynb",
87-
"docs/tutorials/pole_zero_fitting/lemi_pole_zero_fitting_example.ipynb",
88-
"docs/tutorials/processing_configuration.ipynb",
89-
"docs/tutorials/process_cas04_multiple_station.ipynb",
90-
"docs/tutorials/synthetic_data_processing.ipynb"
91-
]
92-
93-
failures = []
94-
95-
for nb_path in notebooks:
96-
# Update kernel spec
97-
print(f"Updating kernel in {nb_path}")
98-
try:
99-
with open(nb_path, "r", encoding="utf-8") as f:
100-
nb = nbformat.read(f, as_version=4)
101-
102-
nb["metadata"]["kernelspec"]["name"] = "python3"
103-
nb["metadata"]["kernelspec"]["display_name"] = "Python (python3)"
104-
105-
with open(nb_path, "w", encoding="utf-8") as f:
106-
nbformat.write(nb, f)
107-
print(f"✓ Updated kernel in {nb_path}")
108-
except Exception as e:
109-
print(f"✗ Failed to update kernel in {nb_path}: {e}")
110-
failures.append(nb_path)
111-
continue
112-
113-
# Execute notebook
114-
print(f"Executing {nb_path}")
115-
result = subprocess.run(
116-
["jupyter", "nbconvert", "--to", "notebook", "--execute", nb_path],
117-
capture_output=True,
118-
text=True
119-
)
120-
121-
if result.returncode != 0:
122-
print(f"✗ Failed to execute {nb_path}")
123-
print(result.stderr)
124-
failures.append(nb_path)
125-
else:
126-
print(f"✓ Successfully executed {nb_path}")
127-
128-
if failures:
129-
print("\n======= Summary =======")
130-
print(f"Failed notebooks: {failures}")
131-
sys.exit(1)
132-
else:
133-
print("\n✓ All notebooks executed successfully!")
134-
EOF
135-
13666
- name: Run Tests
13767
run: |
13868
source .venv/bin/activate

0 commit comments

Comments
 (0)