bird-house / cookiecutter-birdhouse

Cookiecutter template for Birdhouse PyWPS birds.
http://cookiecutter-birdhouse.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
3 stars 4 forks source link

Add notebook testing setup #81

Closed huard closed 4 years ago

huard commented 4 years ago

Description

In Raven we're using notebooks as both documentation material and integration tests.

After unit tests are run, the notebooks are executed and compared with their expected output using the pytest plugin nbval.

These tests are run on Travis-CI to make sure notebooks used as documentation reflect the current software state.

Here are some make commands that we've created in Raven (room for improvement):

test_nb:
    @echo "Running notebook-based tests"
    @bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV);env RAVEN_WPS_URL=$(RAVEN_WPS_URL) FLYINGPIGEON_WPS_URL=$(FLYINGPIGEON_WPS_URL) pytest --nbval $(CURDIR)/docs/source/notebooks/ --sanitize-with $(CURDIR)/docs/source/output_sanitize.cfg --ignore $(CURDIR)/docs/source/notebooks/.ipynb_checkpoints"

notebook:
    @echo "Running notebook server"
    @bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV);env RAVEN_WPS_URL=$(RAVEN_WPS_URL) FLYINGPIGEON_WPS_URL=$(FLYINGPIGEON_WPS_URL) jupyter notebook $(CURDIR)/docs/source/notebooks/"

Another useful command would be to run and save all notebooks to refresh the expected output.

I think this model would be useful to extend to other birds.

huard commented 4 years ago

An nice improvement would be a mechanism to bulk update the notebooks output. When packages are updated, sometimes the outputs change, but it's not a bug. So we usually want to update the notebooks to reflect their expected output in a given environment. At the moment I do this manually:

Using jupyter nbconvert this could be automated. I could imagine for example a make command refresh_notebook that opens a conda client environment and update the notebook. The testing using nbval would be done in the same environment.

Zeitsperre commented 4 years ago

@huard This looks doable. Should I look into a way of performing this in a bird-agnostic way? or should there be some recipes that are only valid for some birds / services (thinking of Raven)?

huard commented 4 years ago

Yes, you'll see examples of this in existing birds. The objective would be to standardize this through the cookie-cutter template. I think these basic services are generic: