Skip to content

Commit a51943f

Browse files
committed
Add notebook testing and a test mode flag.
1 parent a5814be commit a51943f

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

.github/workflows/notebooks.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Notebooks
2+
3+
on:
4+
# Trigger the workflow on push or pull request, but only on dev branch
5+
push:
6+
branches:
7+
- revamp-2025
8+
pull_request:
9+
branches:
10+
- revamp-2025
11+
12+
permissions:
13+
contents: read # to fetch code
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
documentation:
21+
name: Set up Python ${{ matrix.python-version }}
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 10
24+
strategy:
25+
matrix:
26+
python-version: ["3.12"]
27+
fail-fast: false
28+
29+
steps:
30+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install .[dev]
39+
pip install ipykernel pytest-notebook
40+
pip freeze
41+
- name: Turn on test mode
42+
run: |
43+
find docs/source -type f \( -name "*.md" -o -name "*.ipynb" \) -exec sed -i "s/JAS_TEST_MODE = False/JAS_TEST_MODE = True/g" {} +
44+
- name: Register Python3 kernel
45+
run: |
46+
python -m ipykernel install --user --name "python3" --display-name "Python 3"
47+
- name: Test notebooks
48+
run: |
49+
pytest -n auto --tb=short --nb-force-regen --nb-test-files docs/source/ --ignore=docs/source/JAX_for_LLM_pretraining.ipynb --ignore=docs/source/data_loaders_on_cpu_with_jax.ipynb --ignore=docs/source/data_loaders_on_gpu_with_jax.ipynb --ignore=docs/source/JAX_for_PyTorch_users.ipynb --ignore=docs/source/JAX_porting_PyTorch_model.ipynb

docs/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
'JAX_transformer_text_classification.md',
6868
'data_loaders_on_cpu_with_jax.md',
6969
'data_loaders_on_gpu_with_jax.md',
70+
# Ignored test files.
71+
'test_mode_test.md',
72+
'test_mode_test.ipynb',
7073
]
7174

7275
suppress_warnings = [
@@ -104,4 +107,5 @@
104107
'JAX_transformer_text_classification.ipynb',
105108
'data_loaders_on_cpu_with_jax.ipynb',
106109
'data_loaders_on_gpu_with_jax.ipynb',
110+
'test_mode_test.ipynb',
107111
]

docs/source/test_mode_test.ipynb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Tests that CI substitutes False with True\n",
10+
"JAS_TEST_MODE = False\n",
11+
"JAS_TEST_MODE"
12+
]
13+
}
14+
],
15+
"metadata": {
16+
"jupytext": {
17+
"formats": "ipynb,md",
18+
"main_language": "python"
19+
},
20+
"language_info": {
21+
"name": "python"
22+
},
23+
"nbsphinx": {
24+
"orphan": true
25+
},
26+
"nbreg": {
27+
"diff_ignore": ["/cells/0/execution_count", "/cells/0/outputs", "/metadata"]
28+
}
29+
},
30+
"nbformat": 4,
31+
"nbformat_minor": 5
32+
}

docs/source/test_mode_test.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
formats: ipynb,md
5+
main_language: python
6+
text_representation:
7+
extension: .md
8+
format_name: markdown
9+
format_version: '1.3'
10+
jupytext_version: 1.15.2
11+
---
12+
13+
```python
14+
# Tests that CI substitutes False with True
15+
JAS_TEST_MODE = False
16+
JAS_TEST_MODE
17+
```

0 commit comments

Comments
 (0)