Skip to content

Commit

Permalink
Merge pull request #1298 from girder/test-notebooks
Browse files Browse the repository at this point in the history
Test notebooks.
  • Loading branch information
manthey authored Sep 14, 2023
2 parents 9710b4f + 060b122 commit f3c67a2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
name: Install dependencies
command: apt-get update -yq && apt-get install -yq pandoc && pandoc --version
- tox:
env: docs,lint,lintclient
env: docs,lint,lintclient,notebook
- store_artifacts:
path: build/docs
- persist_to_workspace:
Expand Down
2 changes: 1 addition & 1 deletion docs/large_image_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"# Ask JupyterLab to locally proxy an internal tile server\n",
"import importlib.util\n",
"\n",
"if importlib.util.find_spec('google.colab'):\n",
"if importlib.util.find_spec('google') and importlib.util.find_spec('google.colab'):\n",
" # colab intercepts localhost\n",
" large_image.tilesource.jupyter.IPyLeafletMixin.JUPYTER_PROXY = 'https://localhost'\n",
"else:\n",
Expand Down
26 changes: 26 additions & 0 deletions test/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from tempfile import TemporaryDirectory

import pytest


@pytest.mark.notebook()
@pytest.mark.parametrize('notebook', ['docs/large_image_examples.ipynb'])
def test_notebook_exec(notebook):
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor

testDir = os.path.dirname(os.path.realpath(__file__))
notebookpath = os.path.join(testDir, '..', notebook)
with TemporaryDirectory() as tempDir:
with open(notebookpath) as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor(
timeout=600, kernel_name='python3',
resources={'metadata': {'path': tempDir}})
try:
result = ep.preprocess(nb)
assert result is not None, f'Got empty notebook for {notebook}'
except Exception as exp:
msg = f'Failed executing {notebook}: {exp}'
raise AssertionError(msg)
27 changes: 24 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
envlist =
test-py{36,37,38,39,310,311}
docs
flake8
lint
lintclient
notebook
skip_missing_interpreters = true
toxworkdir = {toxinidir}/build/tox

Expand Down Expand Up @@ -38,7 +39,7 @@ commands =
rm -rf build/test/coverage/web_temp
girder build --dev
pytest --numprocesses 1 -m 'singular' --cov-config tox.ini --suppress-no-test-exit-code {posargs}
pytest --numprocesses logical -m 'not singular' --cov-config tox.ini --cov-append --suppress-no-test-exit-code {posargs}
pytest --numprocesses logical -m 'not singular and not notebook' --cov-config tox.ini --cov-append --suppress-no-test-exit-code {posargs}
- npx nyc report --temp-dir build/test/coverage/web_temp --report-dir build/test/coverage --reporter cobertura --reporter text-summary
# Reduce npm chatter
setenv =
Expand Down Expand Up @@ -104,12 +105,31 @@ deps =
pytest-xdist
commands =
pytest --numprocesses 1 -m 'singular and not girder' --cov-config tox.ini --suppress-no-test-exit-code {posargs}
pytest --numprocesses logical -m 'not singular and not girder' --cov-config tox.ini --cov-append --suppress-no-test-exit-code {posargs}
pytest --numprocesses logical -m 'not singular and not girder and not notebook' --cov-config tox.ini --cov-append --suppress-no-test-exit-code {posargs}

[testenv:core-py{36,37,38,39,310,311}]
deps = {[testenv:core]deps}
commands = {[testenv:core]commands}

[testenv:notebook]
description = Run tests on notebooks
deps =
ipykernel
nbconvert
nbformat
pooch
pytest>=3.6
pytest-cov>=2.6
pytest-custom-exit-code
pytest-rerunfailures
pytest-xdist
commands =
pytest --numprocesses 1 -m 'notebook' --no-cov --suppress-no-test-exit-code test/test_notebooks.py {posargs}
setenv =
PIP_FIND_LINKS=https://girder.github.io/large_image_wheels
GDAL_PAM_ENABLED=no
JUPYTER_PLATFORM_DIRS=1

[testenv:lint]
description = Lint python code
skipsdist = true
Expand Down Expand Up @@ -248,6 +268,7 @@ markers =
singular: mark a test to run in a non-parallel environment.
girder: mark a test as requiring girder
girder_client: mark a test as requiring girder client
notebook: mark a test as for jupyter notebooks
plugin: use by girder to load plugins
# Some of these warnings are filtered by their own packages (e.g., the numpy
# warnings), and pytest shows them anyway unless they are listed here. Others,
Expand Down

0 comments on commit f3c67a2

Please sign in to comment.