def test_infinite_recursion(self): nb = self._read_nb("files/infinite-recursion.ipynb") pp = LimitOutput() nb, resources = pp.preprocess(nb, {}) cell, = nb.cells output, = cell.outputs assert len(output.traceback) == 100
def test_long_output(self): nb = self._read_nb("files/long-output.ipynb") cell, = nb.cells output, = cell.outputs assert len(output.text.split("\n")) > 1000 pp = LimitOutput() nb, resources = pp.preprocess(nb, {}) cell, = nb.cells output, = cell.outputs assert len(output.text.split("\n")) == 1000
def run_notebook(ntbk, max_output_lines=1000): """Run the cells in a notebook and limit the output length. Parameters ---------- ntbk : string | instance of NotebookNode The input notebook. max_output_lines : int | None The maximum number of lines allowed in notebook outputs. """ ntbk = _check_nb_file(ntbk) preprocessors = [Execute()] if max_output_lines is not None: preprocessors.append( LimitOutput(max_lines=max_output_lines, max_traceback=max_output_lines)) for prep in preprocessors: ntbk, _ = prep.preprocess(ntbk, {}) return ntbk
def preprocessor(): return LimitOutput()