diff --git a/.github/workflows/notebooktest-package.yml b/.github/workflows/test-tutorials.yml similarity index 91% rename from .github/workflows/notebooktest-package.yml rename to .github/workflows/test-tutorials.yml index a3020042..3e579f07 100644 --- a/.github/workflows/notebooktest-package.yml +++ b/.github/workflows/test-tutorials.yml @@ -1,4 +1,4 @@ -name: Notebooks +name: Tutorials on: [push] @@ -30,7 +30,7 @@ jobs: python -m pip install --upgrade pip python -m pip install pathos pygraphviz neuron cloud-volume k3d scikit-image open3d python -m pip install -e .[test-notebook,all] - - name: Run notebooks + - name: Run tutorials uses: coactions/setup-xvfb@v1 env: NEUPRINT_APPLICATION_CREDENTIALS: ${{ secrets.neuprint }} @@ -38,5 +38,5 @@ jobs: INSECT_BRAIN_DB_PASSWORD: ${{ secrets.insect_brain_db_password }} with: run: | - export NAVIS_HEADLESS=TRUE - python tests/test_notebooks.py + NAVIS_PLOT3D_BACKEND="plotly" + python tests/test_tutorials.py diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py deleted file mode 100644 index 7ba5f9a6..00000000 --- a/tests/test_notebooks.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Code to run Jupyter notebooks in /docs/source. -""" -import navis - -from pathlib import Path - -# If Jupyter is not installed, this will fail. -# We will belay the import error in case the -# user wants to run only the other parts of the -# test suite. -try: - import nbformat - from nbconvert.preprocessors import ExecutePreprocessor -except ImportError: - nbformat = None - pass -except BaseException: - raise - -SKIP = ['transforming.ipynb', # requires navis-flybrains + transforms - 'python2cytoscape.ipynb', # requires cytoscape - 'r_doc.ipynb', # requires rpy2 - 'nblast_flycircuit.ipynb', # requires downloading flycircuit dotprops - 'nblast_hemibrain.ipynb', # requires downloading data - 'microns_tut.ipynb', # requires credentials - 'local_data_skeletons.ipynb', # requires downloaded data - 'local_data_dotprops.ipynb', # requires downloaded data - 'local_data_meshes.ipynb', # requires downloaded data - 'local_data_voxels.ipynb', # requires downloaded data - 'local_data_pickling.ipynb', # requires downloaded data - 'neuromorpho_tut.ipynb', # some certificate issue at the moment - ] - -if __name__ == '__main__': - if not nbformat: - raise ImportError('`nbformat` not found - please install Jupyter') - - navis.set_pbars(jupyter=False, hide=True) - - # Recursively search for notebooks - path = Path(__file__).parent.parent / 'docs/source/tutorials' - - for file in path.glob('*.ipynb'): - if not file.is_file(): - continue - if file.name in SKIP: - continue - - with open(file) as f: - nb = nbformat.read(f, as_version=4) - - ep = ExecutePreprocessor(timeout=600) - - print('Executing', file.name, '... ', end='') - ep.preprocess(nb, {'metadata': {'path': file.parent}}) - print('Done.') - - print('All done.') diff --git a/tests/test_tutorials.py b/tests/test_tutorials.py new file mode 100644 index 00000000..103fbd8f --- /dev/null +++ b/tests/test_tutorials.py @@ -0,0 +1,48 @@ +""" +Code to execute code examples notebooks in /docs/examples. + +This will not be run through pytest but is meant to be run in a separate CI job. +""" + +import subprocess +from pathlib import Path + +# If Jupyter is not installed, this will fail. +# We will belay the import error in case the +# user wants to run only the other parts of the +# test suite. +try: + import nbformat + from nbconvert.preprocessors import ExecutePreprocessor +except ImportError: + nbformat = None + pass +except BaseException: + raise + +SKIP = [ + +] + +if __name__ == "__main__": + # Recursively search for notebooks + path = Path(__file__).parent.parent / "docs/examples" + + files = list(path.rglob("*.py")) + for i, file in enumerate(files): + if not file.is_file(): + continue + if file.name in SKIP: + continue + + print(f"Executing {file.name} [{i+1}/{len(files)}]... ", end="", flush=True) + try: + p = subprocess.run(["python", str(file)], check=True, capture_output=True, timeout=600) + except subprocess.CalledProcessError as e: + print("Failed.") + print(e.stdout.decode()) + print(e.stderr.decode()) + raise + print("Done.", flush=True) + + print("All done.")