Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

test environment for class

Project: test-env
Views: 22
Kernel: SageMath (stable)
import pandas as pd import numpy as np import os import subprocess import tempfile
def _notebook_run(path): dirname, __ = os.path.split(path) os.chdir(dirname) with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout: args = ["nbconvert", "--to", "notebook", "--execute", "--ExecutePreprocessor.timeout=60", "--output", fout.name, path] subprocess.check_call(args) fout.seek(0) nb = nbformat.read(fout, nbformat.current_nbformat) errors = [output for cell in nb.cells if "outputs" in cell for output in cell["outputs"]\ if output.output_type == "error"] return nb, errors
def test_ipynb(): nb, errors = _notebook_run('my_notebook.ipynb') assert errors == []
for i in range(10): print "Hello World!"
Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World!