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 ea4a6cd
Show file tree
Hide file tree
Showing 19 changed files with 4,393 additions and 449 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ jobs:

- name: Get prerelease version tags
if: env.IS_PRERELEASE == 'true'
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_is_pre=$py_is_pre" >> $GITHUB_ENV
echo "js_is_pre=$js_is_pre" >> $GITHUB_ENV
echo "py=$py_is_pre" >> $GITHUB_OUTPUT
echo "js=$js_is_pre" >> $GITHUB_OUTPUT
- name: Fail if prerelease is not correctly versioned
if: (env.IS_PRERELEASE == 'true') && !( env.py_is_pre && env.js_is_pre )
if: (env.IS_PRERELEASE == 'true') && !( steps.prerelease-check.outputs.py && steps.prerelease-check.outputs.js )
uses: actions/github-script@v3
with:
script: |
Expand Down
145 changes: 125 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,20 @@ 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

Expand All @@ -64,14 +52,26 @@ 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
Expand All @@ -93,13 +93,15 @@ 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: |
Expand Down Expand Up @@ -143,3 +145,106 @@ jobs:
run: |
pip install dist/mols2grid-*.whl
python test_install.py
notebook-tests:
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: Cache conda
uses: actions/cache@v3
env:
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
conda-${{ hashFiles('tests/environment.yml') }}-${{ matrix.label }}-${{ env.CACHE_NUMBER }}

- 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"
environment-file: tests/environment.yml
use-only-tar-bz2: true
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true

- name: Install remaining conda dependencies
run: |
mamba install rdkit jupyter-packaging~=0.10 ${{ matrix.extra_dependencies }}
mamba list
- name: Build the extension
run: |
pip install -e .[build]
jupyter labextension develop . --overwrite
jupyter labextension list
- name: Install Test Dependencies
run: |
npm install
npx playwright install chromium
working-directory: tests/notebooks

- name: Execute integration tests
working-directory: tests/notebooks
run: |
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
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ dist
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
**/.yarn/
.pnp.*

### Node Patch ###
Expand Down Expand Up @@ -369,10 +366,16 @@ $RECYCLE.BIN/
# -------------
**/coverage/

# UI-tests
# --------
tests/notebooks/test-results
tests/notebooks/playwright-report

# ======
# Custom
# ======

.yarnrc.yml
mols2grid/nbextension/index.*
mols2grid/labextension
.vscode/
Expand Down
32 changes: 29 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# Dev guide

This is a short guide to setup a dev environment for mols2grid.

## Installation

1. Install conda or mamba
2. Create a new environment. Python 3.7+ (prefer 3.8):
2. Create a new environment. Python 3.8+ (prefer 3.10):
```
conda env create --name mols2grid --file docs/environment.yml
```
3. Install all the package dependencies in editable mode:
3. Install the package in editable mode:
```
pip install -e .[dev]
jupyter labextension develop . --overwrite
```

## Tests

To run tests locally:
- Install Firefox (needed for UI testing)
- Test your installation:
Expand All @@ -19,15 +26,34 @@ To run tests locally:
- You can select/skip the UI testing by specifying the `webdriver` mark in the pytest
command: `-m webdriver` to select UI tests only, or `-m "not webdriver"` to skip them.

### Notebook test

The CI pipeline contains an additional test that runs a simple notebook (see [](tests/notebooks/))
to make sure that there are no issues with the widget and the different versions of JupyterLab and
IPywidgets. This test requires the version of the package to **NOT** be a prerelease and thus the
versions in [](package.json) and [](mols2grid/_version.py) should strictly follow the `X.Y.Z` scheme
(i.e. no `X.Y.Z-a1`).

If this pipeline fails, the CI will automatically produce an artifact named
`notebook-updated-snapshots` containing the captures that were produced while running the test.
Review these snapshots and if they seem correct, commit them to the
[](tests/notebooks/tests/mols2grid.test.ts-snapshots) directory.

## Formatting

We use `black` and `isort` for formatting so either install the corresponding extension
from your IDE or install the package with `pip install black isort`. The configuration
is done inside the `pyproject.toml` file.

## Pull requests

Making a pull request will automatically run the tests and documentation build for you.
Don't forget to update the `CHANGELOG.md` file with your changes.

## Release

For versioning, you'll have to update both `package.json` and `mols2grid/_version.py`
files.
files (but this should be done by a maintainer directly).

The build and deployment process is run automatically when making a release on
GitHub.
Expand Down
28 changes: 21 additions & 7 deletions docs/contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,35 @@

# 🐍 Installation
---

mols2grid was developped for Python 3.7+ and requires rdkit (>=2020.03.1), pandas and jinja2 as dependencies.
The easiest way to install it is from conda:

The easiest way to install `mols2grid` is from conda:
```shell
conda install -c conda-forge mols2grid
```

Alternatively, you can also use pip:
```shell
pip install rdkit mols2grid
pip install 'mols2grid[rdkit]'
```

## Troubleshooting

If you see a JavaScript error message such as:
```text
Failed to load model class 'MolGridModel' from module 'mols2grid'
Error: Module mols2grid, version XXX is not registered, however, YYY is
```

Or if you notice that the selections, callbacks and interactive filtering aren't working as intended, you may have to manually activate the extension:

```shell
jupyter labextension enable mols2grid
```

If you notice that the selections, callbacks and interactive filtering aren't working as intended, you may have to manually activate the extension:
- for Jupyter Lab: `jupyter labextension install mols2grid`
- for Jupyter Notebook: `jupyter nbextension install mols2grid`
You should also make sure that you have installed compatible versions of `ipywidgets` and the
`jupyterlab`/`notebook` stack. The following specs are currently supported:
- `ipywidgets=7`, `jupyterlab=3`, `notebook=6`
- `ipywidgets=8`, `jupyterlab=4`, `notebook=7`

**Compatibility**

Expand Down
11 changes: 4 additions & 7 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ channels:
- conda-forge
- defaults
dependencies:
- ipykernel==6.26.0
- ipywidgets==7.8.0
- notebook<7.0.0
- ipywidgets=8
- notebook=7
- mistune<3.0.0
- jedi==0.19.1
- jinja2==3.1.2
- nbsphinx==0.8.8
- nodejs==18.18.2
- pandas==2.1.4
- nodejs==18.12.1
- pandas=2.1
- rdkit==2023.09.3
- recommonmark==0.7.1
- sphinx==4.5.0
Expand Down
2 changes: 1 addition & 1 deletion mols2grid/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.1-a2"
__version__ = "2.0.1"
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mols2grid",
"version": "2.0.1a2",
"version": "2.0.1",
"description": "Custom widget for the Python mols2grid package",
"keywords": [
"jupyter",
Expand Down Expand Up @@ -54,7 +54,7 @@
"devDependencies": {
"@babel/core": "^7.5.0",
"@babel/preset-env": "^7.5.0",
"@jupyterlab/builder": "^3.0.0",
"@jupyterlab/builder": "^4.0.0",
"@lumino/application": "^1.6.0",
"@lumino/widgets": "^1.6.0",
"@types/jest": "^26.0.0",
Expand Down
Loading

0 comments on commit ea4a6cd

Please sign in to comment.