Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/haddock/modules/scoring/deeprank/deeprank.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@


def deeprank_is_available() -> bool:
"""Check whether the `deeprank_gnn` package is importable."""
import deeprank_gnn # type: ignore # noqa: F401
"""Check whether deeprank-gnn-esm's requirements are met."""
try:
import sqlite3 # noqa: F401
except ImportError as err:
raise ImportError(
"The `deeprank` module requires a python interpreter built with "
"sqlite3 support, which is missing from your current "
"environment."
) from err

try:
import deeprank_gnn # type: ignore # noqa: F401
except ImportError as err:
raise ImportError(
"The `deeprank` module requires the `deeprank_gnn` package, "
"which is not installed in your current environment."
) from err

return True

Expand Down
24 changes: 22 additions & 2 deletions tests/test_module_deeprank.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Tests for the deeprank scoring module wrapper."""

import tempfile
import builtins
import shutil
import tempfile
from pathlib import Path

import pytest

from haddock.modules.scoring.deeprank.deeprank import DeeprankWrapper
from haddock.modules.scoring.deeprank.deeprank import (
DeeprankWrapper,
deeprank_is_available,
)

from . import golden_data as GOLDEN_DATA
from .conftest import has_deeprank
Expand Down Expand Up @@ -43,6 +47,22 @@ def deeprank_wrapper_ensemble():
)


def test_deeprank_is_available_requires_sqlite3(monkeypatch):
"""Must raise a clear error when the interpreter lacks sqlite3 support."""
real_import = builtins.__import__

# mock not being able to find `sqlite3`
def fake_import(name, *args, **kwargs):
if name == "sqlite3":
raise ImportError("No module named '_sqlite3'")
return real_import(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", fake_import)

with pytest.raises(ImportError, match="sqlite3"):
deeprank_is_available()


@has_deeprank
def test_run(deeprank_wrapper):
"""`run()` must return the score for the single input model."""
Expand Down
Loading