Skip to content

Commit

Permalink
Mock gudhi call in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ffl096 committed Nov 18, 2024
1 parent cef17b5 commit 61bff0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ all = [
"TopoNetX[doc, dev]",

# optional packages that are not required to run the library
"gudhi >= 3.9.0",
"hypernetx < 2.0.0",
"spharapy"
]
Expand Down
35 changes: 25 additions & 10 deletions test/classes/test_simplicial_complex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test simplicial complex class."""

from unittest.mock import Mock

import networkx as nx
import numpy as np
import pytest
Expand All @@ -10,11 +12,6 @@
from toponetx.classes.simplicial_complex import SimplicialComplex
from toponetx.datasets.mesh import stanford_bunny

try:
from gudhi import SimplexTree
except ImportError:
SimplexTree = None

try:
import hypernetx as hnx
except ImportError:
Expand Down Expand Up @@ -819,13 +816,31 @@ def test_to_combinatorial_complex(self):
assert len(result.cells) == len(expected_result.cells)
assert len(result.nodes) == len(expected_result.nodes)

@pytest.mark.skipif(
SimplexTree is None, reason="Optional dependency 'gudhi' not installed."
)
def test_from_gudhi(self):
"""Create a SimplicialComplex from a Gudhi SimplexTree and compare the number of simplices."""
tree = SimplexTree()
tree.insert([1, 2, 3, 5])
gudhi_simplices = [
([1, 2, 3, 5], 0.0),
([1, 2, 3], 0.0),
([1, 2, 5], 0.0),
([1, 2], 0.0),
([1, 3, 5], 0.0),
([1, 3], 0.0),
([1, 5], 0.0),
([1], 0.0),
([2, 3, 5], 0.0),
([2, 3], 0.0),
([2, 5], 0.0),
([2], 0.0),
([3, 5], 0.0),
([3], 0.0),
([5], 0.0),
]
tree = Mock(["get_skeleton", "dimension"])
tree.get_skeleton.side_effect = lambda i: (
s for s in gudhi_simplices if len(s[0]) <= i + 1
)
tree.dimension.return_value = 3

expected_result = SimplicialComplex()
expected_result.add_simplex((1, 2, 3, 5))
result = SimplicialComplex.from_gudhi(tree)
Expand Down

0 comments on commit 61bff0e

Please # to comment.