File: testbooknode.py

package info (click to toggle)
python-testbook 0.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 408 kB
  • sloc: python: 1,045; makefile: 11
file content (28 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (2)
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'
        ]