forked from rasbt/python-machine-learning-book-2nd-edition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_notebooks.py
More file actions
138 lines (106 loc) · 4.21 KB
/
test_notebooks.py
File metadata and controls
138 lines (106 loc) · 4.21 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import unittest
import os
import subprocess
import sys
import logging
LOG_FORMAT = '[%(asctime)s %(levelname)s] %(message)s'
LOGGER = logging.getLogger(__file__)
def run_ipynb(path):
nb_dir = os.path.dirname(path)
nb_path = os.path.basename(path)
orig_dir = os.getcwd()
os.chdir(nb_dir)
if (sys.version_info >= (3, 0)):
kernel_name = 'python3'
else:
kernel_name = 'python2'
# error_cells = []
args = ["jupyter", "nbconvert",
"--execute", "--inplace",
"--debug",
"--ExecutePreprocessor.timeout=5000",
"--ExecutePreprocessor.kernel_name=%s" % kernel_name,
nb_path]
if (sys.version_info >= (3, 0)):
try:
subprocess.check_output(args)
except TimeoutError:
sys.stderr.write('%s timed out\n' % path)
sys.stderr.flush()
else:
subprocess.check_output(args)
os.chdir(orig_dir)
class TestNotebooks(unittest.TestCase):
def test_ch01(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch01/ch01.ipynb'))
def test_ch02(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch02/ch02.ipynb'))
def test_ch03(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch03/ch03.ipynb'))
def test_ch04(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch04/ch04.ipynb'))
def test_ch05(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch05/ch05.ipynb'))
def test_ch06(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch06/ch06.ipynb'))
def test_ch07(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch07/ch07.ipynb'))
def test_ch08(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
# run only on Py3, because of Py2 unicode handling
if (sys.version_info >= (3, 0)):
run_ipynb(os.path.join(this_dir,
'../ch08/ch08.ipynb'))
def test_ch09(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
# run only on Py3, because of the Py3 specific pickle files
if (sys.version_info >= (3, 0)):
run_ipynb(os.path.join(this_dir, '../ch09/ch09.ipynb'))
else:
pass
def test_ch10(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch10/ch10.ipynb'))
def test_ch11(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch11/ch11.ipynb'))
def test_ch12(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch12/ch12.ipynb'))
def test_ch13(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch13/ch13.ipynb'))
def test_ch14(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch14/ch14.ipynb'))
def test_ch15(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch15/ch15.ipynb'))
def test_ch16(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
# run only on Py3, because of Py2 unicode handling
if (sys.version_info >= (3, 0)):
run_ipynb(os.path.join(this_dir,
'../ch16/ch16.ipynb'))
if __name__ == '__main__':
unittest.main()