|
| 1 | +import os |
| 2 | +import time |
1 | 3 | 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 | 4 |
|
10 | 5 | def test_version():
|
11 | 6 | import nipype
|
12 | 7 | print("nipype version: ", nipype.__version__)
|
13 | 8 |
|
14 | 9 |
|
15 |
| -def _notebook_run(path): |
16 |
| - """ |
17 |
| - Execute a notebook via nbconvert and collect output. |
18 |
| - :returns (parsed nb object, execution errors) |
19 |
| - """ |
20 |
| - kernel_name = 'python%d' % sys.version_info[0] |
21 |
| - this_file_directory = os.path.dirname(__file__) |
22 |
| - errors = [] |
23 |
| - |
24 |
| - with open(path) as f: |
25 |
| - nb = nbformat.read(f, as_version=4) |
26 |
| - nb.metadata.get('kernelspec', {})['name'] = kernel_name |
27 |
| - ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=7200) #, allow_errors=True |
28 |
| - |
29 |
| - try: |
30 |
| - ep.preprocess(nb, {'metadata': {'path': this_file_directory}}) |
31 |
| - |
32 |
| - except CellExecutionError as e: |
33 |
| - if "TAB" in e.traceback: |
34 |
| - print(str(e.traceback).split("\n")[-2]) |
35 |
| - else: |
36 |
| - raise e |
37 |
| - |
38 |
| - return nb, errors |
39 |
| - |
40 |
| - |
41 | 10 | def reduce_notebook_load(path):
|
42 | 11 | """
|
43 | 12 | Changes the number of subjects in examples and hands-on to two,
|
44 |
| - to reduce computation time on circleci. |
| 13 | + to reduce computation time on CircleCi. |
45 | 14 | """
|
46 | 15 |
|
47 | 16 | path_short = path[:-6] + '_short.ipynb'
|
@@ -82,27 +51,25 @@ def reduce_notebook_load(path):
|
82 | 51 | return path_short
|
83 | 52 |
|
84 | 53 |
|
85 |
| -Dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "notebooks") |
| 54 | +if __name__ == '__main__': |
86 | 55 |
|
87 |
| -@pytest.mark.parametrize("notebook", |
88 |
| - sorted(glob(os.path.join(Dir_path, "introduction_*.ipynb"))) + |
89 |
| - sorted(glob(os.path.join(Dir_path, "basic*.ipynb"))) + |
90 |
| - sorted(glob(os.path.join(Dir_path, "advanced*.ipynb"))) + |
91 |
| - [os.path.join(Dir_path, "example_preprocessing.ipynb"), |
92 |
| - os.path.join(Dir_path, "example_1stlevel.ipynb"), |
93 |
| - os.path.join(Dir_path, "example_normalize.ipynb"), |
94 |
| - os.path.join(Dir_path, "example_2ndlevel.ipynb"), |
95 |
| - os.path.join(Dir_path, "handson_preprocessing.ipynb"), |
96 |
| - os.path.join(Dir_path, "handson_analysis.ipynb")]) |
97 |
| - |
98 |
| -def test_notebooks(notebook): |
99 | 56 | test_version()
|
100 | 57 |
|
101 |
| - if 'example' in notebook or 'handson' in notebook: |
102 |
| - notebook = reduce_notebook_load(notebook) |
103 |
| - print('Testing shortened notebook.') |
| 58 | + notebooks = sorted(glob("/home/neuro/nipype_tutorial/notebooks/introduction_*.ipynb")) + \ |
| 59 | + sorted(glob("/home/neuro/nipype_tutorial/notebooks/basic*.ipynb")) + \ |
| 60 | + sorted(glob("/home/neuro/nipype_tutorial/notebooks/advanced*.ipynb")) |
| 61 | + |
| 62 | + for n in ["/home/neuro/nipype_tutorial/notebooks/example_preprocessing.ipynb", |
| 63 | + "/home/neuro/nipype_tutorial/notebooks/example_1stlevel.ipynb", |
| 64 | + "/home/neuro/nipype_tutorial/notebooks/example_normalize.ipynb", |
| 65 | + "/home/neuro/nipype_tutorial/notebooks/example_2ndlevel.ipynb", |
| 66 | + "/home/neuro/nipype_tutorial/notebooks/handson_preprocessing.ipynb", |
| 67 | + "/home/neuro/nipype_tutorial/notebooks/handson_analysis.ipynb"]: |
| 68 | + |
| 69 | + print('Reducing: %s' % n) |
| 70 | + notebooks.append(reduce_notebook_load(n)) |
104 | 71 |
|
105 |
| - t0 = time.time() |
106 |
| - nb, errors = _notebook_run(notebook) |
107 |
| - print("time", time.time() - t0) |
108 |
| - assert errors == [] |
| 72 | + for test in notebooks: |
| 73 | + t0 = time.time() |
| 74 | + os.system('pytest --nbval-lax --nbval-cell-timeout 7200 -v -s %s' % test) |
| 75 | + print("time", time.time() - t0) |
0 commit comments