Skip to content

Commit 5960182

Browse files
committed
adding tests that runs notebooks; adding nbformat and pytest (fix to jupyter issues) to docker
1 parent ef30962 commit 5960182

File tree

3 files changed

+62
-11
lines changed

3 files changed

+62
-11
lines changed

Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Generated by Neurodocker v0.3.1-19-g8d02eb4.
1+
# Generated by Neurodocker v0.3.2.
22
#
33
# Thank you for using Neurodocker. If you discover any issues
44
# or ways to improve this software, please submit an issue or
55
# pull request on our GitHub repository:
66
# https://github.com/kaczmarj/neurodocker
77
#
8-
# Timestamp: 2017-11-08 20:40:41
8+
# Timestamp: 2017-12-28 23:39:47
99

1010
FROM neurodebian:stretch-non-free
1111

@@ -62,14 +62,14 @@ RUN apt-get update -qq && apt-get install -yq --no-install-recommends libxext6 l
6262
&& apt-get clean \
6363
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
6464
&& echo "Downloading MATLAB Compiler Runtime ..." \
65-
&& curl -sSL -o /tmp/mcr.zip https://www.mathworks.com/supportfiles/downloads/R2017a/deployment_files/R2017a/installers/glnxa64/MCR_R2017a_glnxa64_installer.zip \
65+
&& curl -sSL --retry 5 -o /tmp/mcr.zip https://www.mathworks.com/supportfiles/downloads/R2017a/deployment_files/R2017a/installers/glnxa64/MCR_R2017a_glnxa64_installer.zip \
6666
&& unzip -q /tmp/mcr.zip -d /tmp/mcrtmp \
6767
&& /tmp/mcrtmp/install -destinationFolder /opt/mcr -mode silent -agreeToLicense yes \
6868
&& rm -rf /tmp/*
6969

7070
# Install standalone SPM
7171
RUN echo "Downloading standalone SPM ..." \
72-
&& curl -sSL -o spm.zip http://www.fil.ion.ucl.ac.uk/spm/download/restricted/utopia/dev/spm12_latest_Linux_R2017a.zip \
72+
&& curl -sSL --retry 5 -o spm.zip http://www.fil.ion.ucl.ac.uk/spm/download/restricted/utopia/dev/spm12_latest_Linux_R2017a.zip \
7373
&& unzip -q spm.zip -d /opt \
7474
&& chmod -R 777 /opt/spm* \
7575
&& rm -rf spm.zip \
@@ -90,7 +90,7 @@ ENV CONDA_DIR=/opt/conda \
9090
PATH=/opt/conda/bin:$PATH
9191
RUN echo "Downloading Miniconda installer ..." \
9292
&& miniconda_installer=/tmp/miniconda.sh \
93-
&& curl -sSL -o $miniconda_installer https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \
93+
&& curl -sSL --retry 5 -o $miniconda_installer https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \
9494
&& /bin/bash $miniconda_installer -b -p $CONDA_DIR \
9595
&& rm -f $miniconda_installer \
9696
&& conda config --system --prepend channels conda-forge \
@@ -102,6 +102,7 @@ RUN echo "Downloading Miniconda installer ..." \
102102
# Create conda environment
103103
#-------------------------
104104
RUN conda create -y -q --name neuro python=3.6 \
105+
pytest \
105106
jupyter \
106107
jupyterlab \
107108
jupyter_contrib_nbextensions \
@@ -110,6 +111,7 @@ RUN conda create -y -q --name neuro python=3.6 \
110111
matplotlib \
111112
scikit-learn \
112113
seaborn \
114+
nbformat \
113115
&& sync && conda clean -tipsy && sync \
114116
&& /bin/bash -c "source activate neuro \
115117
&& pip install -q --no-cache-dir https://github.com/nipy/nipype/tarball/master \
@@ -208,10 +210,10 @@ RUN echo '{ \
208210
\n [ \
209211
\n "miniconda", \
210212
\n { \
211-
\n "conda_install": "python=3.6 jupyter jupyterlab jupyter_contrib_nbextensions traits pandas matplotlib scikit-learn seaborn", \
213+
\n "conda_install": "python=3.6 pytest jupyter jupyterlab jupyter_contrib_nbextensions traits pandas matplotlib scikit-learn seaborn nbformat", \
212214
\n "pip_install": "https://github.com/nipy/nipype/tarball/master https://github.com/INCF/pybids/tarball/master nilearn datalad[full] nipy duecredit", \
213215
\n "env_name": "neuro", \
214-
\n "activate": "True" \
216+
\n "activate": true \
215217
\n } \
216218
\n ], \
217219
\n [ \
@@ -276,6 +278,6 @@ RUN echo '{ \
276278
\n ] \
277279
\n ] \
278280
\n ], \
279-
\n "generation_timestamp": "2017-11-08 20:40:41", \
280-
\n "neurodocker_version": "0.3.1-19-g8d02eb4" \
281+
\n "generation_timestamp": "2017-12-28 23:39:47", \
282+
\n "neurodocker_version": "0.3.2" \
281283
\n}' > /neurodocker/neurodocker_specs.json

create_dockerfile.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ docker run --rm kaczmarj/neurodocker:master generate -b neurodebian:stretch-non-
88
--spm version=12 matlab_version=R2017a \
99
--user=neuro \
1010
--miniconda \
11-
conda_install="python=3.6 jupyter jupyterlab jupyter_contrib_nbextensions
12-
traits pandas matplotlib scikit-learn seaborn" \
11+
conda_install="python=3.6 pytest jupyter jupyterlab jupyter_contrib_nbextensions
12+
traits pandas matplotlib scikit-learn seaborn nbformat" \
1313
pip_install="https://github.com/nipy/nipype/tarball/master
1414
https://github.com/INCF/pybids/tarball/master
1515
nilearn datalad[full] nipy duecredit" \

test_notebooks.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from glob import glob
2+
import sys, os, time
3+
import pytest, pdb
4+
5+
import nbformat
6+
from nbconvert.preprocessors import ExecutePreprocessor
7+
from nbconvert.preprocessors.execute import CellExecutionError
8+
9+
def _notebook_run(path):
10+
"""
11+
Execute a notebook via nbconvert and collect output.
12+
:returns (parsed nb object, execution errors)
13+
"""
14+
kernel_name = 'python%d' % sys.version_info[0]
15+
this_file_directory = os.path.dirname(__file__)
16+
errors = []
17+
18+
19+
with open(path) as f:
20+
nb = nbformat.read(f, as_version=4)
21+
nb.metadata.get('kernelspec', {})['name'] = kernel_name
22+
ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=7200) #, allow_errors=True
23+
24+
try:
25+
ep.preprocess(nb, {'metadata': {'path': this_file_directory}})
26+
27+
except CellExecutionError as e:
28+
if "SKIP" in e.traceback:
29+
print(str(e.traceback).split("\n")[-2])
30+
else:
31+
raise e
32+
33+
return nb, errors
34+
35+
36+
Dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "notebooks")
37+
38+
@pytest.mark.parametrize("notebook", glob(os.path.join(Dir_path, "basic*.ipynb")) +
39+
[os.path.join(Dir_path, "introduction_python.ipynb"),
40+
os.path.join(Dir_path, "introduction_quickstart.ipynb")] +
41+
[os.path.join(Dir_path, "example_preprocessing.ipynb"),
42+
os.path.join(Dir_path, "example_1stlevel.ipynb"),
43+
os.path.join(Dir_path, "example_normalize.ipynb"),
44+
os.path.join(Dir_path, "example_2ndlevel.ipynb")])
45+
def test_notebooks(notebook):
46+
t0 = time.time()
47+
nb, errors = _notebook_run(notebook)
48+
print("time", time.time()-t0)
49+
assert errors == []

0 commit comments

Comments
 (0)