Skip to content

Commit

Permalink
add notebook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbouy committed Dec 22, 2023
1 parent 8bff942 commit cd18740
Show file tree
Hide file tree
Showing 20 changed files with 4,824 additions and 515 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/_build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: build-package
on:
workflow_call:
inputs:
check-prerelease:
default: false
required: false
type: boolean

defaults:
run:
shell: bash -l {0}

jobs:
build:
name: Build mols2grid package
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get prerelease version tags
if: inputs.check-prerelease
id: prerelease-check
run: |
py_dirty_tag=$(awk '/__version__ = "[[:digit:]+]\.[[:digit:]+]\.[[:digit:]+]\-.+"/ {print $3}' ./mols2grid/_version.py)
py_is_pre=$(test -z "$py_dirty_tag" && echo "false" || echo "true")
js_version_string=$(grep '"version":' ./package.json)
js_dirty_tag=$(echo "$js_version_string" | cut -d- -f2)
js_is_pre=$(test "$js_version_string" == "$js_dirty_tag" && echo "false" || echo "true")
echo "py=$py_is_pre" >> $GITHUB_OUTPUT
echo "js=$js_is_pre" >> $GITHUB_OUTPUT
- name: Fail if prerelease is not correctly versioned
if: (inputs.check-prerelease) && !( steps.prerelease-check.outputs.py && steps.prerelease-check.outputs.js )
uses: actions/github-script@v3
with:
script: |
core.setFailed("Versions are not tagged as a prerelease")
- name: Install node
uses: actions/setup-node@v3
with:
node-version: "18.12.1"
registry-url: 'https://registry.npmjs.org/'
cache: "yarn"

- name: Install python with pip
uses: actions/setup-python@v4
with:
python-version: 3.10
cache: "pip"

- name: Install dependencies for packaging
run: |
pip install setuptools wheel build virtualenv twine
- name: Check python installation
run: |
which python
python --version
pip --version
pip list
- name: Build package
run: |
python -m build .
50 changes: 3 additions & 47 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get prerelease version tags
if: env.IS_PRERELEASE == 'true'
run: |
py_dirty_tag=$(awk '/__version__ = "[[:digit:]+]\.[[:digit:]+]\.[[:digit:]+]\-.+"/ {print $3}' ./mols2grid/_version.py)
py_is_pre=$(test -z "$py_dirty_tag" && echo "false" || echo "true")
js_version_string=$(grep '"version":' ./package.json)
js_dirty_tag=$(echo "$js_version_string" | cut -d- -f2)
js_is_pre=$(test "$js_version_string" == "$js_dirty_tag" && echo "false" || echo "true")
echo "py_is_pre=$py_is_pre" >> $GITHUB_ENV
echo "js_is_pre=$js_is_pre" >> $GITHUB_ENV
- name: Fail if prerelease is not correctly versioned
if: (env.IS_PRERELEASE == 'true') && !( env.py_is_pre && env.js_is_pre )
uses: actions/github-script@v3
with:
script: |
core.setFailed("Versions are not tagged as a prerelease")
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org/'
cache: "yarn"

- name: Install python with pip
uses: actions/setup-python@v4
- name: Build package
uses: ./.github/workflows/_build-package.yml
with:
python-version: 3.8
cache: "pip"
check-prerelease: ${{ env.IS_PRERELEASE }}

- name: Install dependencies for packaging
run: |
pip install setuptools wheel build virtualenv twine
- name: Check python installation
run: |
which python
python --version
pip --version
pip list
- name: Build package
run: |
python -m build .
- name: Publish the Python package
env:
TWINE_USERNAME: __token__
Expand Down
205 changes: 164 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,30 @@ concurrency:
jobs:
tests:
name: ${{ matrix.label }}
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- label: CI-old
os: ubuntu-latest
- label: rdkit-2021
python-version: 3.8
extra_dependencies: "rdkit==2020.03.1 boost-cpp=1.72.0=h359cf19_6"
- label: CI-edge
os: ubuntu-latest
extra_dependencies: "rdkit==2021.03.1"
- label: rdkit-latest
python-version: "3.10"
extra_dependencies: "rdkit"
- label: CI-py3.9-rdkit2022
os: ubuntu-latest
python-version: 3.9
extra_dependencies: "rdkit==2022.03.1"

steps:
- uses: actions/checkout@v3

- name: Install node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "yarn"

- name: Install Firefox
uses: browser-actions/setup-firefox@latest

- run: firefox --version

- name: Prepare Selenium
uses: browser-actions/setup-geckodriver@latest
with:
geckodriver-version: "0.32.0"

- run: geckodriver --version

