forked from hoh/runipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (24 loc) · 1.12 KB
/
test.py
File metadata and controls
32 lines (24 loc) · 1.12 KB
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
26
27
28
29
30
31
import unittest
from glob import glob
from os import path
from IPython.nbformat.current import read
from runipy.notebook_runner import NotebookRunner
class TestRunipy(unittest.TestCase):
maxDiff = None
def assert_notebooks_equal(self, expected, actual):
self.assertEquals(len(expected['worksheets'][0]['cells']), len(actual['worksheets'][0]['cells']))
for expected_out, actual_out in zip(expected['worksheets'][0]['cells'],
actual['worksheets'][0]['cells']):
self.assertEquals(dict(expected_out), dict(actual_out))
def testRunNotebooks(self):
input_glob = path.join('tests', 'input', '*.ipynb')
for notebook_file in glob(input_glob):
notebook_file_base = path.basename(notebook_file)
print notebook_file_base
expected_file = path.join('tests', 'expected', notebook_file_base)
runner = NotebookRunner(notebook_file)
runner.run_notebook(True)
expected = read(open(expected_file), 'json')
self.assert_notebooks_equal(expected, runner.nb)
if __name__ == '__main__':
unittest.main()