Skip to content

Commit d632e5c

Browse files
authored
Merge pull request #1625 from haddocking/1624-missing-sqlite3-check-on-deeprank-module
add `sqlite3` check to `deeprank_is_available`
2 parents 6261eff + 91b76cf commit d632e5c

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/haddock/modules/scoring/deeprank/deeprank.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,23 @@
1010

1111

1212
def deeprank_is_available() -> bool:
13-
"""Check whether the `deeprank_gnn` package is importable."""
14-
import deeprank_gnn # type: ignore # noqa: F401
13+
"""Check whether deeprank-gnn-esm's requirements are met."""
14+
try:
15+
import sqlite3 # noqa: F401
16+
except ImportError as err:
17+
raise ImportError(
18+
"The `deeprank` module requires a python interpreter built with "
19+
"sqlite3 support, which is missing from your current "
20+
"environment."
21+
) from err
22+
23+
try:
24+
import deeprank_gnn # type: ignore # noqa: F401
25+
except ImportError as err:
26+
raise ImportError(
27+
"The `deeprank` module requires the `deeprank_gnn` package, "
28+
"which is not installed in your current environment."
29+
) from err
1530

1631
return True
1732

tests/test_module_deeprank.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""Tests for the deeprank scoring module wrapper."""
22

3-
import tempfile
3+
import builtins
44
import shutil
5+
import tempfile
56
from pathlib import Path
67

78
import pytest
89

9-
from haddock.modules.scoring.deeprank.deeprank import DeeprankWrapper
10+
from haddock.modules.scoring.deeprank.deeprank import (
11+
DeeprankWrapper,
12+
deeprank_is_available,
13+
)
1014

1115
from . import golden_data as GOLDEN_DATA
1216
from .conftest import has_deeprank
@@ -43,6 +47,22 @@ def deeprank_wrapper_ensemble():
4347
)
4448

4549

50+
def test_deeprank_is_available_requires_sqlite3(monkeypatch):
51+
"""Must raise a clear error when the interpreter lacks sqlite3 support."""
52+
real_import = builtins.__import__
53+
54+
# mock not being able to find `sqlite3`
55+
def fake_import(name, *args, **kwargs):
56+
if name == "sqlite3":
57+
raise ImportError("No module named '_sqlite3'")
58+
return real_import(name, *args, **kwargs)
59+
60+
monkeypatch.setattr(builtins, "__import__", fake_import)
61+
62+
with pytest.raises(ImportError, match="sqlite3"):
63+
deeprank_is_available()
64+
65+
4666
@has_deeprank
4767
def test_run(deeprank_wrapper):
4868
"""`run()` must return the score for the single input model."""

0 commit comments

Comments
 (0)