forked from computationalmodelling/nbval
-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Jean-Luc Stevens edited this page Oct 3, 2017
·
1 revision
Very rough outline/prototype of where things should be changed:
modified nbval/kernel.py
@@ -48,7 +48,7 @@ class NbvalKernelspecManager(KernelSpecManager):
def start_new_kernel(startup_timeout=60, kernel_name='python', **kwargs):
"""Start a new kernel, and return its Manager and Client"""
logger.debug('Starting new kernel: "%s"' % kernel_name)
- km = KernelManager(kernel_name=kernel_name,
+ km = KernelManager(kernel_name=kernel_name)
kernel_spec_manager=NbvalKernelspecManager())
km.start_kernel(**kwargs)
kc = km.client()
@@ -87,8 +87,18 @@ class RunningKernel(object):
stderr=open(os.devnull, 'w'),
cwd=cwd,
)
-
self._ensure_iopub_up()
+ setup_code = """
+import json
+ip = get_ipython()
+json_formatter = ip.display_formatter.formatters['application/json']
+json_formatter.for_type(object, lambda x: {'data':x})
+"""
+ self.kc.execute(setup_code,
+ silent=True,
+ store_history=False,
+ allow_stdin=False,
+ stop_on_error=True)
def _ensure_iopub_up(self):
total_timeout = 30
modified nbval/plugin.py
@@ -11,6 +11,7 @@ from __future__ import print_function
import pytest
import sys
import re
+import json
import hashlib
import warnings
from collections import OrderedDict, defaultdict
@@ -204,7 +205,7 @@ class IPyNbFile(pytest.File):
'execution_count',
)
if not config.option.nbdime:
- self.skip_compare = self.skip_compare + ('image/png', 'image/jpeg')
+ self.skip_compare = self.skip_compare # + ('image/png', 'image/jpeg')
kernel = None
@@ -355,6 +356,7 @@ class IPyNbCell(pytest.Item):
# Use stored skips unless passed a specific value
skip_compare = skip_compare or self.parent.skip_compare
+ print('SKIPPING: ', skip_compare)
test = transform_streams_for_comparison(test)
ref = transform_streams_for_comparison(ref)
@@ -378,6 +380,14 @@ class IPyNbCell(pytest.Item):
# Flatten out MIME types from data of display_data and execute_result
if key == 'data':
for data_key in reference[key].keys():
+ if data_key == 'application/json':
+ try:
+ d = json.loads(reference[key][data_key])
+ if 'data' in d:
+ print('DESERIALIZE: ', d['data'])
+ except:
+ pass
+
# Filter the keys in the SUB-dictionary again:
if data_key not in skip_compare:
reference_outs[data_key].append(self.sanitize(reference[key][data_key]))
@@ -419,6 +429,7 @@ class IPyNbCell(pytest.Item):
# reference are also read from the testing dictionary:
test_values = testing_outs[str(key)]
ref_values = reference_outs[key]
+
if len(test_values) != len(ref_values):
# The number of outputs for a specific MIME type differs
self.comparison_traceback.append(