Skip to content

Commit

Permalink
Test all backends together in CI (#118)
Browse files Browse the repository at this point in the history
* move backend tests

* avoid cached parametrization

* remove conda configs

* make all tests work

* remove mols in favour of fixtures

* make molecules fixtures

* avoid graph-tool on windows

* simplify ci

* mention pip explicitly

* reset backend for good measure

* try no space

* windows

* changelog

* reset backend for every test

* add warning test

* Apply suggestions from code review

* format
  • Loading branch information
RMeli authored Apr 8, 2024
1 parent da6be7f commit 62c5df3
Show file tree
Hide file tree
Showing 17 changed files with 447 additions and 485 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ jobs:
os: [macOS-latest, ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
chemlib: [obabel, rdkit]
graphlib: [nx, gt, rx, all]
graphlib: [nogt, all]
exclude:
# graph-tools does not work on Windows
- {os: "windows-latest", graphlib: "gt"}
- {os: "windows-latest", graphlib: "all"}
- {graphlib: "all", chemlib: "obabel"}
# graph-tool does not work on Windows
- {os: "windows-latest", graphlib: "all"}
# Don't run without graph-tool on Ubuntu and macOS
- {os: "ubuntu-latest", graphlib: "nogt"}
- {os: "macOS-latest", graphlib: "nogt"}
include:
- {os: "macOS-14", graphlib: "gt", chemlib: "obabel", python-version: "3.12"}
- {os: "macOS-14", graphlib: "nx", chemlib: "rdkit", python-version: "3.12"}
- {os: "macOS-14", graphlib: "all", chemlib: "obabel", python-version: "3.12"}
- {os: "macOS-14", graphlib: "all", chemlib: "rdkit", python-version: "3.12"}

steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@
Date: XX/YY/ZZZZ
Contributors: @RMeli

### Added

* Warnings filter for tests of multiple backends [PR #118 | @RMeli]
* Parametrized fixture to run tests with all available backends [PR #118 | @RMeli]

### Improved

* Test IDs [PR #117 | @RMeli]

### Changed

* Location of backend tests to standalone file [PR #118 | @RMeli]

### Removed

* Many CI configurations in favour of running tests for all available backends [PR #118 | @RMeli]
* `tests/molecule.py` in favour of fixtures [PR #118 | @RMeli]

## Version 0.7.0

Date: 05/04/2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ channels:
dependencies:
# Base
- python
- pip
- setuptools

# Maths
- numpy
- scipy
- graph-tool
- networkx>=2
- rustworkx

# Chemistry
- openbabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ channels:
dependencies:
# Base
- python
- pip
- setuptools

# Maths
- numpy
- scipy
- networkx>=2
- rustworkx

# Chemistry
- openbabel
Expand Down
26 changes: 0 additions & 26 deletions devtools/conda-envs/spyrmsd-test-obabel-rx.yaml

This file was deleted.

1 change: 1 addition & 0 deletions devtools/conda-envs/spyrmsd-test-rdkit-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ channels:
dependencies:
# Base
- python
- pip
- setuptools

# Maths
Expand Down
27 changes: 0 additions & 27 deletions devtools/conda-envs/spyrmsd-test-rdkit-gt.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ channels:
dependencies:
# Base
- python
- pip
- setuptools

# Maths
- numpy
- scipy
- networkx>=2
- rustworkx

# Chemistry
- rdkit
Expand Down
27 changes: 0 additions & 27 deletions devtools/conda-envs/spyrmsd-test-rdkit-rx.yaml

This file was deleted.

97 changes: 97 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
https://docs.pytest.org/en/latest/example/simple.html
"""

import os
import warnings
from collections import namedtuple

import numpy as np
import pytest

import spyrmsd
from spyrmsd import io

Mol = namedtuple("Mol", ["mol", "name", "n_atoms", "n_bonds", "n_h"])


def pytest_addoption(parser):
parser.addoption(
Expand Down Expand Up @@ -69,3 +78,91 @@ def pytest_generate_tests(metafunc):
n = metafunc.config.getoption("--n-tests")

metafunc.parametrize("idx", np.random.randint(0, pytest.n_systems, size=n))


@pytest.fixture(autouse=True, params=spyrmsd.available_backends)
def set_backend(request):
# Capture warning when trying to switch to the same backend
with warnings.catch_warnings():
warnings.simplefilter("ignore")
spyrmsd.set_backend(request.param)


@pytest.fixture(scope="session")
def molpath():
fdir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(fdir, f"data{os.sep}molecules")


@pytest.fixture
def benzene(molpath):
mol = io.loadmol(os.path.join(molpath, "benzene.sdf"))
return Mol(mol, "benzene", 12, 12, 6)


@pytest.fixture
def pyridine(molpath):
mol = io.loadmol(os.path.join(molpath, "pyridine.sdf"))
return Mol(mol, "pyridine", 11, 11, 5)


@pytest.fixture(
params=[
# (name, n_atoms, n_bonds, n_h)
("benzene", 12, 12, 6),
("ethanol", 9, 8, 6),
("pyridine", 11, 11, 5),
("dialanine", 23, 22, 12),
]
)
def mol(request, molpath):
"""
Load molecule as sPyRMSD molecule.
"""

name, n_atoms, n_bonds, n_h = request.param

mol = io.loadmol(os.path.join(molpath, f"{name}.sdf"))

return Mol(mol, name, n_atoms, n_bonds, n_h)


@pytest.fixture
def rawmol(mol, molpath):
"""
Load molecule as a molecule of the current molecular I/O library.
"""

RawMol = namedtuple(
"RawMol", ["mol", "rawmol", "name", "n_atoms", "n_bonds", "n_h"]
)

rawmol = io.load(os.path.join(molpath, f"{mol.name}.sdf"))

return RawMol(mol.mol, rawmol, mol.name, mol.n_atoms, mol.n_bonds, mol.n_h)


@pytest.fixture
def trps(molpath):
trp_list = []
for i in range(6):
trp_list.append(io.loadmol(os.path.join(molpath, f"trp{i}.pdb")))

return trp_list


@pytest.fixture
def docking_2viz(molpath):
mols = {} # Dictionary (pose, molecule)
for i in [1, 2, 3]:
mols[i] = io.loadmol(os.path.join(molpath, f"2viz_{i}.sdf"))

return mols


@pytest.fixture
def docking_1cbr(molpath):
return [
io.loadmol(os.path.join(molpath, "1cbr_ligand.mol2")),
*io.loadallmols(os.path.join(molpath, "1cbr_docking.sdf")),
]
80 changes: 0 additions & 80 deletions tests/molecules.py

This file was deleted.

Loading

0 comments on commit 62c5df3

Please sign in to comment.