Пример #1
0
def test_noexceptions(nb_path, tmpdir):
    """Ensure that no cells raise an exception."""
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % str(
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
Пример #2
0
def test_no_outputs(nb_file):
    """Ensure that no cells have output."""
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    for cell in iter_cells(nb):
        assert cell.outputs == [], "Cell outputs not cleared"
        assert cell.execution_count is None, "Execution count not cleared"
Пример #3
0
def test_no_outputs(nb_file):
    """Ensure that no cells have output."""
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    for cell in iter_cells(nb):
        assert cell.outputs == [], "Cell outputs not cleared"
        assert cell.execution_count is None, "Execution count not cleared"
Пример #4
0
def test_noexceptions(nb_path, tmpdir):
    """Ensure that no cells raise an exception."""
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % str(
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
Пример #5
0
def assert_noexceptions(nb_file, tmp_path):
    plt = pytest.importorskip("matplotlib.pyplot")
    nb_path = examples_dir / f"{nb_file}.ipynb"
    nb = load_notebook(nb_path)
    pyfile = tmp_path / (nb_path.stem + ".py")
    export_py(nb, pyfile)
    execfile(pyfile, {})
    plt.close("all")
Пример #6
0
def test_notebooks(fname, tmpdir, plt):
    import matplotlib
    matplotlib.use('Agg')
    import pylab as _pylab
    _pylab.show = lambda: warnings.warn("Skipping command: 'pylab.show()'")
    py = os.path.join(str(tmpdir), "notebook.py")
    export_py(load_notebook(fname), py)
    execfile(py, {'get_ipython': _get_ipython, 'pylab': _pylab})
Пример #7
0
def test_notebooks(fname, tmpdir, plt):
    import matplotlib
    matplotlib.use('Agg')
    import pylab as _pylab
    _pylab.show = lambda: warnings.warn("Skipping command: 'pylab.show()'")
    py = os.path.join(str(tmpdir), "notebook.py")
    export_py(load_notebook(fname), py)
    execfile(py, {'get_ipython': _get_ipython, 'pylab': _pylab})
Пример #8
0
def assert_noexceptions(nb_file, tmpdir):
    plt = pytest.importorskip("matplotlib.pyplot")
    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    plt.close("all")
Пример #9
0
def test_nooutput(nb_path):
    """Ensure that no cells have output."""
    nb = load_notebook(nb_path)

    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == 'code':
                assert cell.outputs == [], (
                    "Clear all cell outputs in " + nb_path)
Пример #10
0
def test_nooutput(nb_path):
    """Ensure that no cells have output."""
    nb = load_notebook(nb_path)

    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == 'code':
                assert cell.outputs == [], ("Clear all cell outputs in " +
                                            nb_path)
Пример #11
0
def assert_noexceptions(nb_file, tmpdir):
    plt = pytest.importorskip('matplotlib.pyplot')
    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    plt.close('all')
Пример #12
0
def assert_noexceptions(nb_file, tmpdir, plt):
    from nengo.utils.ipython import export_py, load_notebook
    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    # Note: plt imported but not used to ensure figures are closed
    plt.saveas = None
Пример #13
0
def assert_noexceptions(nb_file, tmpdir, plt):
    from nengo.utils.ipython import export_py, load_notebook
    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (tmpdir.join(
        os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    # Note: plt imported but not used to ensure figures are closed
    plt.saveas = None
Пример #14
0
def test_nooutput(nb_path):
    """Ensure that no cells have output."""
    pytest.importorskip("IPython", minversion="1.0")
    from nengo.utils.ipython import load_notebook
    nb = load_notebook(nb_path)

    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == 'code':
                assert cell.outputs == [], (
                    "Clear all cell outputs in " + nb_path)
Пример #15
0
def test_noexceptions(nb_path, tmpdir, plt):
    """Ensure that no cells raise an exception."""
    pytest.importorskip("IPython", minversion="1.0")
    from nengo.utils.ipython import export_py, load_notebook
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    # Note: plt imported but not used to ensure figures are closed
    plt.saveas = None
Пример #16
0
def assert_noexceptions(nb_file, tmpdir, plt):
    plt.saveas = None  # plt used to ensure figures are closed, but don't save
    pytest.importorskip("IPython", minversion="1.0")
    pytest.importorskip("jinja2")
    from nengo.utils.ipython import export_py, load_notebook
    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
Пример #17
0
def test_nooutput(nb_path):
    """Ensure that no cells have output."""
    pytest.importorskip("IPython", minversion="1.0")
    from nengo.utils.ipython import load_notebook
    nb = load_notebook(nb_path)

    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == 'code':
                assert cell.outputs == [], ("Clear all cell outputs in " +
                                            nb_path)
Пример #18
0
def test_noexceptions(nb_path, tmpdir, plt):
    """Ensure that no cells raise an exception."""
    pytest.importorskip("IPython", minversion="1.0")
    from nengo.utils.ipython import export_py, load_notebook
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (tmpdir.join(
        os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    # Note: plt imported but not used to ensure figures are closed
    plt.saveas = None
Пример #19
0
def assert_noexceptions(nb_file, tmpdir):
    plt = pytest.importorskip("matplotlib.pyplot")
    pytest.importorskip("IPython", minversion="1.0")
    pytest.importorskip("jinja2")
    from nengo.utils.ipython import export_py, load_notebook

    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    plt.close("all")
Пример #20
0
def assert_noexceptions(nb_file, tmpdir):
    plt = pytest.importorskip('matplotlib.pyplot')
    pytest.importorskip("IPython", minversion="1.0")
    pytest.importorskip("jinja2")
    from nengo.utils.ipython import export_py, load_notebook
    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    pyfile = "%s.py" % (
        tmpdir.join(os.path.splitext(os.path.basename(nb_path))[0]))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    plt.close('all')
Пример #21
0
def iter_cells(nb_file, cell_type="code"):
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))

    if nb.nbformat <= 3:
        cells = []
        for ws in nb.worksheets:
            cells.extend(ws.cells)
    else:
        cells = nb.cells

    for cell in cells:
        if cell.cell_type == cell_type:
            yield cell
Пример #22
0
def iter_cells(nb_file, cell_type="code"):
    from nengo.utils.ipython import load_notebook

    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))

    if nb.nbformat <= 3:
        cells = []
        for ws in nb.worksheets:
            cells.extend(ws.cells)
    else:
        cells = nb.cells

    for cell in cells:
        if cell.cell_type == cell_type:
            yield cell
Пример #23
0
def test_minimal_metadata(nb_file):
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))

    assert "kernelspec" not in nb.metadata
    assert "signature" not in nb.metadata

    badinfo = (
        "codemirror_mode",
        "file_extension",
        "mimetype",
        "nbconvert_exporter",
        "version",
    )
    for info in badinfo:
        assert info not in nb.metadata.language_info
