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
|
from nbformat import NotebookNode
class TestbookNode(NotebookNode):
"""
Extends `NotebookNode` to perform assertions
"""
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
@property
def output_text(self):
text = ''
for output in self['outputs']:
if 'text' in output:
text += output['text']
return text.strip()
@property
def execute_result(self):
"""Return data from execute_result outputs"""
return [
output["data"]
for output in self["outputs"]
if output["output_type"] == 'execute_result'
]
|