From 82bda3da7d980a9a312c3ff6b748249a6abb526b Mon Sep 17 00:00:00 2001 From: Alexander Rodin Date: Thu, 1 Jun 2017 16:40:06 +0300 Subject: [PATCH 1/3] Add tests for examples notebooks --- .travis.yml | 2 ++ pymc3/tests/test_examples_notebooks.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 pymc3/tests/test_examples_notebooks.py diff --git a/.travis.yml b/.travis.yml index f145902e50..811eec04f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,11 @@ env: - PYTHON_VERSION=2.7 TESTCMD="--durations=10 --ignore=pymc3/tests/test_examples.py --cov-append --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py" - PYTHON_VERSION=2.7 RUN_PYLINT="true" TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py" - PYTHON_VERSION=2.7 TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_variational_inference.py pymc3/tests/test_updates.py" + - PYTHON_VERSION=2.7 TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples_notebooks.py" - PYTHON_VERSION=3.6 TESTCMD="--durations=10 --cov-append --ignore=pymc3/tests/test_examples.py --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py" - PYTHON_VERSION=3.6 TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py" - PYTHON_VERSION=3.6 TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_variational_inference.py pymc3/tests/test_updates.py" + - PYTHON_VERSION=3.6 TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples_notebooks.py" script: - . ./scripts/test.sh $TESTCMD diff --git a/pymc3/tests/test_examples_notebooks.py b/pymc3/tests/test_examples_notebooks.py new file mode 100644 index 0000000000..35164ad175 --- /dev/null +++ b/pymc3/tests/test_examples_notebooks.py @@ -0,0 +1,18 @@ +import os +from glob import glob +import nbformat +from nbconvert.preprocessors import ExecutePreprocessor +import pytest + +from .helpers import SeededTest + +notebooks_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'docs', 'source', 'notebooks') +notebooks_files = [file for file in os.listdir(notebooks_dir) if file.lower().endswith('.ipynb')] + +class TestExamplesNotebooks(SeededTest): + @pytest.mark.parametrize('notebook_filename', notebooks_files) + def test_run_notebook(self, notebook_filename): + with open(os.path.join(notebooks_dir, notebook_filename)) as f: + nb = nbformat.read(f, as_version=4) + ep = ExecutePreprocessor(timeout=900) + ep.preprocess(nb, {'metadata': {'path': notebooks_dir}}) From 2b4608bfdb0cf9aefaf9ac2913459f4864fa4ff8 Mon Sep 17 00:00:00 2001 From: Alexander Rodin Date: Thu, 1 Jun 2017 17:45:41 +0300 Subject: [PATCH 2/3] Add keras and seaborn to test dependencies (required by some examples) --- scripts/create_testenv.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/create_testenv.sh b/scripts/create_testenv.sh index daf1f57895..c2b7d2b289 100755 --- a/scripts/create_testenv.sh +++ b/scripts/create_testenv.sh @@ -50,6 +50,9 @@ pip install pytest pytest-cov nose-parameterized pylint # Install untested, non-required code (linter fails without them) pip install ipython ipywidgets numdifftools +# Install dependencies for examples +pip install keras seaborn + if [ -z ${NO_SETUP} ]; then python setup.py build_ext --inplace fi From dc98be4be1bd0dd18e7ce45c5601cbea033b8aa0 Mon Sep 17 00:00:00 2001 From: Alexander Rodin Date: Thu, 1 Jun 2017 21:37:52 +0300 Subject: [PATCH 3/3] Reduce timeout to avoid 10 minutes without output termination --- pymc3/tests/test_examples_notebooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tests/test_examples_notebooks.py b/pymc3/tests/test_examples_notebooks.py index 35164ad175..8eebac536e 100644 --- a/pymc3/tests/test_examples_notebooks.py +++ b/pymc3/tests/test_examples_notebooks.py @@ -14,5 +14,5 @@ class TestExamplesNotebooks(SeededTest): def test_run_notebook(self, notebook_filename): with open(os.path.join(notebooks_dir, notebook_filename)) as f: nb = nbformat.read(f, as_version=4) - ep = ExecutePreprocessor(timeout=900) + ep = ExecutePreprocessor(timeout=300) ep.preprocess(nb, {'metadata': {'path': notebooks_dir}})