Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run / test the notebooks from the command line automatically #334

Open
5 tasks
jonwright opened this issue Oct 11, 2024 · 3 comments
Open
5 tasks

Run / test the notebooks from the command line automatically #334

jonwright opened this issue Oct 11, 2024 · 3 comments

Comments

@jonwright
Copy link
Member

We accumulated a lot of code in notebooks, and so I guess I will sometimes break them. Here are some notes on how to test notebooks. ToDo's seem to be:

  • set up or find a few test cases that run (at least) at ESRF using files in /data/id11 that stay around
  • ensure we do not overwrite something when testing
  • define/select the jupyter kernels (e.g. the batteries included one at ESRF and/or a clean venv)
  • add something to run these independent of the github CI (because of big files)
  • look into rendering some notebooks into the documentation

Some links:

https://github.com/nteract/testbook

https://nbconvert.readthedocs.io/en/latest/execute_api.html

https://github.com/jupyter/nbconvert/blob/main/docs/api_examples/template_path/make_html.py

https://stackoverflow.com/questions/70671733/testing-a-jupyter-notebook

import nbformat
import pytest
from nbconvert.preprocessors import ExecutePreprocessor

@pytest.mark.parametrize("notebook", ["passed.ipynb", "failed.ipynb"])
def test_notebook_exec(notebook):
  with open(notebook) as f:
      nb = nbformat.read(f, as_version=4)
      ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
      try:
        assert ep.preprocess(nb) is not None, f"Got empty notebook for {notebook}"
      except Exception:
          assert False, f"Failed executing {notebook}"
@jadball
Copy link
Contributor

jadball commented Oct 18, 2024

Will this still be possible if we move the notebooks to a different repository?

@jonwright
Copy link
Member Author

Anything is possible? I would like to have historical as well as modern notebooks working. I guess that means putting version requirements at the top and bumping ImageD11 versions more often. It would go into testing against several venvs. At least the recent ones on pypi. Some kind of a matrix to run.

The "reproducible" part of FAIR is worth aiming for. So far as I am aware, the code can still be backward compatible except for cases where it had a bug.

@jonwright
Copy link
Member Author

Going over to parameterised notebooks, we could try:
https://papermill.readthedocs.io/en/latest/

This was referenced Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants