Skip to content

Commit

Permalink
Add documentation on how to regenrate the output of the notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sunu committed Jul 12, 2024
1 parent 53b6fd1 commit 288e269
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
FROM pangeo/pangeo-notebook:2024.06.02

USER root

COPY --chown=${NB_USER}:${NB_USER} image-tests /srv/repo/image-tests
COPY --chown=${NB_USER}:${NB_USER} scripts /srv/repo/scripts

USER ${NB_USER}

ADD environment.yml environment.yml

RUN mamba env update --prefix /srv/conda/envs/notebook --file environment.yml

COPY --chown=${NB_USER}:${NB_USER} image-tests /srv/repo/image-tests
COPY --chown=${NB_USER}:${NB_USER} scripts /srv/repo/scripts
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ To add new tests, create new notebooks or add to the existing notebooks in `imag

```bash
docker build -t pangeo-notebook-veda .
docker run -v ./image-tests:/home/jovyan/image-tests pangeo-notebook-veda jupyter nbconvert --to notebook --inplace --execute image-tests/*.ipynb
docker run -v ./image-tests:/srv/repo/image-tests -e REGENERATE_OUTPUTS=true pangeo-notebook-veda bash /srv/repo/scripts/run_tests.sh
```

### Regenrating the output of the test notebooks

To regenerate the output of the test notebooks, we can use the same command we used in the previous section to generate the output of the notebooks while adding new tests:

```bash
docker build -t pangeo-notebook-veda .
docker run -v ./image-tests:/srv/repo/image-tests -e REGENERATE_OUTPUTS=true pangeo-notebook-veda bash /srv/repo/scripts/run_tests.sh
```
This will regenerate the output of the notebooks in place and you can commit the changes to the repository. Tests will fail when the output of the notebooks is different from the existing output. But on subsequent runs, the tests will pass after the output is regenerated.

### Running the test notebooks interactively

To interactively run the test notebooks in a JupiterLab environment locally, run the following command:
Expand Down
5 changes: 5 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ ls /srv/repo/image-tests/*.ipynb > /dev/null && \
python3 -c "import pytest_notebook" 2> /dev/null || \
python3 -m pip install --no-cache pytest-notebook > /dev/null;

# If regeneration flag is set, add it to the pytest flags
[ -n "${REGENERATE_OUTPUTS}" ] && \
echo "Regenerating notebook outputs..." && \
export PYTEST_FLAGS="--nb-force-regen ${PYTEST_FLAGS}";

py.test ${PYTEST_FLAGS} /srv/repo/image-tests/

0 comments on commit 288e269

Please sign in to comment.