예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
파일: run.py 프로젝트: gmanchon/nbclean
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
예제 #6
0
def preprocessor():
    return LimitOutput()