-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.py
25 lines (19 loc) · 849 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import unittest
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
import pytest
import itertools as itt
DIRECTORY = os.path.dirname(os.path.realpath(__file__))
# CHECK THIS http://stackoverflow.com/questions/1676269/writing-a-re-usable-parametrized-unittest-testcase-method
def get_all_ipynb(directory):
for root, directory, files in os.walk(directory):
for file in files:
if file.endswith('.ipynb') and 'checkpoints' not in root:
yield os.path.join(root, file)
@pytest.mark.parametrize('path', get_all_ipynb(DIRECTORY))
def test_notebook(path):
with open(os.path.join(DIRECTORY, path)) as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
ep.preprocess(nb, {'metadata': {'path': DIRECTORY}})