- name: Cache conda
Expand All @@ -64,15 +52,27 @@ jobs:
with:
path: ~/conda_pkgs_dir
key:
conda-${{ hashFiles('environment.yml') }}-${{ matrix.label }}-${{ env.CACHE_NUMBER }}
conda-${{ hashFiles('tests/environment.yml') }}-${{ matrix.label }}-${{ env.CACHE_NUMBER }}

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('setup.cfg') }}
key: pip-${{ hashFiles('pyproject.toml') }}
restore-keys: pip-

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache yarn
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -93,14 +93,16 @@ jobs:
- name: Install remaining conda dependencies
run: |
mamba install ${{ matrix.extra_dependencies }}
mamba install 'jupyterlab>=3,<5' ipywidgets=8 ${{ matrix.extra_dependencies }}
mamba list
- name: Install package through pip
- name: Build and install package
run: |
pip install .[tests,build]
jupyter labextension develop . --overwrite
pip list
jupyter labextension list
- name: Run tests
run: |
pytest --color=yes --disable-pytest-warnings \
Expand All @@ -120,26 +122,147 @@ jobs:
fail_ci_if_error: true
verbose: true

- name: Prepare for build
run: |
pip uninstall -y mols2grid
python -m build .
echo "$SCRIPT" > test_install.py
cat test_install.py
build:
name: Build package
runs-on: ubuntu-latest
steps:
- name: Build package
uses: ./.github/workflows/_build-package.yml

- name: Prepare quick test script
run: |
echo "$SCRIPT" > test_install.py
cat test_install.py
env:
SCRIPT: |
import mols2grid as mg
from rdkit import RDConfig
sdf = f"{RDConfig.RDDocsDir}/Book/data/solubility.test.sdf"
mg.save(sdf, output="/dev/null")
- name: Test tar.gz build
run: |
pip install dist/mols2grid-*.tar.gz
python test_install.py
pip uninstall -y mols2grid
- name: Test wheel build
run: |
pip install dist/mols2grid-*.whl
python test_install.py
- name: Cache package
uses: actions/cache@v3
id: cache-mols2grid
with:
path: dist/mols2grid-*.whl
key: ${{ runner.os }}-mols2grid-wheel

notebook-tests:
needs: [build]
name: ${{ matrix.label }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- label: JLab-3-Widgets-7
extra_dependencies: "jupyterlab>=3.2 ipywidgets=7"
- label: JLab-4-Widgets-8
extra_dependencies: "jupyterlab=4 ipywidgets=8"

steps:
- uses: actions/checkout@v3

- name: Retrieve cached package
uses: actions/cache@v3
id: cache-mols2grid
with:
path: dist/mols2grid-*.whl
key: ${{ runner.os }}-mols2grid-wheel

- name: Cache conda
uses: actions/cache@v3
env:
SCRIPT: |
import mols2grid as mg
from rdkit import RDConfig
sdf = f"{RDConfig.RDDocsDir}/Book/data/solubility.test.sdf"
mg.save(sdf, output="/dev/null")
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
conda-${{ hashFiles('tests/environment.yml') }}-${{ matrix.label }}-${{ env.CACHE_NUMBER }}

- name: Test tar.gz build
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('pyproject.toml') }}
restore-keys: pip-

- name: Get yarn cache directory path
id: yarn-ui-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Cache yarn
uses: actions/cache@v3
with:
path: ${{ steps.yarn-ui-cache-dir-path.outputs.dir }}
key: yarn-ui-${{ hashFiles('tests/notebooks/yarn.lock') }}
restore-keys: |
yarn-ui-
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.10"
use-only-tar-bz2: true
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true

- name: Install remaining conda dependencies
run: |
mamba install rdkit pandas ${{ matrix.extra_dependencies }}
mamba list
- name: Install the extension
run: |
pip install dist/mols2grid-*.whl[packaging]
jupyter labextension list
- name: Install Test Dependencies
run: |
pip install dist/mols2grid-*.tar.gz
python test_install.py
pip uninstall -y mols2grid
jlpm --no-immutable
npx playwright install chromium
working-directory: tests/notebooks

- name: Test wheel build
- name: Execute integration tests
working-directory: tests/notebooks
run: |
pip install dist/mols2grid-*.whl
python test_install.py
npx playwright test
- name: Upload Playwright Test assets
if: always()
uses: actions/upload-artifact@v3
with:
name: notebooks-test-assets
path: |
tests/notebooks/test-results
- name: Upload Playwright Test report
if: always()
uses: actions/upload-artifact@v3
with:
name: notebooks-test-report
path: |
tests/notebooks/playwright-report
- name: Update snapshots
if: failure()
working-directory: tests/notebooks
run: |
jlpm test:update
- name: Upload updated snapshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: notebook-updated-snapshots
path: tests/notebooks/tests
Loading

0 comments on commit cd18740

Please sign in to comment.