* wrap/python/tests/ipnbdoctest.py: Skip if IPython is missing.
This commit is contained in:
parent
3bf3d2c8a1
commit
72c7ad9fcd
1 changed files with 32 additions and 20 deletions
|
|
@ -4,7 +4,8 @@ simple example script for running and testing notebooks.
|
|||
|
||||
Usage: `ipnbdoctest.py foo.ipynb [bar.ipynb [...]]`
|
||||
|
||||
Each cell is submitted to the kernel, and the outputs are compared with those stored in the notebook.
|
||||
Each cell is submitted to the kernel, and the outputs are compared
|
||||
with those stored in the notebook.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
|
@ -21,6 +22,13 @@ except ImportError:
|
|||
print('Python 3.x is needed to run this script.')
|
||||
sys.exit(77)
|
||||
|
||||
import imp
|
||||
try:
|
||||
imp.find_module('IPython')
|
||||
except:
|
||||
print('IPython is needed to run this script.')
|
||||
sys.exit(77)
|
||||
|
||||
try:
|
||||
from IPython.kernel import KernelManager
|
||||
except ImportError:
|
||||
|
|
@ -42,7 +50,8 @@ def compare_png(a64, b64):
|
|||
def sanitize(s):
|
||||
"""sanitize a string for comparison.
|
||||
|
||||
fix universal newlines, strip trailing newlines, and normalize likely random values (memory addresses and UUIDs)
|
||||
fix universal newlines, strip trailing newlines, and normalize likely
|
||||
random values (memory addresses and UUIDs)
|
||||
"""
|
||||
if not isinstance(s, str):
|
||||
return s
|
||||
|
|
@ -73,18 +82,20 @@ def consolidate_outputs(outputs):
|
|||
elif out.type == 'pyerr':
|
||||
data['pyerr'] = dict(ename=out.ename, evalue=out.evalue)
|
||||
else:
|
||||
for key in ('png', 'svg', 'latex', 'html', 'javascript', 'text', 'jpeg',):
|
||||
for key in ('png', 'svg', 'latex', 'html',
|
||||
'javascript', 'text', 'jpeg',):
|
||||
if key in out:
|
||||
data[key].append(out[key])
|
||||
return data
|
||||
|
||||
|
||||
def compare_outputs(test, ref, skip_compare=('png', 'traceback', 'latex', 'prompt_number')):
|
||||
def compare_outputs(test, ref, skip_cmp=('png', 'traceback',
|
||||
'latex', 'prompt_number')):
|
||||
for key in ref:
|
||||
if key not in test:
|
||||
print("missing key: %s != %s" % (test.keys(), ref.keys()))
|
||||
return False
|
||||
elif key not in skip_compare and sanitize(test[key]) != sanitize(ref[key]):
|
||||
elif key not in skip_cmp and sanitize(test[key]) != sanitize(ref[key]):
|
||||
print("mismatch %s:" % key)
|
||||
exp = ref[key]
|
||||
eff = test[key]
|
||||
|
|
@ -146,7 +157,8 @@ def run_cell(shell, iopub, cell):
|
|||
|
||||
def test_notebook(nb):
|
||||
km = KernelManager()
|
||||
km.start_kernel(extra_arguments=['--pylab=inline'], stderr=open(os.devnull, 'w'))
|
||||
km.start_kernel(extra_arguments=['--pylab=inline'],
|
||||
stderr=open(os.devnull, 'w'))
|
||||
try:
|
||||
kc = km.client()
|
||||
kc.start_channels()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue