test_backend_nbagg.py 948 B

1234567891011121314151617181920212223242526272829
  1. import os
  2. from pathlib import Path
  3. import subprocess
  4. from tempfile import TemporaryDirectory
  5. import pytest
  6. nbformat = pytest.importorskip('nbformat')
  7. # From https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/
  8. def test_ipynb():
  9. nb_path = Path(__file__).parent / 'test_nbagg_01.ipynb'
  10. with TemporaryDirectory() as tmpdir:
  11. out_path = Path(tmpdir, "out.ipynb")
  12. subprocess.check_call(
  13. ["jupyter", "nbconvert", "--to", "notebook",
  14. "--execute", "--ExecutePreprocessor.timeout=500",
  15. "--output", str(out_path), str(nb_path)],
  16. env={**os.environ, "IPYTHONDIR": tmpdir})
  17. with out_path.open() as out:
  18. nb = nbformat.read(out, nbformat.current_nbformat)
  19. errors = [output for cell in nb.cells if "outputs" in cell
  20. for output in cell["outputs"]
  21. if output.output_type == "error"]
  22. assert not errors