Пример #24
0
def test_minimal_metadata(nb_file):
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))

    assert "kernelspec" not in nb.metadata
    assert "signature" not in nb.metadata

    badinfo = (
        "codemirror_mode",
        "file_extension",
        "mimetype",
        "nbconvert_exporter",
        "version",
    )
    for info in badinfo:
        assert info not in nb.metadata.language_info
Пример #25
0
def test_nooutput(nb_file):
    """Ensure that no cells have output."""
    pytest.importorskip("IPython", minversion="1.0")
    pytest.importorskip("jinja2")
    from nengo.utils.ipython import load_notebook

    def check_all(cells):
        for cell in cells:
            if cell.cell_type == 'code':
                assert cell.outputs == [], ("Clear outputs in %s" % nb_path)

    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    if nb.nbformat <= 3:
        for ws in nb.worksheets:
            check_all(ws.cells)
    else:
        check_all(nb.cells)
Пример #26
0
def test_nooutput(nb_file):
    """Ensure that no cells have output."""
    pytest.importorskip("IPython", minversion="1.0")
    pytest.importorskip("jinja2")
    from nengo.utils.ipython import load_notebook

    def check_all(cells):
        for cell in cells:
            if cell.cell_type == 'code':
                assert cell.outputs == [], ("Clear outputs in %s" % nb_path)

    nb_path = os.path.join(examples_dir, "%s.ipynb" % nb_file)
    nb = load_notebook(nb_path)
    if nb.nbformat <= 3:
        for ws in nb.worksheets:
            check_all(ws.cells)
    else:
        check_all(nb.cells)
Пример #27
0
def test_version_4(nb_file):
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    assert nb.nbformat == 4
Пример #28
0
def test_version_4(nb_file):
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    assert nb.nbformat == 4
Пример #29
0
def test_no_signature(nb_file):
    from nengo.utils.ipython import load_notebook
    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    assert 'signature' not in nb.metadata, "Notebook has signature"
Пример #30
0
def test_version_4(nb_file):
    pytest.importorskip("IPython", minversion="3.0")
    nb = load_notebook(examples_dir / f"{nb_file}.ipynb")
    assert nb.nbformat == 4
Пример #31
0
def test_no_signature(nb_file):
    from nengo.utils.ipython import load_notebook

    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    assert "signature" not in nb.metadata, "Notebook has signature"
Пример #32
0
def test_no_signature(nb_file):
    pytest.importorskip("IPython", minversion="1.0")

    nb = load_notebook(os.path.join(examples_dir, "%s.ipynb" % nb_file))
    assert "signature" not in nb.metadata, "Notebook has signature"