Skip to content

Commit

Permalink
Add testing for the new graph caching with multiple backends
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnelen committed Mar 6, 2024
1 parent 1045a91 commit 41a8a4c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_build_graph_node_features_unsupported() -> None:
def test_set_backend() -> None:
import graph_tool as gt
import networkx as nx

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

spyrmsd.set_backend("networkx")
Expand Down
33 changes: 33 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
from tests import molecules

Expand Down Expand Up @@ -236,3 +237,35 @@ def test_from_rdmol(adjacency):
with pytest.raises(AttributeError):
# No adjacency_matrix attribute
mol.adjacency_matrix


@pytest.mark.skipif(
len(spyrmsd.available_backends) < 2,
reason="Not all of the required backends are installed",
)
@pytest.mark.parametrize(
"mol", [(molecules.benzene), (molecules.ethanol), (molecules.dialanine)]
)
def test_molecule_graph_cache(mol) -> None:
import graph_tool as gt
import networkx as nx

## 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()

## Make sure both backends (still) have a cache
assert isinstance(mol.G["networkx"], nx.Graph)
assert isinstance(mol.G["graph-tool"], gt.Graph)

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

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

0 comments on commit 41a8a4c

Please sign in to comment.