Skip to content

Commit cf83bd3

Browse files
authored
Merge pull request #393 from bayesflow-org/test-examples
Test examples
2 parents e0f8b4e + 20751fe commit cf83bd3

File tree

10 files changed

+72
-4
lines changed

10 files changed

+72
-4
lines changed

.github/workflows/tests.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ jobs:
9999
100100
- name: Run Tests
101101
run: |
102-
pytest -x
102+
pytest -x -m "not slow"
103+
104+
- name: Run Slow Tests
105+
# run only on manual trigger
106+
if: github.event_name == 'workflow_dispatch'
107+
run: |
108+
pytest -x -m "slow"
103109
104110
- name: Create Coverage Report
105111
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ For an in-depth exposition, check out our walkthrough notebooks below.
5454
1. [Linear regression starter example](examples/Linear_Regression_Starter.ipynb)
5555
2. [From ABC to BayesFlow](examples/From_ABC_to_BayesFlow.ipynb)
5656
3. [Two moons starter example](examples/Two_Moons_Starter.ipynb)
57-
4. [Rapid iteration with point estimators](examples/Lotka_Volterra_point_estimation_and_expert_stats.ipynb)
57+
4. [Rapid iteration with point estimators](examples/Lotka_Volterra_Point_Estimation_and_Expert_Stats.ipynb)
5858
5. [SIR model with custom summary network](examples/SIR_Posterior_Estimation.ipynb)
5959
6. [Bayesian experimental design](examples/Bayesian_Experimental_Design.ipynb)
6060
7. [Simple model comparison example](examples/One_Sample_TTest.ipynb)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ all = [
3737
# dev
3838
"jupyter",
3939
"jupyterlab",
40+
"nbconvert",
4041
"pre-commit",
4142
"ruff",
4243
"tox",
@@ -71,6 +72,7 @@ docs = [
7172
"sphinxcontrib-bibtex",
7273
]
7374
test = [
75+
"nbconvert",
7476
"pytest",
7577
"pytest-cov",
7678
"pytest-rerunfailures",

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ markers =
66
numpy: mark test as requiring NumPy
77
tensorflow: mark test as requiring TensorFlow
88
torch: mark test as requiring PyTorch
9+
slow: mark test as especially slow, such as running a whole fitting workflow
910

1011
testpaths =
1112
tests

tests/test_examples/__init__.py

Whitespace-only changes.

tests/test_examples/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
import pytest
3+
4+
5+
@pytest.fixture(scope="session")
6+
def examples_path():
7+
from pathlib import Path
8+
return Path(__file__).parents[2] / "examples"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
import pytest
3+
4+
from tests.utils import run_notebook
5+
6+
7+
@pytest.mark.slow
8+
def test_bayesian_experimental_design(examples_path):
9+
run_notebook(examples_path / "Bayesian_Experimental_Design.ipynb")
10+
11+
12+
@pytest.mark.slow
13+
def test_from_abc_to_bayesflow(examples_path):
14+
run_notebook(examples_path / "From_ABC_to_BayesFlow.ipynb")
15+
16+
17+
@pytest.mark.slow
18+
def test_linear_regression_starter(examples_path):
19+
run_notebook(examples_path / "Linear_Regression_Starter.ipynb")
20+
21+
22+
@pytest.mark.slow
23+
def test_lotka_volterra_point_estimation_and_expert_stats(examples_path):
24+
run_notebook(examples_path / "Lotka_Volterra_Point_Estimation_and_Expert_Stats.ipynb")
25+
26+
27+
@pytest.mark.slow
28+
def test_one_sample_ttest(examples_path):
29+
run_notebook(examples_path / "One_Sample_TTest.ipynb")
30+
31+
32+
@pytest.mark.slow
33+
def test_sir_posterior_estimation(examples_path):
34+
run_notebook(examples_path / "SIR_Posterior_estimation.ipynb")
35+
36+
37+
@pytest.mark.slow
38+
def test_two_moons_starter(examples_path):
39+
run_notebook(examples_path / "Two_Moons_Starter.ipynb")

tests/utils/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .assertions import *
22
from .callbacks import *
3-
from .ops import *
4-
from .ecdf import *
53
from .check_combinations import *
4+
from .ecdf import *
5+
from .jupyter import *
6+
from .ops import *

tests/utils/jupyter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import nbformat
3+
from nbconvert.preprocessors import ExecutePreprocessor
4+
5+
def run_notebook(path):
6+
with open(str(path)) as f:
7+
nb = nbformat.read(f, nbformat.NO_CONVERT)
8+
9+
kernel = ExecutePreprocessor(timeout=600, kernel_name="python3")
10+
11+
return kernel.preprocess(nb)

0 commit comments

Comments
 (0)