open-atmos / devops_tests

pytest test routines asserting for GitHub issue-linked TODO labelling in the code, README link consistency and some Jupyter notebook sanity checks
GNU General Public License v3.0
0 stars 2 forks source link

check notebook header cells (badges, colab magick) #8

Open slayoo opened 1 year ago

slayoo commented 1 year ago

something like this?

COLAB_HEADER = """import sys
if 'google.colab' in sys.modules:
    !pip --quiet install open-atmos-jupyter-utils
    from open_atmos_jupyter_utils import pip_install_on_colab
    pip_install_on_colab('PySDM-examples')"""

def test_first_cell_contains_three_badges(notebook):
    """ checks if all notebooks feature nbviewer, mybinder and Colab badges (in the first cell) """
    with open(notebook) as fp:
        nb = nbformat.read(fp, nbformat.NO_CONVERT)
        assert len(nb.cells) > 0
        assert nb.cells[0].cell_type == "markdown"
        lines = nb.cells[0].source.split("\n")
        assert len(lines) == 3
        assert lines[0] == _nbviewer_badge_markdown(notebook)
        assert lines[1] == _mybinder_badge_markdown(notebook)
        assert lines[2] == _colab_badge_markdown(notebook)

def test_second_cell_contains_colab_header(notebook):
    """ checks if all notebooks feature a Colab-magick cell (just below badges) """
    with open(notebook) as fp:
        nb = nbformat.read(fp, nbformat.NO_CONVERT)
        assert len(nb.cells) > 1
        assert nb.cells[0].cell_type == "code"
        assert nb.cells[1].source == COLAB_HEADER

def test_third_cell_is_a_markdown_cell(notebook):
    """ checks if all notebooks have their third cell with some markdown (hopefully clarifying what the example is about) """
    with open(notebook) as fp:
        nb = nbformat.read(fp, nbformat.NO_CONVERT)
        assert len(nb.cells) > 2
        assert nb.cells[2].cell_type == "markdown"
slayoo commented 1 year ago

(see #7 for definition of badge functions)

github-actions[bot] commented 11 months ago

Stale issue message

github-actions[bot] commented 9 months ago

Stale issue message

github-actions[bot] commented 6 months ago

Stale issue message

github-actions[bot] commented 3 months ago

Stale issue message

github-actions[bot] commented 1 month ago

Stale issue message