Repository navigation
Expand file tree
/
Copy pathnb.py
More file actions
56 lines (52 loc) · 1.62 KB
/
Copy pathnb.py
File metadata and controls
56 lines (52 loc) · 1.62 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
# This script is designed to test notebooks.
# It is a work in progres...
import os
import json
import sys
import pipes3
from termcolor import colored
pinterp = None #pipes3.init_cling()
print("Starting up...")
def join(lines):
if lines is None:
return ""
elif type(lines) == str:
return lines
else:
return " ".join(lines)
def process(jdata,key=None):
if type(jdata) == list:
for jd in jdata:
process(jd)
elif type(jdata) == dict and jdata.get("cell_type","") == "code":
assert "source" in jdata
assert type(jdata["source"]) == list
src = "\n".join(jdata["source"])
pinterp.stdin.write(src+'$delim$\n')
pinterp.stdin.flush()
out = join(pipes3.read_output(pinterp, pinterp.stdout))
err = join(pipes3.read_output(pinterp, pinterp.stderr))
print("src:",colored(src,"cyan"))
if "ASSERTION FAILURE" in err:
print("out:",colored(out,"yellow"))
print("err:",colored(err,"red"))
print(colored("FAILED","red"))
exit(1)
else:
print(colored("PASSED","green"))
elif type(jdata) == dict:
for k in jdata:
jd = jdata[k]
process(jd, key=k)
elif type(jdata) in [str, int]:
pass
else:
print("info:",type(jdata), jdata, key)
raise Exception()
for a in sys.argv[1:]:
with open(a, "r") as fd:
print(colored("Testing file:"+a,"magenta"))
pinterp = pipes3.init_cling()
jdata = json.loads(fd.read().strip())
process(jdata)
print(colored("ALL TESTS PASSSED","green"))