1515from packaging .version import Version
1616
1717_NOTEBOOK_EXECUTION_TIMEOUT_SECONDS : Final [int ] = 60 * 20 # 20min
18- docs_dir : Path = Path (__file__ ).parent .parent .parent / "docs"
19- all_notebooks : List [Path ] = list (docs_dir .rglob ("*.ipynb" ))
20- min_version_reqs : Dict [str , Version ] = {
18+ _docs_dir : Path = Path (__file__ ).parent .parent .parent / "docs"
19+
20+ all_notebooks : List [Path ] = list (_docs_dir .rglob ("*.ipynb" ))
21+
22+ MIN_VERSION_REQS : Dict [str , Version ] = {
2123 "BasicTutorial_v0.5.0.ipynb" : Version ("0.5.0" ),
2224 "BasicTutorial_v0.6.0.ipynb" : Version ("0.6.0" ),
2325}
2426
2527
28+ def _papermill_execute_notebook (
29+ tmp_path : Path , notebook : Path , parameters : dict [str , Any ]
30+ ) -> Path :
31+ assert (
32+ notebook .is_file ()
33+ ), f"{ notebook .name } is not a file (full path: { notebook .resolve ()} )"
34+
35+ if min_version := MIN_VERSION_REQS .get (notebook .name ):
36+ if Version (osparc .__version__ ) < min_version :
37+ pytest .skip (
38+ f"Skipping { notebook .name } because "
39+ f"{ osparc .__version__ = } < { min_version = } "
40+ )
41+
42+ tmp_nb = tmp_path / notebook .name
43+ shutil .copy (notebook , tmp_nb )
44+ assert tmp_nb .is_file (), "Did not succeed in copying notebook"
45+ output : Path = tmp_path / (tmp_nb .stem + "_output.ipynb" )
46+
47+ pm .execute_notebook (
48+ input_path = tmp_nb ,
49+ output_path = output ,
50+ kernel_name = "python3" ,
51+ parameters = parameters ,
52+ execution_timeout = _NOTEBOOK_EXECUTION_TIMEOUT_SECONDS ,
53+ )
54+ return output
55+
56+
2657def test_notebook_config (tmp_path : Path ):
2758 """Checks the jupyter environment is configured correctly"""
2859 config_test_nb : Path = Path (__file__ ).parent / "config_test.ipynb"
2960 assert config_test_nb .is_file ()
30- test_run_notebooks (
61+ _papermill_execute_notebook (
3162 tmp_path ,
3263 config_test_nb ,
3364 {
@@ -36,8 +67,8 @@ def test_notebook_config(tmp_path: Path):
3667 "expected_osparc_file" : osparc .__file__ ,
3768 },
3869 )
39- assert len (all_notebooks ) > 0 , f"Did not find any notebooks in { docs_dir } "
40- min_keys : set = set (min_version_reqs .keys ())
70+ assert len (all_notebooks ) > 0 , f"Did not find any notebooks in { _docs_dir } "
71+ min_keys : set = set (MIN_VERSION_REQS .keys ())
4172 notebook_names : set = set (pth .name for pth in all_notebooks )
4273 msg : str = (
4374 f"Must specify max version for: { notebook_names - min_keys } ."
@@ -47,25 +78,11 @@ def test_notebook_config(tmp_path: Path):
4778
4879
4980@pytest .mark .parametrize ("notebook" , all_notebooks , ids = lambda nb : nb .name )
50- def test_run_notebooks (tmp_path : Path , notebook : Path , params : dict [ str , Any ] ):
81+ def test_run_notebooks (tmp_path : Path , notebook : Path ):
5182 """Run all notebooks in the documentation"""
52- assert (
53- notebook .is_file ()
54- ), f"{ notebook .name } is not a file (full path: { notebook .resolve ()} )"
55- if min_version := min_version_reqs .get (notebook .name ):
56- if Version (osparc .__version__ ) < min_version :
57- pytest .skip (
58- f"Skipping { notebook .name } because "
59- f"{ osparc .__version__ = } < { min_version = } "
60- )
61- tmp_nb = tmp_path / notebook .name
62- shutil .copy (notebook , tmp_nb )
63- assert tmp_nb .is_file (), "Did not succeed in copying notebook"
64- output : Path = tmp_path / (tmp_nb .stem + "_output.ipynb" )
65- pm .execute_notebook (
66- input_path = tmp_nb ,
67- output_path = output ,
68- kernel_name = "python3" ,
69- parameters = params or {},
70- execution_timeout = _NOTEBOOK_EXECUTION_TIMEOUT_SECONDS ,
83+
84+ _papermill_execute_notebook (
85+ tmp_path = tmp_path ,
86+ notebook = notebook ,
87+ parameters = {}, # NOTE: for the moment these notebooks have no parameters
7188 )
0 commit comments