Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli committed May 28, 2024
2 parents fea73a9 + a530454 commit c3f98d0
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
26 changes: 26 additions & 0 deletions devtools/conda-envs/spyrmsd-test-obabel-rx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: spyrmsd
channels:
- conda-forge
dependencies:
# Base
- python
- setuptools

# Maths
- numpy
- scipy
- rustworkx

# Chemistry
- openbabel

# Testing
- pytest
- pytest-cov
- pytest-benchmark

# Dev
- mypy
- flake8
- black
- codecov
27 changes: 27 additions & 0 deletions devtools/conda-envs/spyrmsd-test-rdkit-rx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: spyrmsd
channels:
- conda-forge
- rdkit
dependencies:
# Base
- python
- setuptools

# Maths
- numpy
- scipy
- rustworkx

# Chemistry
- rdkit

# Testing
- pytest
- pytest-cov
- pytest-benchmark

# Dev
- mypy
- flake8
- black
- codecov
1 change: 1 addition & 0 deletions devtools/conda-envs/spyrmsd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dependencies:
- numpy
- scipy
- rustworkx
- networkx
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"bib": ["duecredit"],
"rdkit": ["rdkit"],
"openbabel": ["openbabel"],
"networkx": ["networkx"],
},
platforms=["Linux", "Mac OS-X", "Unix", "Windows"],
python_requires=">=3.9",
Expand Down
38 changes: 38 additions & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def test_build_graph_node_features(property) -> None:
assert graph.num_edges(G) == 3


@pytest.mark.skipif(
spyrmsd.get_backend() != "graph_tool",
reason="NetworkX supports all Python objects as node properties.",
)
def test_build_graph_node_features_unsupported() -> None:
if spyrmsd.get_backend() != "graph-tool":
pytest.skip(
Expand All @@ -169,3 +173,37 @@ def test_build_graph_node_features_unsupported() -> None:

with pytest.raises(ValueError, match="Unsupported property type:"):
_ = graph.graph_from_adjacency_matrix(A, property)


@pytest.mark.skipif(
# Run test if all supported backends are installed
not set(spyrmsd.graph._supported_backends) <= set(spyrmsd.available_backends),
reason="Not all of the required backends are installed",
)
def test_set_backend() -> None:
import graph_tool as gt
import networkx as nx
import rustworkx as rx

A = np.array([[0, 1, 1], [1, 0, 0], [1, 0, 1]])

spyrmsd.set_backend("networkx")
assert spyrmsd.get_backend() == "networkx"

Gnx = graph.graph_from_adjacency_matrix(A)
assert isinstance(Gnx, nx.Graph)

spyrmsd.set_backend("graph-tool")
assert spyrmsd.get_backend() == "graph_tool"

Ggt = graph.graph_from_adjacency_matrix(A)
assert isinstance(Ggt, gt.Graph)

spyrmsd.set_backend("rustworkx")
assert spyrmsd.get_backend() == "rustworkx"

Grx = graph.graph_from_adjacency_matrix(A)
assert isinstance(Grx, rx.PyGraph)

with pytest.raises(ValueError, match="backend is not recognized or supported"):
spyrmsd.set_backend("unknown")
36 changes: 36 additions & 0 deletions tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import pytest

import spyrmsd
from spyrmsd import constants, graph, io, molecule, utils


Expand Down Expand Up @@ -205,3 +206,38 @@ def test_from_rdmol(molpath, adjacency):
with pytest.raises(AttributeError):
# No adjacency_matrix attribute
mol.adjacency_matrix


@pytest.mark.skipif(
# Run test if all supported backends are installed
not set(spyrmsd.graph._supported_backends) <= set(spyrmsd.available_backends),
reason="Not all of the required backends are installed",
)
def test_molecule_graph_cache(mol) -> None:
import graph_tool as gt
import networkx as nx
import rustworkx as rx

## Graph cache persists from previous tests, manually reset them
mol.G = {}
spyrmsd.set_backend("networkx")
mol.to_graph()

assert isinstance(mol.G["networkx"], nx.Graph)
assert "graph_tool" not in mol.G.keys()

spyrmsd.set_backend("graph-tool")
mol.to_graph()

spyrmsd.set_backend("rustworkx")
mol.to_graph()

## Make sure all backends (still) have a cache
assert isinstance(mol.G["networkx"], nx.Graph)
assert isinstance(mol.G["graph_tool"], gt.Graph)
assert isinstance(mol.G["rustworkx"], rx.PyGraph)

## Strip the molecule to ensure the cache is reset
mol.strip()

assert len(mol.G.items()) == 0

0 comments on commit c3f98d0

Please sign in to comment.